|
| 1 | +import { expect, html } from '@open-wc/testing'; |
| 2 | +import { createFixture } from '@patternfly/pfe-tools/test/create-fixture.js'; |
| 3 | +import { a11ySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js'; |
| 4 | +import { PfV6Banner } from '@patternfly/elements/pf-v6-banner/pf-v6-banner.js'; |
| 5 | + |
| 6 | +describe('<pf-v6-banner>', function() { |
| 7 | + it('imperatively instantiates', function() { |
| 8 | + expect(document.createElement('pf-v6-banner')).to.be.an.instanceof(PfV6Banner); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should upgrade', async function() { |
| 12 | + const el = await createFixture<PfV6Banner>(html`<pf-v6-banner>Test</pf-v6-banner>`); |
| 13 | + expect(el) |
| 14 | + .to.be.an.instanceOf(customElements.get('pf-v6-banner')) |
| 15 | + .and |
| 16 | + .to.be.an.instanceOf(PfV6Banner); |
| 17 | + }); |
| 18 | + |
| 19 | + describe('default', function() { |
| 20 | + let element: PfV6Banner; |
| 21 | + |
| 22 | + beforeEach(async function() { |
| 23 | + element = await createFixture<PfV6Banner>(html` |
| 24 | + <pf-v6-banner>Default banner</pf-v6-banner> |
| 25 | + `); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should be accessible', async function() { |
| 29 | + await expect(element).to.be.accessible(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should display content in the accessibility tree', async function() { |
| 33 | + const snapshot = await a11ySnapshot(); |
| 34 | + const node = snapshot.children?.find( |
| 35 | + (child: { name?: string }) => child.name?.includes('Default banner') |
| 36 | + ); |
| 37 | + expect(node).to.exist; |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('with color="blue"', function() { |
| 42 | + let element: PfV6Banner; |
| 43 | + |
| 44 | + beforeEach(async function() { |
| 45 | + element = await createFixture<PfV6Banner>(html` |
| 46 | + <pf-v6-banner color="blue">Blue banner</pf-v6-banner> |
| 47 | + `); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should be accessible', async function() { |
| 51 | + await expect(element).to.be.accessible(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + describe('with status="danger"', function() { |
| 56 | + let element: PfV6Banner; |
| 57 | + |
| 58 | + beforeEach(async function() { |
| 59 | + element = await createFixture<PfV6Banner>(html` |
| 60 | + <pf-v6-banner status="danger">Danger banner</pf-v6-banner> |
| 61 | + `); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should be accessible', async function() { |
| 65 | + await expect(element).to.be.accessible(); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('with screen-reader-text', function() { |
| 70 | + let element: PfV6Banner; |
| 71 | + |
| 72 | + beforeEach(async function() { |
| 73 | + element = await createFixture<PfV6Banner>(html` |
| 74 | + <pf-v6-banner status="danger" screen-reader-text="Danger alert:"> |
| 75 | + An error has occurred. |
| 76 | + </pf-v6-banner> |
| 77 | + `); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should include screen reader text in the accessibility tree', async function() { |
| 81 | + const snapshot = await a11ySnapshot(); |
| 82 | + const node = snapshot.children?.find( |
| 83 | + (child: { name?: string }) => child.name?.includes('Danger alert:') |
| 84 | + ); |
| 85 | + expect(node).to.exist; |
| 86 | + }); |
| 87 | + |
| 88 | + it('should include banner content in the accessibility tree', async function() { |
| 89 | + const snapshot = await a11ySnapshot(); |
| 90 | + const node = snapshot.children?.find( |
| 91 | + (child: { name?: string }) => child.name?.includes('An error has occurred.') |
| 92 | + ); |
| 93 | + expect(node).to.exist; |
| 94 | + }); |
| 95 | + |
| 96 | + it('should be accessible', async function() { |
| 97 | + await expect(element).to.be.accessible(); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + describe('without screen-reader-text', function() { |
| 102 | + beforeEach(async function() { |
| 103 | + await createFixture<PfV6Banner>(html` |
| 104 | + <pf-v6-banner>No screen reader text</pf-v6-banner> |
| 105 | + `); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should not include screen reader text in the accessibility tree', async function() { |
| 109 | + const snapshot = await a11ySnapshot(); |
| 110 | + const hasScreenReaderNode = snapshot.children?.some( |
| 111 | + (child: { name?: string }) => child.name === '' |
| 112 | + ); |
| 113 | + expect(hasScreenReaderNode).to.not.be.true; |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('with sticky', function() { |
| 118 | + let element: PfV6Banner; |
| 119 | + |
| 120 | + beforeEach(async function() { |
| 121 | + element = await createFixture<PfV6Banner>(html` |
| 122 | + <pf-v6-banner sticky>Sticky banner</pf-v6-banner> |
| 123 | + `); |
| 124 | + }); |
| 125 | + |
| 126 | + it('should have sticky positioning', function() { |
| 127 | + expect(getComputedStyle(element).position).to.equal('sticky'); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('with slotted link', function() { |
| 132 | + beforeEach(async function() { |
| 133 | + await createFixture<PfV6Banner>(html` |
| 134 | + <pf-v6-banner> |
| 135 | + Banner with <a href="#">a link</a> |
| 136 | + </pf-v6-banner> |
| 137 | + `); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should include the link in the accessibility tree', async function() { |
| 141 | + const snapshot = await a11ySnapshot(); |
| 142 | + const link = snapshot.children?.find( |
| 143 | + (child: { role?: string }) => child.role === 'link' |
| 144 | + ); |
| 145 | + expect(link).to.exist; |
| 146 | + expect(link).to.have.property('name', 'a link'); |
| 147 | + }); |
| 148 | + }); |
| 149 | +}); |
0 commit comments