Skip to content

Commit

Permalink
Merge pull request #674 from dpc-sdp/feature/component-tests
Browse files Browse the repository at this point in the history
[R20-538] adding component tests
  • Loading branch information
lambry authored Jun 26, 2023
2 parents dc67621 + ec41578 commit a14f1a7
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 224 deletions.
27 changes: 13 additions & 14 deletions packages/ripple-ui-core/src/components/alert/RplAlert.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import RplAlert from './RplAlert.vue'
import { rplEventBus } from './../../index.js'

const baseProps = {
variant: 'information',
Expand All @@ -14,25 +13,25 @@ const baseProps = {
describe('RplAlert', () => {
it('mounts', () => {
cy.mount(RplAlert, {
props: {
...baseProps
}
props: baseProps
})
})
xit('calls dismiss when clicked', () => {
let fired = false
const handler = () => {
fired = !fired
}
rplEventBus.on('rpl-alert/dismiss', handler)

it('fires dismiss event when cleared', () => {
let dismissed = false
const onDismiss = () => (dismissed = true)

cy.mount(RplAlert, {
props: {
...baseProps,
dismissed: fired
onDismiss
}
})
cy.get('[data-cy="dismiss"]')
cy.wrap(fired).should('be.true')
rplEventBus.off('rpl-alert/dismiss', handler)

cy.get('.rpl-alert__btn-close').click()

cy.wait(50).then(() => {
cy.wrap(dismissed).should('be.true')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import RplDataTable from './RplDataTable.vue'
import { RplDataTableColumns, RplDataTableItems } from './fixtures/sample'

const props = {
columns: RplDataTableColumns,
items: RplDataTableItems
}

describe('RplDataTable', () => {
it('mounts', () => {
cy.mount(RplDataTable, { props })
})

it('toggles the display of more information', () => {
cy.mount(RplDataTable, { props })

cy.get('.rpl-data-table__row').first().as('row')
cy.get('@row').find('.rpl-data-table__toggle').as('toggle')
cy.get('@row').find('.rpl-data-table__details').as('details')

cy.get('@details').should('be.hidden')
cy.get('@toggle').should('contain.text', 'More info')

cy.get('@toggle').click()

cy.get('@details').should('be.visible')
cy.get('@toggle').should('contain.text', 'Less info')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ArgsTable
} from '@storybook/addon-docs'
import RplDataTable from './RplDataTable.vue'
import { RplDataTableColumns, RplDataTableItems } from './fixtures/sample'
import { a11yStoryCheck } from './../../../stories/interactions.js'

export const SingleTemplate = (args) => ({
Expand All @@ -31,41 +32,8 @@ export const SingleTemplate = (args) => ({
args={{
caption: "Optional table caption",
footer: "Optional table footer",
columns: [
"Column 1",
"Column 2",
"Column 3",
"Column 4"
],
items: [
[
"R1 - C1",
"R1 - C2",
"R1 - C3",
"R1 - C4",
[
"<p><strong>R1 test heading</strong></p><p>R1 test content</p>"
]
],
[
"R2 - C1",
"R2 - C2",
"R2 - C3",
"R2 - C4",
[
"<p><strong>R2 test heading</strong></p><p>R2 test content</p>"
]
],
[
"R3 - C1",
"R3 - C2",
"R3 - C3",
"R3 - C4",
[
"R3 test content text only"
]
]
],
columns: RplDataTableColumns,
items: RplDataTableItems,
headingType: {
vertical: true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const RplDataTableColumns = [
'Column 1',
'Column 2',
'Column 3',
'Column 4'
]

export const RplDataTableItems = [
[
'R1 - C1',
'R1 - C2',
'R1 - C3',
'R1 - C4',
['<p><strong>R1 test heading</strong></p><p>R1 test content</p>']
],
[
'R2 - C1',
'R2 - C2',
'R2 - C3',
'R2 - C4',
['<p><strong>R2 test heading</strong></p><p>R2 test content</p>']
],
['R3 - C1', 'R3 - C2', 'R3 - C3', 'R3 - C4', ['R3 test content text only']]
]
27 changes: 27 additions & 0 deletions packages/ripple-ui-core/src/components/footer/RplFooter.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import RplFooter from './RplFooter.vue'
import { RplFooterLinks } from './fixtures/sample'
import { bpMin } from '../../lib/breakpoints'

const props = {
nav: RplFooterLinks
}

describe('RplFooter', () => {
it('mounts', () => {
cy.mount(RplFooter, { props })
})

it('allows menus to be opened on small screens', () => {
cy.viewport(bpMin.s, 1000).mount(RplFooter, { props })

cy.get('.rpl-footer-nav-section__header-inner-button').first().as('button')

cy.get('@button').click()

cy.get('@button')
.invoke('attr', 'aria-controls')
.then((id) => {
cy.get(`#${id}`).should('be.visible')
})
})
})
143 changes: 2 additions & 141 deletions packages/ripple-ui-core/src/components/footer/RplFooter.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@storybook/addon-docs'
import RplFooter from './RplFooter.vue'
import { RplFooterVariants } from './constants'
import { RplFooterLinks } from './fixtures/sample'
import { a11yStoryCheck } from './../../../stories/interactions.js'
import { bpMin } from '../../lib/breakpoints'

Expand All @@ -28,147 +29,7 @@ export const SingleTemplate = (args) => ({
}}
args={{
variant: 'default',
nav: [
{
text: 'Your Services',
url: '#',
items: [
{
text: 'Grants awards and assistance',
url: '#'
},
{
text: 'Law and safety',
url: '#'
},
{
text: 'Business and Industry',
url: '#'
},
{
text: 'Jobs and the Workplace',
url: '#'
},
{
text: 'Transport and Traffic',
url: '#'
},
{
text: 'Education',
url: '#'
},
{
text: 'Housing and Property',
url: '#'
},
{
text: 'Health',
url: '#'
},
{
text: 'Community',
url: '#'
},
{
text: 'Art, Culture and Sport',
url: '#'
},
{
text: 'Environment and Water',
url: '#'
}
]
},
{
text: 'News',
url: '#'
},
{
text: 'About VIC Government - A very long title to test wrapping behaviour',
url: '#',
items: [
{
text: 'Grants awards and assistance',
url: '#'
},
{
text: 'Law and safety',
url: '#'
},
{
text: 'Business and Industry ',
url: '#'
},
{
text: 'Jobs and the Workplace',
url: '#'
},
{
text: 'Transport and Traffic',
url: '#'
},
{
text: 'Education',
url: '#'
},
{
text: 'Housing and Property',
url: '#'
},
{
text: 'Health',
url: '#'
},
{
text: 'Community',
url: '#'
},
{
text: 'Art, Culture and Sport',
url: '#'
},
{
text: 'Environment and Water',
url: '#'
}
]
},
{
text: 'Events',
url: '#'
},
{
text: 'Connect with us',
url: '',
items: [
{
text: 'DFFH Twitter',
url: '#',
icon: 'icon-twitter'
},
{
text: 'DH Twitter',
url: '#',
icon: 'icon-twitter'
},
{
text: 'DFFH LinkedIn',
url: '#',
icon: 'icon-linkedin'
},
{
text: 'DFFH Facebook',
url: '#',
icon: 'icon-facebook'
},
{
text: 'Youtube',
url: '#',
icon: 'icon-youtube'
}
]
}
],
nav: RplFooterLinks,
links: [
{
text: 'Privacy',
Expand Down
Loading

0 comments on commit a14f1a7

Please sign in to comment.