From 65b3794ce5d352bfeac931d9996a65b96df1801d Mon Sep 17 00:00:00 2001 From: Melloware Date: Fri, 12 Jan 2024 11:52:21 -0500 Subject: [PATCH] Fix tests (#5759) * Fix #5757: Accordion error reading disabled * Fixed tests --- components/lib/chip/Chip.js | 2 +- components/lib/chip/Chip.spec.js | 6 +- .../lib/chip/__snapshots__/Chip.spec.js.snap | 53 +---- components/lib/fieldset/Fieldset.spec.js | 4 +- .../__snapshots__/Fieldset.spec.js.snap | 207 ++++++++++++++++++ 5 files changed, 218 insertions(+), 54 deletions(-) diff --git a/components/lib/chip/Chip.js b/components/lib/chip/Chip.js index 6a0f347438..0e3b9af89f 100644 --- a/components/lib/chip/Chip.js +++ b/components/lib/chip/Chip.js @@ -20,7 +20,7 @@ export const Chip = React.memo( useHandleStyle(ChipBase.css.styles, isUnstyled, { name: 'chip' }); const onKeyDown = (event) => { - if (event.key === 'Enter' || event.key === 'Backspace') { + if (event.code === 'Enter' || event.code === 'Backspace') { close(event); } }; diff --git a/components/lib/chip/Chip.spec.js b/components/lib/chip/Chip.spec.js index 35846b39e8..5bc8725d69 100644 --- a/components/lib/chip/Chip.spec.js +++ b/components/lib/chip/Chip.spec.js @@ -10,7 +10,7 @@ describe('Chip', () => { snapshot(, 'image and alt'); snapshot(, 'icon'); snapshot(, 'label'); - test('when removable is true it returns with remove icon', () => { + test('when removable is true the chip is removed when ENTER is pressed', () => { // Arrange const removeOn = jest.fn(); const { container } = render(); @@ -19,13 +19,13 @@ describe('Chip', () => { const chipRemoveIcon = container.getElementsByClassName('p-chip-remove-icon')[0]; // Act - fireEvent.keyDown(chipRemoveIcon, { key: 'enter', keyCode: 13 }); + fireEvent.keyDown(chipRemoveIcon, { key: 'Enter', code: 'Enter' }); // Assert expect(container).toMatchSnapshot('after remove'); expect(removeOn).toHaveBeenCalledTimes(1); }); - test('when removable is true the chip is removed when ENTER is pressed', () => { + test('when removable is true it returns with remove icon', () => { // Arrange const removeOn = jest.fn(); const { container } = render(); diff --git a/components/lib/chip/__snapshots__/Chip.spec.js.snap b/components/lib/chip/__snapshots__/Chip.spec.js.snap index b3f9745027..8f48a63436 100644 --- a/components/lib/chip/__snapshots__/Chip.spec.js.snap +++ b/components/lib/chip/__snapshots__/Chip.spec.js.snap @@ -75,50 +75,7 @@ exports[`Chip label 1`] = ` `; -exports[`Chip when removable is true it returns with remove icon: after remove 1`] = ` -
-
- -
-
-`; +exports[`Chip when removable is true it returns with remove icon: after remove 1`] = `
`; exports[`Chip when removable is true it returns with remove icon: before remove 1`] = `
@@ -140,7 +97,7 @@ exports[`Chip when removable is true it returns with remove icon: before remove xmlns="http://www.w3.org/2000/svg" > { ); - const legend = container.getElementsByClassName('p-fieldset-legend')[0]; + const legend = container.querySelectorAll('[data-pc-section="toggler"]')[0]; expect(container).toMatchSnapshot('toggleable-open'); @@ -54,7 +54,7 @@ describe('Fieldset', () => { ); - const legend = container.getElementsByClassName('p-fieldset-legend')[0]; + const legend = container.querySelectorAll('[data-pc-section="toggler"]')[0]; expect(container).toMatchSnapshot('expandable-open'); diff --git a/components/lib/fieldset/__snapshots__/Fieldset.spec.js.snap b/components/lib/fieldset/__snapshots__/Fieldset.spec.js.snap index 7be0efdfee..3cef37d66a 100644 --- a/components/lib/fieldset/__snapshots__/Fieldset.spec.js.snap +++ b/components/lib/fieldset/__snapshots__/Fieldset.spec.js.snap @@ -62,6 +62,85 @@ exports[`Fieldset legend 1`] = `
`; +exports[`Fieldset when Fieldset is toggleable it must expand and collapse: expandable-closed 1`] = ` +
+
+ + + +
+
+

+ Lorem ipsum dolor sit amet +

+
+
+
+
+`; + exports[`Fieldset when Fieldset is toggleable it must expand and collapse: expandable-open 1`] = `
`; +exports[`Fieldset when Fieldset is toggleable it must expand and collapse: expandable-open 2`] = ` +
+
+ + + + + Expand/Collapse + + + +
+
+

+ Lorem ipsum dolor sit amet +

+
+
+
+
+`; + +exports[`Fieldset when Fieldset is toggleable it will toggle when clicked: toggleable-closed 1`] = ` +
+
+ + + + + Toggleable + + + +
+
+

+ Lorem ipsum dolor sit amet +

+
+
+
+
+`; + exports[`Fieldset when Fieldset is toggleable it will toggle when clicked: toggleable-open 1`] = `