Skip to content

Commit

Permalink
Tests, Notifications - Add duplicate class test
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Apr 6, 2024
1 parent 07efa0d commit babc075
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 19 additions & 2 deletions tests/Notifications/elements.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { NotivueIcons, outlinedIcons } from 'notivue'

import { Classes as _Classes } from '@/Notifications/constants'
import { DEFAULT_ANIM_DURATION } from '@/support/utils'

const { TRANSITION, ...Classes } = _Classes

const defaultClasses = Object.values(Classes).filter((className) => className !== Classes.DUPLICATE)

it('All elements are rendered and only exists one element per class', () => {
cy.mountNotifications({
options: {
Expand All @@ -15,18 +18,32 @@ it('All elements are rendered and only exists one element per class', () => {
.get('.Success')
.click()

Object.values(Classes).forEach((className) => {
defaultClasses.forEach((className) => {
cy.get(`.${className}`).should('exist').and('have.length', 1)
})
})

it('Duplicate class is added correctly', () => {
cy.mountNotifications(undefined, {
avoidDuplicates: true,
})

.get('.Success')
.click()
.wait(DEFAULT_ANIM_DURATION)
.get('.Success')
.click()

cy.get(`.${Classes.DUPLICATE}`).should('exist').and('have.length', 1)
})

it('Title is not rendered by default (if empty string) while all other elements are', () => {
cy.mountNotifications()

.get('.Success')
.click()

Object.values(Classes).forEach((className) => {
defaultClasses.forEach((className) => {
if (className === Classes.TITLE) {
cy.get(`.${className}`).should('not.exist')
} else {
Expand Down
8 changes: 4 additions & 4 deletions tests/cypress/support/commands-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Classes } from '@/Notifications/constants'

import Notivue, { CyNotificationsProps } from '@/tests/Notifications/components/Notivue.vue'

import { createNotivue, type NotivueTheme } from 'notivue'
import { createNotivue, type NotivueTheme, type NotivueConfig } from 'notivue'

declare global {
namespace Cypress {
interface Chainable {
mountNotifications(props?: CyNotificationsProps): Chainable<any>
mountNotifications(props?: CyNotificationsProps, config?: NotivueConfig): Chainable<any>
checkTheme(theme: NotivueTheme): Chainable<any>
mountAndCheckTheme(theme: NotivueTheme): Chainable<any>
}
Expand All @@ -24,8 +24,8 @@ Cypress.Commands.add('checkTheme', (theme: NotivueTheme) => {
})
})

Cypress.Commands.add('mountNotifications', (props = {}) => {
const notivue = createNotivue()
Cypress.Commands.add('mountNotifications', (props = {}, config = {}) => {
const notivue = createNotivue(config)

return mount(Notivue, {
global: {
Expand Down

0 comments on commit babc075

Please sign in to comment.