Skip to content

Commit

Permalink
fix(kalert,kemptystate): icon slot test (#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiarrowood authored and adamdehaven committed Jun 3, 2024
1 parent 8620dee commit f831561
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/components/KAlert/KAlert.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { h } from 'vue'
import { mount } from 'cypress/vue'
import KAlert from '@/components/KAlert/KAlert.vue'
import { AlertAppearances } from '@/types'

const rendersCorrectVariant = (variant) => {
const rendersCorrectVariant = (variant: string) => {
it(`renders ${variant} variant`, () => {
mount(KAlert, {
props: {
Expand Down Expand Up @@ -85,21 +86,25 @@ describe('KAlert', () => {
message,
},
slots: {
default: `<span data-testid="default-slot-content">${defaultSlotContent}</span>`,
default: h('span', {}, defaultSlotContent),
},
})

cy.get('.alert-message').should('be.visible').and('have.text', defaultSlotContent)
})

it('displays icon passed through icon slot', () => {
const iconSlotContent = 'icon slot content'
const testId = 'slotted-icon'

mount(KAlert, {
slots: {
icon: '<img data-testid="slotted-icon" src="https://via.placeholder.com/24" />',
icon: h('div', { 'data-testid': testId }, iconSlotContent),
},
})

cy.get('.alert-icon-container').findTestId('slotted-icon').should('be.visible')
cy.get('.alert-icon-container').findTestId(testId).should('be.visible')
cy.get('.alert-icon-container').findTestId(testId).should('contain.text', iconSlotContent)
})

it('emits dismiss event when dismiss button is clicked', () => {
Expand Down
14 changes: 10 additions & 4 deletions src/components/KEmptyState/KEmptyState.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { h } from 'vue'
import { mount } from 'cypress/vue'
import KEmptyState from '@/components/KEmptyState/KEmptyState.vue'

Expand Down Expand Up @@ -73,27 +74,32 @@ describe('KEmptyState', () => {

it('displays content passed through default slot correctly', () => {
const content = 'Content'
const testId = 'slotted-message'

mount(KEmptyState, {
props: {
message: 'Message',
},
slots: {
default: `<span data-testid="slotted-message">${content}</span>`,
default: h('span', { 'data-testid': testId }, content),
},
})

cy.get('.empty-state-message').findTestId('slotted-message').should('be.visible').should('contain', content)
cy.get('.empty-state-message').findTestId(testId).should('be.visible').should('contain', content)
})

it('displays icon passed through icon slot', () => {
const iconSlotContent = 'icon slot content'
const testId = 'slotted-icon'

mount(KEmptyState, {
slots: {
icon: '<img data-testid="slotted-icon" src="https://via.placeholder.com/36" />',
icon: h('div', { 'data-testid': testId }, iconSlotContent),
},
})

cy.get('.empty-state-icon').findTestId('slotted-icon').should('be.visible')
cy.get('.empty-state-icon').findTestId(testId).should('be.visible')
cy.get('.empty-state-icon').findTestId(testId).should('contain.text', iconSlotContent)
})

it('emits event when action button is clicked', () => {
Expand Down

0 comments on commit f831561

Please sign in to comment.