Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kalert,kemptystate): icon slot test #2123

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading