import * as React from "react"
import { composeStories } from "@storybook/testing-react"
import { mount } from "@cypress/react"
import * as stories from "./Alert.stories"
const { Default, WithActions } = composeStories(stories)
describe('Alert tests', () => {
it('Default', () => {
mount()
cy.get('.alert').should('not.exist')
const title = 'Example text'
const subtitle = 'Example subtitle'
mount()
cy.get('.alert .alert-title').contains(title)
cy.get('.alert .alert-subtitle').contains(subtitle)
cy.get('.alert .alert-icon').should('exist')
cy.get('.alert .alert-close button').should('exist')
mount()
cy.get('.alert .alert-icon').should('not.exist')
cy.get('.alert .alert-close button').should('not.exist')
})
it('Variants', () => {
mount()
cy.get('.alert').should('have.class', 'bg-success-light')
mount()
cy.get('.alert').should('have.class', 'bg-warning-light')
mount()
cy.get('.alert').should('have.class', 'bg-danger-light')
mount()
cy.get('.alert').should('have.class', 'border-inverted-2')
mount()
cy.get('.alert').should('have.class', 'bg-primary-light')
})
it('WithActions', () => {
mount()
cy.get('.alert .alert-actions *').should('exist')
let alerted = ''
cy.on('window:alert', msg => alerted = msg)
cy.get('.alert .alert-close button').click().then(() => expect(alerted).to.match(/Alert closed/))
})
})