diff --git a/.eslintrc.js b/.eslintrc.js index cf67b0050..96f813f7e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,7 +14,6 @@ module.exports = { sourceType: "module", }, rules: { - "prettier/prettier": ["error", { trailingComma: "es5" }], "react/forbid-component-props": [ "error", { diff --git a/src/components/Accordion/Accordion.test.tsx b/src/components/Accordion/Accordion.test.tsx index 42c5d9b0e..dde1711b0 100644 --- a/src/components/Accordion/Accordion.test.tsx +++ b/src/components/Accordion/Accordion.test.tsx @@ -22,7 +22,7 @@ describe("Accordion", () => { content: <>More test content, }, ]} - /> + />, ); expect(screen.getByRole("tablist")).toMatchSnapshot(); }); @@ -37,11 +37,11 @@ describe("Accordion", () => { }, ]} titleElement="h4" - /> + />, ); // Check for the specific element as defined in the titleElement prop. expect( - within(screen.getByRole("listitem")).getByRole("heading").tagName + within(screen.getByRole("listitem")).getByRole("heading").tagName, ).toBe("H4"); }); @@ -60,7 +60,7 @@ describe("Accordion", () => { content: <>More test content, }, ]} - /> + />, ); const tab = screen.getByRole("tab", { name: "Advanced topics" }); await userEvent.click(tab); @@ -86,7 +86,7 @@ describe("Accordion", () => { key: "networking", }, ]} - /> + />, ); expect(screen.getByRole("tabpanel", { name: "Networking" })).toBeVisible(); }); diff --git a/src/components/Accordion/Accordion.tsx b/src/components/Accordion/Accordion.tsx index e8b56cb48..a572832bb 100644 --- a/src/components/Accordion/Accordion.tsx +++ b/src/components/Accordion/Accordion.tsx @@ -54,7 +54,7 @@ const generateSections = ( sections: Section[], setExpanded, expanded, - titleElement + titleElement, ) => sections.map(({ key, ...props }, i) => ( diff --git a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx index 205804dae..55e089da4 100644 --- a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx +++ b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx @@ -12,7 +12,7 @@ describe("AccordionSection ", () => { expanded="abcd-1234" setExpanded={jest.fn()} title="Test section" - /> + />, ); expect(screen.getByRole("listitem")).toMatchSnapshot(); @@ -26,7 +26,7 @@ describe("AccordionSection ", () => { setExpanded={jest.fn()} title="Test section" titleElement="h4" - /> + />, ); // Query for the specific element as defined in the titleElement prop. // eslint-disable-next-line testing-library/no-node-access @@ -47,7 +47,7 @@ describe("AccordionSection ", () => { expanded = id; }} title="Test section" - /> + />, ); await userEvent.click(screen.getByRole("tab", { name: "Test section" })); expect(onTitleClick).toHaveBeenCalledWith(true, ":r4:"); @@ -60,7 +60,7 @@ describe("AccordionSection ", () => { expanded = id; }} title="Test section" - /> + />, ); // Clicking the title again should close the accordion section. await userEvent.click(screen.getByRole("tab", { name: "Test section" })); @@ -81,7 +81,7 @@ describe("AccordionSection ", () => { expanded = id; }} title="Test section" - /> + />, ); await userEvent.click(screen.getByRole("tab", { name: "Test section" })); @@ -100,7 +100,7 @@ describe("AccordionSection ", () => { optional } - /> + />, ); const title = screen.getByRole("tab"); expect(title.children).toHaveLength(2); diff --git a/src/components/ActionButton/ActionButton.tsx b/src/components/ActionButton/ActionButton.tsx index 44929fe43..fcefd36ba 100644 --- a/src/components/ActionButton/ActionButton.tsx +++ b/src/components/ActionButton/ActionButton.tsx @@ -126,7 +126,7 @@ const ActionButton = ({ "is-processing": showLoader || showSuccess, "is-disabled": disabled, "is-inline": inline, - } + }, ); const showIcon = showLoader || showSuccess; const icon = (showLoader && "spinner") || (showSuccess && "success") || null; diff --git a/src/components/ApplicationLayout/ApplicationLayout.test.tsx b/src/components/ApplicationLayout/ApplicationLayout.test.tsx index 32b288aac..e13859011 100644 --- a/src/components/ApplicationLayout/ApplicationLayout.test.tsx +++ b/src/components/ApplicationLayout/ApplicationLayout.test.tsx @@ -17,7 +17,7 @@ it("displays a logo", () => { const link = screen.getAllByRole("link", { name: "Juju" })[0]; expect(within(link).getByRole("img", { name: "Juju" })).toHaveAttribute( "src", - "name.svg" + "name.svg", ); }); @@ -39,7 +39,7 @@ it("displays main content", () => { render( {content} - + , ); expect(screen.getByText(content)).toBeInTheDocument(); }); @@ -58,7 +58,7 @@ it("displays an aside", () => { logo={logo} navItems={[]} aside={{content}} - /> + />, ); expect(screen.getByText(content)).toBeInTheDocument(); expect(document.querySelector(".l-aside")).toBeInTheDocument(); @@ -79,7 +79,7 @@ it("pins the menu using external state", async () => { navItems={[]} menuPinned={true} onPinMenu={onPinMenu} - /> + />, ); expect(document.querySelector(".l-navigation")).toHaveClass("is-pinned"); await userEvent.click(screen.getByRole("button", { name: "Unpin menu" })); @@ -91,7 +91,7 @@ it("opens and collapses the menu", async () => { expect(document.querySelector(".l-navigation")).toHaveClass("is-collapsed"); await userEvent.click(screen.getByRole("button", { name: "Menu" })); expect(document.querySelector(".l-navigation")).not.toHaveClass( - "is-collapsed" + "is-collapsed", ); await userEvent.click(screen.getByRole("button", { name: "Close menu" })); expect(document.querySelector(".l-navigation")).toHaveClass("is-collapsed"); @@ -105,7 +105,7 @@ it("collapses the menu using external state", async () => { navItems={[]} menuCollapsed={true} onCollapseMenu={onCollapseMenu} - /> + />, ); expect(document.querySelector(".l-navigation")).toHaveClass("is-collapsed"); await userEvent.click(screen.getByRole("button", { name: "Menu" })); diff --git a/src/components/ArticlePagination/ArticlePagination.test.tsx b/src/components/ArticlePagination/ArticlePagination.test.tsx index 94891dedc..b5406de53 100644 --- a/src/components/ArticlePagination/ArticlePagination.test.tsx +++ b/src/components/ArticlePagination/ArticlePagination.test.tsx @@ -11,7 +11,7 @@ describe("ArticlePagination ", () => { nextURL="#next" previousLabel="Lorem ipsum dolor sit amet" previousURL="#previous" - /> + />, ); expect(screen.getByRole("contentinfo")).toMatchSnapshot(); }); diff --git a/src/components/Badge/Badge.test.tsx b/src/components/Badge/Badge.test.tsx index 960638aa4..c2ff8d48e 100644 --- a/src/components/Badge/Badge.test.tsx +++ b/src/components/Badge/Badge.test.tsx @@ -29,7 +29,7 @@ it("rounds number correctly for thousands", () => { it("rounds number correctly for millions", () => { render( - + , ); // Check that the correct value is displayed. expect(screen.getByText("132M")).toBeInTheDocument(); @@ -37,7 +37,7 @@ it("rounds number correctly for millions", () => { it("rounds number correctly for billions", () => { render( - + , ); // Check that the correct value is displayed. expect(screen.getByText("13B")).toBeInTheDocument(); @@ -45,7 +45,10 @@ it("rounds number correctly for billions", () => { it("rounds number correctly for trillions", () => { render( - + , ); // Check that the correct value is displayed. expect(screen.getByText("132T")).toBeInTheDocument(); @@ -56,7 +59,7 @@ it("displays the correct max value if it exceeds 999T", () => { + />, ); // Check that the correct value is displayed. expect(screen.getByText("999T")).toBeInTheDocument(); diff --git a/src/components/Badge/Badge.tsx b/src/components/Badge/Badge.tsx index 79f209f05..1a49a3552 100644 --- a/src/components/Badge/Badge.tsx +++ b/src/components/Badge/Badge.tsx @@ -72,7 +72,7 @@ const Badge = ({ [`p-badge--negative`]: !!isNegative, "p-badge": !isNegative, }, - className + className, ); let safeValue = Math.round(value); diff --git a/src/components/Button/Button.test.tsx b/src/components/Button/Button.test.tsx index 0861f6e01..1dbf4adb5 100644 --- a/src/components/Button/Button.test.tsx +++ b/src/components/Button/Button.test.tsx @@ -14,7 +14,7 @@ describe("Button ", () => { render( + , ); expect(screen.getByRole("link")).toMatchSnapshot(); }); @@ -53,7 +53,7 @@ describe("Button ", () => { disabled={true} href="http://example.com" onClick={onClick} - /> + />, ); const button = screen.getByRole("link"); expect(button).toHaveClass("is-disabled"); @@ -71,7 +71,7 @@ describe("Button ", () => { disabled={true} href="http://example.com" onClick={onClick} - /> + />, ); const button = screen.getByRole("link"); const clickEvent = createEvent.click(button); @@ -109,7 +109,7 @@ describe("Button ", () => { it("puts additional classes at the end", () => { render(} - + , ); await userEvent.click(screen.getByRole("button", { name: "Toggle" })); @@ -290,7 +290,7 @@ describe("ContextualMenu ", () => { // Click on an item: await userEvent.click(screen.getByRole("button", { name: "child" })); expect( - screen.queryByLabelText(DropdownLabel.Dropdown) + screen.queryByLabelText(DropdownLabel.Dropdown), ).not.toBeInTheDocument(); }); @@ -298,7 +298,7 @@ describe("ContextualMenu ", () => { render( child - + , ); await userEvent.click(screen.getByRole("button", { name: "Toggle" })); diff --git a/src/components/ContextualMenu/ContextualMenu.tsx b/src/components/ContextualMenu/ContextualMenu.tsx index fbb656db3..d87626471 100644 --- a/src/components/ContextualMenu/ContextualMenu.tsx +++ b/src/components/ContextualMenu/ContextualMenu.tsx @@ -128,14 +128,14 @@ export type Props = BaseProps & */ const getPositionNode = ( wrapper: HTMLElement, - positionNode?: HTMLElement + positionNode?: HTMLElement, ): HTMLElement | null => { if (positionNode) { return positionNode; } else if (wrapper) { // We want to position the menu in relation to the toggle, if it exists. const toggle = wrapper.querySelector( - ".p-contextual-menu__toggle" + ".p-contextual-menu__toggle", ); return toggle || wrapper; } @@ -237,7 +237,7 @@ const ContextualMenu = ({ updatePositionCoords(); } }, - [updatePositionCoords] + [updatePositionCoords], ); // Handle controlling updates to the menu visibility from outside @@ -266,7 +266,7 @@ const ContextualMenu = ({ updatePositionCoords(); } }, - [closePortal, positionNode, updatePositionCoords] + [closePortal, positionNode, updatePositionCoords], ); const onScroll = useCallback( @@ -279,7 +279,7 @@ const ContextualMenu = ({ updatePositionCoords(); } }, - [positionNode, updatePositionCoords] + [positionNode, updatePositionCoords], ); useListener(window, onResize, "resize", true, isOpen); @@ -317,7 +317,7 @@ const ContextualMenu = ({ "p-icon--chevron-down p-contextual-menu__indicator", { "is-light": ["negative", "positive"].includes(toggleAppearance), - } + }, )} > ) : null} diff --git a/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.test.tsx b/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.test.tsx index 1f8032db4..d34e04126 100644 --- a/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.test.tsx +++ b/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.test.tsx @@ -19,10 +19,10 @@ describe("ContextualMenuDropdown ", () => { i)} - /> + />, ); expect( - document.querySelector(".p-contextual-menu__dropdown") + document.querySelector(".p-contextual-menu__dropdown"), ).not.toHaveAttribute("style"); }); @@ -37,7 +37,7 @@ describe("ContextualMenuDropdown ", () => { links={links} positionNode={positionNode} scrollOverflow - /> + />, ); // Rerender the component so that the hooks run again once the elements have // been created in the DOM. @@ -47,14 +47,14 @@ describe("ContextualMenuDropdown ", () => { links={links} positionNode={positionNode} scrollOverflow - /> + />, ); await waitFor(() => { expect( - document.querySelector(".p-contextual-menu__dropdown") + document.querySelector(".p-contextual-menu__dropdown"), ).toHaveAttribute( "style", - "min-height: 2rem; overflow-x: auto; max-height: 100px;" + "min-height: 2rem; overflow-x: auto; max-height: 100px;", ); }); positionNode.remove(); @@ -118,8 +118,8 @@ describe("ContextualMenuDropdown ", () => { "left", generateFits({ fromLeft: { fitsRight: false }, - }) - ) + }), + ), ).toBe("right"); }); @@ -129,8 +129,8 @@ describe("ContextualMenuDropdown ", () => { "right", generateFits({ fromRight: { fitsLeft: false }, - }) - ) + }), + ), ).toBe("left"); }); @@ -142,8 +142,8 @@ describe("ContextualMenuDropdown ", () => { fromCenter: { fitsCentered: { fitsLeft: false, fitsRight: false } }, fromLeft: { fitsRight: false }, fromRight: { fitsLeft: false }, - }) - ) + }), + ), ).toBe("center"); }); @@ -154,8 +154,8 @@ describe("ContextualMenuDropdown ", () => { generateFits({ fromCenter: { fitsCentered: { fitsLeft: false } }, fromRight: { fitsLeft: false }, - }) - ) + }), + ), ).toBe("left"); }); @@ -166,8 +166,8 @@ describe("ContextualMenuDropdown ", () => { generateFits({ fromCenter: { fitsCentered: { fitsRight: false } }, fromLeft: { fitsRight: false }, - }) - ) + }), + ), ).toBe("right"); }); }); @@ -196,13 +196,13 @@ describe("ContextualMenuDropdown ", () => { isOpen links={links} positionNode={positionNode} - /> + />, ); // get the dropdown menu dom element and set its height // NOTE: we can only do this after the component has been rendered at least once let dropdownNode = document.querySelector( - ".p-contextual-menu__dropdown" + ".p-contextual-menu__dropdown", ) as HTMLElement; dropdownNode.getBoundingClientRect = jest @@ -216,14 +216,14 @@ describe("ContextualMenuDropdown ", () => { isOpen links={links} positionNode={positionNode} - /> + />, ); }; const assertMenuPosition = async (position: "above" | "below") => { await waitFor(() => { const dropdownNode = document.querySelector( - ".p-contextual-menu__dropdown" + ".p-contextual-menu__dropdown", ) as HTMLElement; let condition = expect(dropdownNode); diff --git a/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.tsx b/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.tsx index 3561e85b2..62133fcac 100644 --- a/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.tsx +++ b/src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.tsx @@ -58,7 +58,7 @@ const getPositionStyle = ( position: Position, verticalPosition: VerticalPosition, positionCoords: Props["positionCoords"], - constrainPanelWidth: Props["constrainPanelWidth"] + constrainPanelWidth: Props["constrainPanelWidth"], ): React.CSSProperties => { if (!positionCoords) { return null; @@ -101,7 +101,7 @@ const getPositionStyle = ( */ export const adjustForWindow = ( position: Position, - fitsWindow: WindowFitment + fitsWindow: WindowFitment, ): Position => { let newPosition: string = position; if (!fitsWindow.fromRight.fitsLeft && newPosition === "right") { @@ -144,7 +144,7 @@ export const adjustForWindow = ( const generateLink = ( link: ButtonProps, key: React.Key, - handleClose: Props["handleClose"] + handleClose: Props["handleClose"], ) => { const { children, className, onClick, ...props } = link; return ( @@ -167,7 +167,7 @@ const generateLink = ( }; const getClosestScrollableParent = ( - node: HTMLElement | null + node: HTMLElement | null, ): HTMLElement | null => { let currentNode = node; while (currentNode && currentNode !== document.body) { @@ -209,8 +209,8 @@ const ContextualMenuDropdown = ({ adjustedPosition, verticalPosition, positionCoords, - constrainPanelWidth - ) + constrainPanelWidth, + ), ); const [maxHeight, setMaxHeight] = useState(); // Update the styles to position the menu. @@ -220,8 +220,8 @@ const ContextualMenuDropdown = ({ adjustedPosition, verticalPosition, positionCoords, - constrainPanelWidth - ) + constrainPanelWidth, + ), ); }, [adjustedPosition, positionCoords, verticalPosition, constrainPanelWidth]); @@ -256,7 +256,7 @@ const ContextualMenuDropdown = ({ windowSpaceBelow >= dropdownHeight) || windowSpaceBelow > scrollParentSpaceAbove ? "bottom" - : "top" + : "top", ); }, [positionNode]); @@ -277,7 +277,7 @@ const ContextualMenuDropdown = ({ scrollOverflow, setAdjustedPosition, updateVerticalPosition, - ] + ], ); // Handle adjusting the horizontal position and scrolling of the dropdown so that it remains on screen. @@ -286,7 +286,7 @@ const ContextualMenuDropdown = ({ positionNode, onUpdateWindowFitment, 0, - isOpen && (autoAdjust || scrollOverflow) + isOpen && (autoAdjust || scrollOverflow), ); // Update the styles when the position changes. @@ -328,7 +328,7 @@ const ContextualMenuDropdown = ({ return ( {item.map((link, j) => - generateLink(link, j, handleClose) + generateLink(link, j, handleClose), )} ); diff --git a/src/components/EmptyState/EmptyState.test.tsx b/src/components/EmptyState/EmptyState.test.tsx index a9ea1afc6..132d669d4 100644 --- a/src/components/EmptyState/EmptyState.test.tsx +++ b/src/components/EmptyState/EmptyState.test.tsx @@ -15,7 +15,7 @@ describe("EmptyState ", () => { } - /> + />, ); expect(screen.getByRole("img")).toHaveAttribute("src", "path/to/image"); }); @@ -24,7 +24,7 @@ describe("EmptyState ", () => { render( }> Empty - + , ); expect(screen.getByText("Empty")).toBeInTheDocument(); }); @@ -38,7 +38,7 @@ describe("EmptyState ", () => { data-testid="wrapper" > Empty - + , ); expect(screen.getByTestId("wrapper")).toHaveClass("extra-class"); }); diff --git a/src/components/Field/Field.test.tsx b/src/components/Field/Field.test.tsx index b7550b373..825fb05e5 100644 --- a/src/components/Field/Field.test.tsx +++ b/src/components/Field/Field.test.tsx @@ -8,7 +8,7 @@ describe("Field ", () => { render( Test content - + , ); expect(screen.getByTestId("field")).toMatchSnapshot(); }); @@ -24,10 +24,10 @@ describe("Field ", () => { render( - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleErrorMessage( - "Are you sure?" + "Are you sure?", ); expect(screen.getByTestId("field")).toHaveClass("is-caution"); }); @@ -40,10 +40,10 @@ describe("Field ", () => { data-testid="field" > - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleErrorMessage( - "Are you sure?" + "Are you sure?", ); expect(screen.getByTestId("field")).toHaveClass("is-caution"); }); @@ -52,10 +52,10 @@ describe("Field ", () => { render( - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleErrorMessage( - "You can't do that" + "You can't do that", ); expect(screen.getByTestId("field")).toHaveClass("is-error"); }); @@ -68,10 +68,10 @@ describe("Field ", () => { data-testid="field" > - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleErrorMessage( - "You can't do that" + "You can't do that", ); expect(screen.getByTestId("field")).toHaveClass("is-error"); }); @@ -80,10 +80,10 @@ describe("Field ", () => { render( - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleDescription( - "You did it!" + "You did it!", ); expect(screen.getByTestId("field")).toHaveClass("is-success"); }); @@ -96,10 +96,10 @@ describe("Field ", () => { data-testid="field" > - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleDescription( - "You did it!" + "You did it!", ); expect(screen.getByTestId("field")).toHaveClass("is-success"); }); @@ -108,10 +108,10 @@ describe("Field ", () => { render( - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleDescription( - "This is how you do it" + "This is how you do it", ); }); @@ -119,10 +119,10 @@ describe("Field ", () => { render( This is how you do it} helpId="id-1"> - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleDescription( - "This is how you do it" + "This is how you do it", ); }); @@ -133,14 +133,14 @@ describe("Field ", () => { label="Test label" labelClassName="label-node" data-testid="field" - /> + />, ); const field = screen.getByTestId("field"); expect(field.childNodes[0]).toHaveClass("label-node"); // The label should not be inside the control. expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-form__control .p-form__label") + document.querySelector(".p-form__control .p-form__label"), ).not.toBeInTheDocument(); }); @@ -152,7 +152,7 @@ describe("Field ", () => { // The label should be inside the control. expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-form__control .p-form__label") + document.querySelector(".p-form__control .p-form__label"), ).toBeInTheDocument(); }); @@ -176,12 +176,12 @@ describe("Field ", () => { // The Label should be inside a col-4. expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".col-4 .p-form__label") + document.querySelector(".col-4 .p-form__label"), ).toBeInTheDocument(); // The control should be inside a col-8. expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".col-8 .p-form__control") + document.querySelector(".col-8 .p-form__control"), ).toBeInTheDocument(); expect(screen.getByTestId("field")).toHaveClass("row"); }); diff --git a/src/components/Field/Field.tsx b/src/components/Field/Field.tsx index 6dc09eb17..f6f6e1776 100644 --- a/src/components/Field/Field.tsx +++ b/src/components/Field/Field.tsx @@ -102,7 +102,7 @@ const generateError = ( error: Props["error"], caution: Props["caution"], success: Props["success"], - validationId: Props["validationId"] + validationId: Props["validationId"], ) => { if (!error && !caution && !success) { return null; @@ -119,7 +119,7 @@ const generateLabel = ( required: Props["required"], label: Props["label"], labelClassName: Props["labelClassName"], - stacked: Props["stacked"] + stacked: Props["stacked"], ) => { if (!label) { return null; @@ -195,7 +195,7 @@ const Field = ({ required, label, labelClassName, - stacked + stacked, ); const content = generateContent({ diff --git a/src/components/Form/Form.test.tsx b/src/components/Form/Form.test.tsx index 0bfd43a5e..21b35662f 100644 --- a/src/components/Form/Form.test.tsx +++ b/src/components/Form/Form.test.tsx @@ -6,7 +6,7 @@ import Form from "./Form"; describe("Form ", () => { it("renders", () => { render( -
Test content
+
Test content
, ); expect(screen.getByRole("form")).toMatchSnapshot(); }); @@ -27,7 +27,7 @@ describe("Form ", () => { name="this needs a name so RTL can find it" stacked={true} className="extra-class" - /> + />, ); const form = screen.getByRole("form"); expect(form).toHaveClass("p-form"); diff --git a/src/components/FormikField/FormikField.test.tsx b/src/components/FormikField/FormikField.test.tsx index 75da14fc0..349099f07 100644 --- a/src/components/FormikField/FormikField.test.tsx +++ b/src/components/FormikField/FormikField.test.tsx @@ -10,7 +10,7 @@ describe("FormikField", () => { render( - + , ); expect(screen.getByRole("combobox")).toBeInTheDocument(); @@ -26,7 +26,7 @@ describe("FormikField", () => { onSubmit={jest.fn()} > - + , ); expect(screen.getByRole("textbox")).toHaveAccessibleErrorMessage("Uh oh!"); @@ -41,7 +41,7 @@ describe("FormikField", () => { onSubmit={jest.fn()} > - + , ); expect(screen.getByRole("textbox")).not.toHaveAccessibleErrorMessage(); diff --git a/src/components/Input/Input.test.tsx b/src/components/Input/Input.test.tsx index 11ea7b910..a2131bfa1 100644 --- a/src/components/Input/Input.test.tsx +++ b/src/components/Input/Input.test.tsx @@ -20,13 +20,13 @@ describe("Input", () => { render(); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-radio__label") + document.querySelector(".p-radio__label"), ).toBeInTheDocument(); expect(screen.getByRole("radio")).toHaveAccessibleName("text label"); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-form__label") + document.querySelector(".p-form__label"), ).not.toBeInTheDocument(); }); @@ -35,11 +35,11 @@ describe("Input", () => { expect(screen.getByRole("checkbox")).toHaveAccessibleName("text label"); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-checkbox__label") + document.querySelector(".p-checkbox__label"), ).toBeInTheDocument(); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-form__label") + document.querySelector(".p-form__label"), ).not.toBeInTheDocument(); }); @@ -84,7 +84,7 @@ describe("Input", () => { render(); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-radio") + document.querySelector(".p-radio"), ).toHaveClass("label-class-name"); }); @@ -92,7 +92,7 @@ describe("Input", () => { render(); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-checkbox") + document.querySelector(".p-checkbox"), ).toHaveClass("label-class-name"); }); @@ -141,15 +141,15 @@ describe("Input", () => { className="extra-class" help="additional description" helpClassName="additional-help-text-class" - /> + />, ); expect(screen.getByRole("textbox")).toHaveClass( "p-form-validation__input", - "extra-class" + "extra-class", ); // eslint-disable-next-line testing-library/no-container, testing-library/no-node-access expect(container.querySelector(".p-form-help-text")).toHaveClass( - "additional-help-text-class" + "additional-help-text-class", ); }); }); diff --git a/src/components/Label/Label.test.tsx b/src/components/Label/Label.test.tsx index 179428a85..9231411bf 100644 --- a/src/components/Label/Label.test.tsx +++ b/src/components/Label/Label.test.tsx @@ -8,7 +8,7 @@ describe("Label ", () => { render( + , ); expect(screen.getByTestId("label")).toMatchSnapshot(); }); diff --git a/src/components/Link/Link.test.tsx b/src/components/Link/Link.test.tsx index 8eb9046ff..386ad92f8 100644 --- a/src/components/Link/Link.test.tsx +++ b/src/components/Link/Link.test.tsx @@ -28,7 +28,7 @@ describe("Link ", () => { render( Test content - + , ); const link = screen.getByRole("link"); expect(link).toHaveClass("p-link--soft"); diff --git a/src/components/List/List.test.tsx b/src/components/List/List.test.tsx index 2c690ca38..4b3de2e4e 100644 --- a/src/components/List/List.test.tsx +++ b/src/components/List/List.test.tsx @@ -19,7 +19,7 @@ describe("List ", () => { it("can define items as JSX", () => { render(test, items]} />); expect( - within(screen.getAllByRole("listitem")[0]).getByRole("button") + within(screen.getAllByRole("listitem")[0]).getByRole("button"), ).toBeInTheDocument(); }); @@ -32,7 +32,7 @@ describe("List ", () => { className: "item-class", }, ]} - /> + />, ); const item = within(screen.getByRole("listitem")).getByText("test"); expect(item).toBeInTheDocument(); @@ -48,7 +48,7 @@ describe("List ", () => { render(); expect(screen.getByRole("list")).toHaveClass("p-inline-list"); expect(screen.getAllByRole("listitem")[0]).toHaveClass( - "p-inline-list__item" + "p-inline-list__item", ); }); @@ -56,7 +56,7 @@ describe("List ", () => { render(); expect(screen.getByRole("list")).toHaveClass("p-inline-list--middot"); expect(screen.getAllByRole("listitem")[0]).toHaveClass( - "p-inline-list__item" + "p-inline-list__item", ); }); @@ -65,7 +65,7 @@ describe("List ", () => { expect(screen.getByRole("list")).toHaveClass("p-inline-list--stretch"); expect(screen.getByRole("list")).not.toHaveClass("p-list"); expect(screen.getAllByRole("listitem")[0]).toHaveClass( - "p-inline-list__item" + "p-inline-list__item", ); }); @@ -97,16 +97,16 @@ describe("List ", () => { content: "test", }, ]} - /> + />, ); expect(screen.getByRole("list")).toHaveClass("p-stepped-list"); const item = screen.getAllByRole("listitem")[0]; expect(item).toHaveClass("p-stepped-list__item"); expect(within(item).getByText("Test title")).toHaveClass( - "p-stepped-list__title" + "p-stepped-list__title", ); expect(within(item).getByText("test")).toHaveClass( - "p-stepped-list__content" + "p-stepped-list__content", ); }); @@ -121,16 +121,16 @@ describe("List ", () => { content: "test", }, ]} - /> + />, ); expect(screen.getByRole("list")).toHaveClass("p-stepped-list--detailed"); const item = screen.getAllByRole("listitem")[0]; expect(item).toHaveClass("p-stepped-list__item"); expect(within(item).getByText("Test title")).toHaveClass( - "p-stepped-list__title" + "p-stepped-list__title", ); expect(within(item).getByText("test")).toHaveClass( - "p-stepped-list__content" + "p-stepped-list__content", ); }); diff --git a/src/components/Loader/Loader.tsx b/src/components/Loader/Loader.tsx index 639d00d50..42ffcebec 100644 --- a/src/components/Loader/Loader.tsx +++ b/src/components/Loader/Loader.tsx @@ -10,7 +10,7 @@ import { IS_DEV } from "../../utils"; const Loader = (props: SpinnerProps): JSX.Element => { if (IS_DEV) { console.warn( - "The Loader component has been renamed to Spinner and will be removed in a future release. https://canonical.github.io/react-components/?path=/story/spinner--default-story" + "The Loader component has been renamed to Spinner and will be removed in a future release. https://canonical.github.io/react-components/?path=/story/spinner--default-story", ); } return ; diff --git a/src/components/LoginPageLayout/LoginPageLayout.test.tsx b/src/components/LoginPageLayout/LoginPageLayout.test.tsx index f41c6cd2d..567eee5f8 100644 --- a/src/components/LoginPageLayout/LoginPageLayout.test.tsx +++ b/src/components/LoginPageLayout/LoginPageLayout.test.tsx @@ -9,7 +9,7 @@ it("should display the default logo", () => { const link = screen.getByRole("link", { name: "Logo Canonical" }); expect(within(link).getByRole("img", { name: "Logo" })).toHaveAttribute( "src", - "https://assets.ubuntu.com/v1/82818827-CoF_white.svg" + "https://assets.ubuntu.com/v1/82818827-CoF_white.svg", ); }); @@ -18,19 +18,19 @@ it("should display a custom logo", () => { + />, ); const link = screen.getByRole("link", { name: "Logo My logo" }); expect(within(link).getByRole("img", { name: "Logo" })).toHaveAttribute( "src", - "logo.png" + "logo.png", ); }); it("should display the title", () => { render(); expect( - screen.getByRole("heading", { name: "Login page" }) + screen.getByRole("heading", { name: "Login page" }), ).toBeInTheDocument(); }); diff --git a/src/components/MainTable/MainTable.test.tsx b/src/components/MainTable/MainTable.test.tsx index c18814da9..ac5f432de 100644 --- a/src/components/MainTable/MainTable.test.tsx +++ b/src/components/MainTable/MainTable.test.tsx @@ -101,7 +101,7 @@ describe("MainTable", () => { expect(columns.length).toEqual(rows[rows.length - 1].columns.length + 1); const expandingColumn = columns[columns.length - 1]; expect(expandingColumn.classList.contains("p-table__expanding-panel")).toBe( - true + true, ); expect(expandingColumn.textContent).toBe("Expand this"); }); @@ -115,14 +115,14 @@ describe("MainTable", () => { render(); expect(screen.getAllByRole("rowheader")[0]).toHaveAttribute( "data-heading", - "Status" + "Status", ); }); it("doesn't contain data-heading attribute if there is no heading", () => { render(); expect(screen.getAllByRole("rowheader")[0]).not.toHaveAttribute( - "data-heading" + "data-heading", ); }); @@ -131,14 +131,14 @@ describe("MainTable", () => { render(); expect(screen.getAllByRole("gridcell")[2]).toHaveAttribute( "data-heading", - "Replacement" + "Replacement", ); }); it("can be paginated", () => { render(); expect( - screen.getByRole("button", { name: PaginationButtonLabel.Next }) + screen.getByRole("button", { name: PaginationButtonLabel.Next }), ).toBeInTheDocument(); expect(screen.getAllByRole("row")).toHaveLength(2); }); @@ -146,7 +146,7 @@ describe("MainTable", () => { it("can change the page", async () => { render(); await userEvent.click( - screen.getByRole("button", { name: PaginationButtonLabel.Next }) + screen.getByRole("button", { name: PaginationButtonLabel.Next }), ); expect(screen.getAllByRole("row")).toHaveLength(1); expect(screen.getAllByRole("rowheader")[0].textContent).toEqual("Idle"); @@ -174,11 +174,11 @@ describe("MainTable", () => { render(); // Sortable headers should have the sort prop set. expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "none"); // non-sortable headers should not have the sort prop set. expect( - screen.getByRole("columnheader", { name: "Disks" }) + screen.getByRole("columnheader", { name: "Disks" }), ).not.toHaveAttribute("aria-sort"); }); @@ -187,63 +187,63 @@ describe("MainTable", () => { const rowItems = screen.getAllByRole("row"); // Check the initial status order. expect(within(rowItems[1]).getByRole("rowheader").textContent).toBe( - "Ready" + "Ready", ); expect(within(rowItems[2]).getByRole("rowheader").textContent).toBe( - "Waiting" + "Waiting", ); expect(within(rowItems[3]).getByRole("rowheader").textContent).toBe( - "Idle" + "Idle", ); await userEvent.click( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ); // The status should now be ascending. expect(within(rowItems[1]).getByRole("rowheader").textContent).toBe( - "Idle" + "Idle", ); expect(within(rowItems[2]).getByRole("rowheader").textContent).toBe( - "Ready" + "Ready", ); expect(within(rowItems[3]).getByRole("rowheader").textContent).toBe( - "Waiting" + "Waiting", ); await userEvent.click( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ); // The status should now be descending. expect(within(rowItems[1]).getByRole("rowheader").textContent).toBe( - "Waiting" + "Waiting", ); expect(within(rowItems[2]).getByRole("rowheader").textContent).toBe( - "Ready" + "Ready", ); expect(within(rowItems[3]).getByRole("rowheader").textContent).toBe( - "Idle" + "Idle", ); await userEvent.click( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ); // The status be back to the original order. expect(within(rowItems[1]).getByRole("rowheader").textContent).toBe( - "Ready" + "Ready", ); expect(within(rowItems[2]).getByRole("rowheader").textContent).toBe( - "Waiting" + "Waiting", ); expect(within(rowItems[3]).getByRole("rowheader").textContent).toBe( - "Idle" + "Idle", ); }); @@ -251,14 +251,14 @@ describe("MainTable", () => { render(); const rowItems = screen.getAllByRole("row"); await userEvent.click( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ); const expectedOrder = ["Idle", "Ready", "Waiting"]; // The status should now be ascending. for (let i = 1; i < 4; i++) { expect(within(rowItems[i]).getByRole("rowheader").textContent).toBe( - expectedOrder[i - 1] + expectedOrder[i - 1], ); } @@ -266,7 +266,7 @@ describe("MainTable", () => { // The status should not change for (let i = 1; i < 4; i++) { expect(within(rowItems[i]).getByRole("rowheader").textContent).toBe( - expectedOrder[i - 1] + expectedOrder[i - 1], ); } @@ -274,7 +274,7 @@ describe("MainTable", () => { // The status should not change for (let i = 1; i < 4; i++) { expect(within(rowItems[i]).getByRole("rowheader").textContent).toBe( - expectedOrder[i - 1] + expectedOrder[i - 1], ); } }); @@ -287,11 +287,11 @@ describe("MainTable", () => { headers={headers} rows={rows} sortable={true} - /> + />, ); // Sortable headers should have the sort prop set. expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "descending"); }); @@ -303,13 +303,13 @@ describe("MainTable", () => { headers={headers} rows={rows} sortable={true} - /> + />, ); expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "descending"); expect( - screen.getByRole("columnheader", { name: "Cores" }) + screen.getByRole("columnheader", { name: "Cores" }), ).toHaveAttribute("aria-sort", "none"); rerender( { headers={headers} rows={rows} sortable={true} - /> + />, ); expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "none"); expect( - screen.getByRole("columnheader", { name: "Cores" }) + screen.getByRole("columnheader", { name: "Cores" }), ).toHaveAttribute("aria-sort", "ascending"); }); @@ -339,12 +339,12 @@ describe("MainTable", () => { rows={rows} sortable={true} hiddenCaption={captionText} - /> + />, ); // can't target the caption using getByRole :( expect(screen.getByTestId("hidden-caption").textContent).toEqual( - captionText + captionText, ); }); }); diff --git a/src/components/MainTable/MainTable.tsx b/src/components/MainTable/MainTable.tsx index 0f812ac59..88934c6c4 100644 --- a/src/components/MainTable/MainTable.tsx +++ b/src/components/MainTable/MainTable.tsx @@ -117,7 +117,7 @@ export type Props = PropsWithSpread< a: MainTableRow, b: MainTableRow, currentSortDirection: SortDirection, - currentSortKey: MainTableHeader["sortKey"] + currentSortKey: MainTableHeader["sortKey"], ) => -1 | 0 | 1; /** * A hidden caption to display on the table for screen readers @@ -131,7 +131,7 @@ const updateSort = ( setSortKey: (sortKey: MainTableHeader["sortKey"]) => void, setSortDirection: (direction: SortDirection) => void, sortKey: MainTableHeader["sortKey"], - sortDirection: SortDirection + sortDirection: SortDirection, ) => { let newDirection = null; if (sortDirection === "none") { @@ -152,7 +152,7 @@ const generateHeaders = ( headers: Props["headers"], sortable: Props["sortable"], setSortKey: (sortKey: MainTableHeader["sortKey"]) => void, - setSortDirection: (direction: SortDirection) => void + setSortDirection: (direction: SortDirection) => void, ) => { const headerItems = headers.map(({ content, sortKey, ...props }, index) => { let sortDirection: SortDirection; @@ -174,7 +174,7 @@ const generateHeaders = ( setSortKey, setSortDirection, sortKey, - sortDirection + sortDirection, ) : undefined } @@ -206,7 +206,7 @@ const generateRows = ({ rows.map( ( { columns, expanded, expandedContent, key, sortData, ...rowProps }, - index + index, ) => { const cellItems = columns?.map(({ content, ...cellProps }, index) => { const headerContent = headers && headers[index]["content"]; @@ -242,7 +242,7 @@ const generateRows = ({ )} ); - } + }, ); const sortRows = ({ @@ -275,7 +275,7 @@ const sortRows = ({ }; } sortedRows.sort((a, b) => - sortFunction(a, b, currentSortDirection, currentSortKey) + sortFunction(a, b, currentSortDirection, currentSortKey), ); } return sortedRows; @@ -327,7 +327,7 @@ const MainTable = ({ sortable, sortFunction, }), - [currentSortDirection, currentSortKey, rows, sortable, sortFunction] + [currentSortDirection, currentSortKey, rows, sortable, sortFunction], ); const { @@ -365,7 +365,7 @@ const MainTable = ({ headers, sortable, updateSort, - setSortDirection + setSortDirection, )} { // If the table has no rows, return empty state message diff --git a/src/components/Modal/Modal.test.tsx b/src/components/Modal/Modal.test.tsx index b596f1af8..8792a4153 100644 --- a/src/components/Modal/Modal.test.tsx +++ b/src/components/Modal/Modal.test.tsx @@ -14,14 +14,14 @@ describe("Modal ", () => { ]} > Button tester - + , ); expect(screen.getAllByRole("button").length).toEqual(2); }); it("displays any content in the button row", () => { const { container } = render( - I am not a button}>Button tester + I am not a button}>Button tester, ); expect(container.innerHTML).toContain("I am not a button"); expect(container.innerHTML).toContain("Button tester"); @@ -31,7 +31,7 @@ describe("Modal ", () => { const { container } = render( Are you sure? - + , ); expect(container.querySelector(".p-modal__button-row")).toBeNull(); }); @@ -48,7 +48,7 @@ describe("Modal ", () => { it("can pass extra classes to the wrapper", () => { const { container } = render( - Bare bones. + Bare bones., ); expect(container.querySelector(".extra-class")).toBeInTheDocument(); }); @@ -57,10 +57,10 @@ describe("Modal ", () => { const { container } = render( My modal - + , ); expect(container.querySelector("button.p-modal__close")).toBe( - document.activeElement + document.activeElement, ); }); @@ -77,7 +77,7 @@ describe("Modal ", () => { } > Bare bones - + , ); const closeButton = container.querySelector("button.p-modal__close"); @@ -94,7 +94,7 @@ describe("Modal ", () => { const { container } = render( Bare bones - + , ); const closeButton = container.querySelector("button.p-modal__close"); @@ -132,7 +132,7 @@ describe("Modal ", () => { Bare bones - + , ); await userEvent.keyboard("{Escape}"); @@ -147,7 +147,7 @@ describe("Modal ", () => { Bare bones - + , ); const closeButton = container.querySelector("button.p-modal__close"); @@ -163,7 +163,7 @@ describe("Modal ", () => { Bare bones - + , ); const closeButton = container.querySelector("button.p-modal__close"); diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index cca0e6f96..e264d58ae 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -78,7 +78,7 @@ export const Modal = ({ }; const handleEscKey = ( - event: KeyboardEvent | React.KeyboardEvent + event: KeyboardEvent | React.KeyboardEvent, ) => { if ("nativeEvent" in event && event.nativeEvent.stopImmediatePropagation) { event.nativeEvent.stopImmediatePropagation(); @@ -103,7 +103,7 @@ export const Modal = ({ useEffect(() => { focusableModalElements.current = modalRef.current.querySelectorAll( - focusableElementSelectors + focusableElementSelectors, ); let focusIndex = 0; // when the close button is rendered, focus on the 2nd content element and not the close btn. @@ -134,7 +134,7 @@ export const Modal = ({ }; const handleOverlayOnMouseDown = ( - event: React.MouseEvent + event: React.MouseEvent, ) => { if (event.target === modalRef.current) { shouldClose.current = true; diff --git a/src/components/ModularTable/ModularTable.stories.tsx b/src/components/ModularTable/ModularTable.stories.tsx index c7c063499..2a3899cf7 100644 --- a/src/components/ModularTable/ModularTable.stories.tsx +++ b/src/components/ModularTable/ModularTable.stories.tsx @@ -79,7 +79,7 @@ export const Default: Story = { className: "u-align-text--right", }, ], - [] + [], )} // eslint-disable-next-line react-hooks/rules-of-hooks data={React.useMemo( @@ -106,7 +106,7 @@ export const Default: Story = { finished: "ages ago", }, ], - [] + [], )} /> ), @@ -143,7 +143,7 @@ export const Empty: Story = { className: "u-align-text--right", }, ], - [] + [], )} data={[]} emptyMsg="Waiting for data..." @@ -217,7 +217,7 @@ export const Sortable: Story = { sortType: "basic", }, ], - [] + [], )} // eslint-disable-next-line react-hooks/rules-of-hooks data={React.useMemo( @@ -244,7 +244,7 @@ export const Sortable: Story = { finished: "ages ago", }, ], - [] + [], )} /> ), @@ -290,7 +290,7 @@ export const Subrows: Story = { ), }, ], - [] + [], )} // eslint-disable-next-line react-hooks/rules-of-hooks data={React.useMemo( @@ -334,7 +334,7 @@ export const Subrows: Story = { ], }, ], - [] + [], )} /> ), diff --git a/src/components/ModularTable/ModularTable.test.tsx b/src/components/ModularTable/ModularTable.test.tsx index 923707c21..67dd28c7c 100644 --- a/src/components/ModularTable/ModularTable.test.tsx +++ b/src/components/ModularTable/ModularTable.test.tsx @@ -92,19 +92,19 @@ describe("ModularTable", () => { initialSortColumn="disks" initialSortDirection="descending" sortable - /> + />, ); const tableBody = screen.getAllByRole("rowgroup")[1]; const rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(3); expect(within(rowItems[0]).queryAllByRole("cell")[3]).toHaveTextContent( - "3" + "3", ); expect(within(rowItems[1]).queryAllByRole("cell")[3]).toHaveTextContent( - "2" + "2", ); expect(within(rowItems[2]).queryAllByRole("cell")[3]).toHaveTextContent( - "2" + "2", ); }); @@ -136,13 +136,13 @@ describe("ModularTable", () => { const rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(3); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Waiting" + "Waiting", ); expect(within(rowItems[2]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); }); @@ -179,30 +179,30 @@ describe("ModularTable", () => { const tableBody = screen.getAllByRole("rowgroup")[1]; let rowItems = within(tableBody).getAllByRole("row"); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Waiting" + "Waiting", ); expect(within(rowItems[2]).queryAllByRole("cell")[0]).toHaveTextContent( - "Error" + "Error", ); expect(within(rowItems[3]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); await userEvent.click(screen.getByRole("columnheader", { name: "Cores" })); rowItems = within(tableBody).getAllByRole("row"); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[2]).queryAllByRole("cell")[0]).toHaveTextContent( - "Error" + "Error", ); expect(within(rowItems[3]).queryAllByRole("cell")[0]).toHaveTextContent( - "Waiting" + "Waiting", ); }); @@ -215,7 +215,7 @@ describe("ModularTable", () => { it("renders empty message when data is empty", () => { render( - + , ); const rowItems = screen.getAllByRole("row"); @@ -223,13 +223,13 @@ describe("ModularTable", () => { expect( within(rowItems[rowItems.length - 1]).getByRole("gridcell", { name: "Nothing here", - }) + }), ).toBeInTheDocument(); }); it("renders a row with footer content", () => { render( - + , ); const rowItems = screen.getAllByRole("row"); @@ -237,7 +237,7 @@ describe("ModularTable", () => { expect( within(rowItems[rowItems.length - 1]).getByRole("gridcell", { name: "This is a footer", - }) + }), ).toBeInTheDocument(); }); @@ -258,11 +258,11 @@ describe("ModularTable", () => { ? "This is a cell with custom label" : undefined, })} - /> + />, ); expect( - screen.getByRole("cell", { name: "This is a cell with custom label" }) + screen.getByRole("cell", { name: "This is a cell with custom label" }), ).toBeInTheDocument(); }); @@ -274,7 +274,7 @@ describe("ModularTable", () => { getCellProps={({ column }) => ({ role: column.id === "status" ? "rowheader" : undefined, })} - /> + />, ); const tableBody = screen.getAllByRole("rowgroup")[1]; const rowItems = within(tableBody).getAllByRole("row"); @@ -294,13 +294,13 @@ describe("ModularTable", () => { "aria-label": row.values.status === "Idle" ? "Custom idle row label" : undefined, })} - /> + />, ); const tableBody = screen.getAllByRole("rowgroup")[1]; expect( within(tableBody).getByRole("row", { name: "Custom idle row label", - }) + }), ).toBeInTheDocument(); }); @@ -347,33 +347,33 @@ describe("ModularTable", () => { let rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click(screen.getByRole("columnheader", { name: "Cores" })); rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); await userEvent.click( - screen.getByRole("button", { name: "Change table data" }) + screen.getByRole("button", { name: "Change table data" }), ); rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(3); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Error" + "Error", ); expect(within(rowItems[2]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); }); @@ -396,33 +396,33 @@ describe("ModularTable", () => { expect(screen.getAllByRole("columnheader")).toHaveLength(2); expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "none"); expect( - screen.getByRole("columnheader", { name: "Not Sortable" }) + screen.getByRole("columnheader", { name: "Not Sortable" }), ).not.toHaveAttribute("aria-sort"); const tableBody = screen.getAllByRole("rowgroup")[1]; let rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click( - screen.getByRole("columnheader", { name: "Not Sortable" }) + screen.getByRole("columnheader", { name: "Not Sortable" }), ); rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); }); @@ -458,10 +458,10 @@ describe("ModularTable", () => { let rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click(header[1]); @@ -469,10 +469,10 @@ describe("ModularTable", () => { rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click(header[2]); @@ -480,10 +480,10 @@ describe("ModularTable", () => { rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); }); @@ -510,21 +510,21 @@ describe("ModularTable", () => { expect(screen.getAllByRole("columnheader")).toHaveLength(2); expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "none"); expect(screen.getByRole("columnheader", { name: "0" })).toHaveAttribute( "aria-sort", - "none" + "none", ); const tableBody = screen.getAllByRole("rowgroup")[1]; let rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click(screen.getByRole("columnheader", { name: "0" })); @@ -532,10 +532,10 @@ describe("ModularTable", () => { rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); }); @@ -562,21 +562,21 @@ describe("ModularTable", () => { expect(screen.getAllByRole("columnheader")).toHaveLength(2); expect( - screen.getByRole("columnheader", { name: "Status" }) + screen.getByRole("columnheader", { name: "Status" }), ).toHaveAttribute("aria-sort", "none"); expect(screen.getByRole("columnheader", { name: "JSX" })).toHaveAttribute( "aria-sort", - "none" + "none", ); const tableBody = screen.getAllByRole("rowgroup")[1]; let rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); await userEvent.click(screen.getByRole("columnheader", { name: "JSX" })); @@ -584,10 +584,10 @@ describe("ModularTable", () => { rowItems = within(tableBody).getAllByRole("row"); expect(rowItems).toHaveLength(2); expect(within(rowItems[0]).queryAllByRole("cell")[0]).toHaveTextContent( - "Ready" + "Ready", ); expect(within(rowItems[1]).queryAllByRole("cell")[0]).toHaveTextContent( - "Idle" + "Idle", ); }); }); diff --git a/src/components/ModularTable/ModularTable.tsx b/src/components/ModularTable/ModularTable.tsx index e7004b3c3..7c70a2a1f 100644 --- a/src/components/ModularTable/ModularTable.tsx +++ b/src/components/ModularTable/ModularTable.tsx @@ -46,19 +46,19 @@ export type Props> = PropsWithSpread< * This function is used to resolve any props needed for a particular column's header cell. */ getHeaderProps?: ( - header: HeaderGroup + header: HeaderGroup, ) => Partial>; /** * This function is used to resolve any props needed for a particular row. */ getRowProps?: ( - row: Row + row: Row, ) => Partial>; /** * This function is used to resolve any props needed for a particular cell. */ getCellProps?: ( - cell: Cell + cell: Cell, ) => Partial>; getRowId?: UseTableOptions["getRowId"]; /** @@ -79,7 +79,7 @@ export type Props> = PropsWithSpread< const generateCell = >( cell: Cell, - getCellProps: Props["getCellProps"] + getCellProps: Props["getCellProps"], ) => { const hasColumnIcon = cell.column.getCellIcon; const iconName = hasColumnIcon && cell.column.getCellIcon?.(cell); @@ -106,7 +106,7 @@ const generateRows = >( rows: Row[], prepareRow: (row: Row) => void, getRowProps: Props["getRowProps"], - getCellProps: Props["getCellProps"] + getCellProps: Props["getCellProps"], ) => { let tableRows: ReactNode[] = []; rows.forEach((row) => { @@ -117,11 +117,11 @@ const generateRows = >( tableRows.push( {row.cells.map((cell) => generateCell(cell, getCellProps))} - + , ); if (row.subRows?.length) { tableRows = tableRows.concat( - generateRows(row.subRows, prepareRow, getRowProps, getCellProps) + generateRows(row.subRows, prepareRow, getRowProps, getCellProps), ); } }); @@ -205,7 +205,7 @@ function ModularTable>({ }, ] : [], - [initialSortColumn, initialSortDirection] + [initialSortColumn, initialSortDirection], ); const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable( @@ -218,7 +218,7 @@ function ModularTable>({ }, autoResetSortBy, }, - sortable ? useSortBy : undefined + sortable ? useSortBy : undefined, ); const showEmpty: boolean = !!emptyMsg && (!rows || rows.length === 0); diff --git a/src/components/MultiSelect/FadeInDown/FadeInDown.test.tsx b/src/components/MultiSelect/FadeInDown/FadeInDown.test.tsx index 73f218756..3ef4778d2 100644 --- a/src/components/MultiSelect/FadeInDown/FadeInDown.test.tsx +++ b/src/components/MultiSelect/FadeInDown/FadeInDown.test.tsx @@ -7,7 +7,7 @@ it("renders with correct attributes", () => { render(
Content
-
+ , ); // eslint-disable-next-line testing-library/no-node-access @@ -20,14 +20,14 @@ it("hides and reveals children", () => { const { rerender } = render(
Content
-
+ , ); expect(screen.getByText("Content")).toBeInTheDocument(); rerender(
Test child
-
+ , ); expect(screen.queryByText("Content")).not.toBeInTheDocument(); diff --git a/src/components/MultiSelect/MultiSelect.stories.tsx b/src/components/MultiSelect/MultiSelect.stories.tsx index c94821f2d..0ba38f1f4 100644 --- a/src/components/MultiSelect/MultiSelect.stories.tsx +++ b/src/components/MultiSelect/MultiSelect.stories.tsx @@ -6,7 +6,7 @@ import { MultiSelect, MultiSelectItem, MultiSelectProps } from "./MultiSelect"; const Template = (props: MultiSelectProps) => { const [selectedItems, setSelectedItems] = useState( - props.selectedItems || [] + props.selectedItems || [], ); return ( { items.forEach((item) => { expect( - screen.queryByRole("checkbox", { name: item.label }) + screen.queryByRole("checkbox", { name: item.label }), ).not.toBeInTheDocument(); }); @@ -23,7 +23,7 @@ it("shows options when opened", async () => { items.forEach((item) => { expect( - screen.getByRole("checkbox", { name: item.label }) + screen.getByRole("checkbox", { name: item.label }), ).toBeInTheDocument(); }); }); @@ -37,15 +37,19 @@ it("opens the dropdown when the combobox is clicked", async () => { it("can have some options preselected", async () => { render( - + , ); expect(screen.getByRole("combobox")).toHaveTextContent(items[0].label); expect( - screen.queryByRole("checkbox", { name: items[0].label }) + screen.queryByRole("checkbox", { name: items[0].label }), ).not.toBeInTheDocument(); await userEvent.click(screen.getByRole("combobox")); expect( - screen.getByRole("checkbox", { name: items[0].label }) + screen.getByRole("checkbox", { name: items[0].label }), ).toBeInTheDocument(); }); @@ -57,7 +61,7 @@ it("can select options from the dropdown", async () => { items={items} onItemsUpdate={onItemsUpdate} onSelectItem={onSelectItem} - /> + />, ); await userEvent.click(screen.getByRole("combobox")); await userEvent.click(screen.getByLabelText(items[0].label)); @@ -74,12 +78,12 @@ it("can remove options that have been selected", async () => { selectedItems={items} onItemsUpdate={onItemsUpdate} onDeselectItem={onDeselectItem} - /> + />, ); await userEvent.click(screen.getByRole("combobox")); expect(screen.getAllByRole("listitem")).toHaveLength(3); await userEvent.click( - within(screen.getByRole("listbox")).getByLabelText(items[0].label) + within(screen.getByRole("listbox")).getByLabelText(items[0].label), ); expect(onItemsUpdate).toHaveBeenCalledWith(items.slice(1)); expect(onDeselectItem).toHaveBeenCalledWith(items[0]); @@ -99,14 +103,14 @@ it("can display a custom dropdown header and footer", async () => { dropdownHeader={} dropdownFooter={} items={items} - /> + />, ); await userEvent.click(screen.getByRole("combobox")); expect( - screen.getByRole("button", { name: "custom header button" }) + screen.getByRole("button", { name: "custom header button" }), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: "custom footer button" }) + screen.getByRole("button", { name: "custom footer button" }), ).toBeInTheDocument(); }); @@ -116,18 +120,22 @@ it("can not display the footer", async () => { dropdownFooter={} items={items} showDropdownFooter={false} - /> + />, ); await userEvent.click(screen.getByRole("combobox")); expect( - screen.queryByRole("button", { name: "custom footer button" }) + screen.queryByRole("button", { name: "custom footer button" }), ).not.toBeInTheDocument(); }); it("selects all items and clears selection when respective buttons are clicked", async () => { const onItemsUpdate = jest.fn(); render( - + , ); await userEvent.click(screen.getByRole("combobox")); await userEvent.type(screen.getByRole("combobox"), "item"); @@ -155,7 +163,11 @@ it("closes the dropdown when clicking on the button", async () => { it("updates text in the input field if something is selected", async () => { render( - + , ); expect(screen.getByRole("combobox")).toHaveTextContent(items[0].label); }); @@ -169,7 +181,7 @@ it("can display the placeholder when items are selected", async () => { variant="condensed" listSelected={false} placeholder={placeholder} - /> + />, ); expect(screen.getByRole("combobox")).toHaveTextContent(placeholder); }); @@ -186,7 +198,7 @@ it("can have one or more sections with titles", async () => { itemsWithGroup.forEach((item) => { expect( - screen.getByRole("heading", { name: item.group }) + screen.getByRole("heading", { name: item.group }), ).toBeInTheDocument(); expect(screen.getByRole("list", { name: item.group })).toBeInTheDocument(); }); @@ -205,15 +217,15 @@ it("sorts grouped options alphabetically", async () => { const checkGroupOrder = async ( groupName: string, - expectedLabels: string[] + expectedLabels: string[], ) => { const group = screen.getByRole("list", { name: groupName }); await waitFor(() => within(group) .getAllByRole("listitem") .forEach((item, index) => - expect(item).toHaveTextContent(expectedLabels[index]) - ) + expect(item).toHaveTextContent(expectedLabels[index]), + ), ); }; @@ -234,7 +246,7 @@ it("hides group title when no items match the search query", async () => { await userEvent.type(screen.getByRole("combobox"), "item two"); expect( - screen.queryByRole("heading", { name: "Group 1" }) + screen.queryByRole("heading", { name: "Group 1" }), ).not.toBeInTheDocument(); expect(screen.getByRole("heading", { name: "Group 2" })).toBeInTheDocument(); }); diff --git a/src/components/MultiSelect/MultiSelect.tsx b/src/components/MultiSelect/MultiSelect.tsx index e5aa95dfe..2cdcc768b 100644 --- a/src/components/MultiSelect/MultiSelect.tsx +++ b/src/components/MultiSelect/MultiSelect.tsx @@ -35,7 +35,7 @@ export type MultiSelectProps = { type ValueSet = Set; type GroupFn = ( - items: Parameters[0] + items: Parameters[0], ) => ReturnType; type SortFn = typeof sortAlphabetically; type MultiSelectDropdownProps = { @@ -97,11 +97,11 @@ export const MultiSelectDropdown: React.FC = ({ }: MultiSelectDropdownProps) => { const selectedItemValues = useMemo( () => new Set(selectedItems.map((item) => item.value)), - [selectedItems] + [selectedItems], ); const disabledItemValues = useMemo( () => new Set(disabledItems.map((item) => item.value)), - [disabledItems] + [disabledItems], ); const [previouslySelectedItemValues, setPreviouslySelectedItemValues] = useState(new Set(selectedItemValues)); @@ -117,7 +117,7 @@ export const MultiSelectDropdown: React.FC = ({ const groupedItems = useMemo( () => (hasGroup ? groupFn(items) : [{ group: "Ungrouped", items }]), // eslint-disable-next-line react-hooks/exhaustive-deps - [items, groupFn] + [items, groupFn], ); const handleOnChange = (event: React.ChangeEvent) => { const { checked, value } = event.target; @@ -211,7 +211,7 @@ export const MultiSelect: React.FC = ({ const inputId = useId(); const selectedItemsLabel = selectedItems .filter((selectedItem) => - items.some((item) => item.value === selectedItem.value) + items.some((item) => item.value === selectedItem.value), ) .map((el) => el.label) .join(", "); @@ -227,8 +227,8 @@ export const MultiSelect: React.FC = ({ const enabledItems = items.filter( (item) => !disabledItems.some( - (disabledItem) => disabledItem.value === item.value - ) + (disabledItem) => disabledItem.value === item.value, + ), ); updateItems([...selectedItems, ...enabledItems]); }} @@ -241,8 +241,8 @@ export const MultiSelect: React.FC = ({ onClick={() => { const disabledSelectedItems = selectedItems.filter((item) => disabledItems.some( - (disabledItem) => disabledItem.value === item.value - ) + (disabledItem) => disabledItem.value === item.value, + ), ); updateItems(disabledSelectedItems); }} @@ -333,7 +333,7 @@ export const MultiSelect: React.FC = ({ items={ filter.length > 0 ? items.filter((item) => - item.label.toLowerCase().includes(filter.toLowerCase()) + item.label.toLowerCase().includes(filter.toLowerCase()), ) : items } diff --git a/src/components/Navigation/Navigation.test.tsx b/src/components/Navigation/Navigation.test.tsx index 3fef6df84..ec7de53a7 100644 --- a/src/components/Navigation/Navigation.test.tsx +++ b/src/components/Navigation/Navigation.test.tsx @@ -29,7 +29,7 @@ it("displays full width", () => { render(} />); expect( - document.querySelector(".p-navigation__row--full-width") + document.querySelector(".p-navigation__row--full-width"), ).toBeInTheDocument(); expect(document.querySelector(".p-navigation__row")).not.toBeInTheDocument(); }); @@ -39,10 +39,10 @@ it("passes additional classes to the header element", () => { } - /> + />, ); expect(screen.getByRole("banner")).toHaveClass( - "p-navigation not-a-footer-thats-for-sure" + "p-navigation not-a-footer-thats-for-sure", ); }); @@ -51,11 +51,11 @@ it("passes additional props to the header element", () => { } - /> + />, ); expect(screen.getByRole("banner")).toHaveAttribute( "aria-label", - "This is definitely the header" + "This is definitely the header", ); }); @@ -68,7 +68,7 @@ it("can display a standard logo", () => { title: "This is the site name", url: "/this/is/the/logo/link", }} - /> + />, ); const homePageLink = screen.getByRole("link", { name: "Homepage" }); expect(homePageLink).toBeInTheDocument(); @@ -100,7 +100,7 @@ it("can display a standard logo with a generated link", () => { title: "This is the site name", url: "/this/is/the/logo/link", }} - /> + />, ); const homePageLink = screen.getByRole("link", { name: "Homepage" }); expect(homePageLink).toBeInTheDocument(); @@ -121,12 +121,12 @@ it("can provide a custom logo", () => { This logo is totally not anything like the normal one. } - /> + />, ); expect( screen.getByRole("link", { name: "This logo is totally not anything like the normal one.", - }) + }), ).toBeInTheDocument(); }); @@ -135,10 +135,10 @@ it("can display menus", () => { } - /> + />, ); expect( - screen.getByRole("button", { name: "THIS IS A MENU" }) + screen.getByRole("button", { name: "THIS IS A MENU" }), ).toBeInTheDocument(); }); @@ -147,10 +147,10 @@ it("can display links", () => { } - /> + />, ); expect( - screen.getByRole("link", { name: "THIS IS A LINK" }) + screen.getByRole("link", { name: "THIS IS A LINK" }), ).toBeInTheDocument(); }); @@ -165,10 +165,10 @@ it("can pass additional classes to links", () => { }, ]} logo={} - /> + />, ); expect(screen.getByRole("link", { name: "THIS IS A LINK" })).toHaveClass( - "p-navigation__link this-link-has-a-very-nice-custom-class" + "p-navigation__link this-link-has-a-very-nice-custom-class", ); }); @@ -184,12 +184,12 @@ it("can mark a nav item as selected", () => { ]} leftNavProps={{ "aria-label": "Left nav" }} logo={} - /> + />, ); expect( within(screen.getByLabelText("Left nav")) .getByRole("listitem") - .className.includes("is-selected") + .className.includes("is-selected"), ).toBe(true); }); @@ -198,18 +198,18 @@ it("displays without search", () => { expect( screen.queryByRole("button", { name: "Search", - }) + }), ).not.toBeInTheDocument(); expect( screen.queryByRole("listitem", { name: "Search", - }) + }), ).not.toBeInTheDocument(); expect( - document.querySelector(".p-navigation__search") + document.querySelector(".p-navigation__search"), ).not.toBeInTheDocument(); expect( - document.querySelector(".p-navigation__search-overlay") + document.querySelector(".p-navigation__search-overlay"), ).not.toBeInTheDocument(); }); @@ -219,19 +219,19 @@ it("displays with search", () => { logo={} searchProps={{ onSearch: jest.fn() }} rightNavProps={{ "aria-label": "Right nav" }} - /> + />, ); expect( within(screen.getByLabelText("Right nav")).getByRole("button", { name: "Search", - }) + }), ).toBeInTheDocument(); expect( - document.querySelector(".p-navigation__link--search-toggle") + document.querySelector(".p-navigation__link--search-toggle"), ).toBeInTheDocument(); expect(document.querySelector(".p-navigation__search")).toBeInTheDocument(); expect( - document.querySelector(".p-navigation__search-overlay") + document.querySelector(".p-navigation__search-overlay"), ).toBeInTheDocument(); }); @@ -240,11 +240,11 @@ it("can open the search form", async () => { } searchProps={{ onSearch: jest.fn() }} - /> + />, ); await userEvent.click(screen.getAllByRole("button", { name: "Search" })[0]); expect(screen.getByRole("banner").className.includes("has-search-open")).toBe( - true + true, ); expect(screen.getByRole("searchbox")).toBeInTheDocument(); }); @@ -254,7 +254,7 @@ it("focuses on the searchbox when it appears", async () => { } searchProps={{ onSearch: jest.fn() }} - /> + />, ); await userEvent.click(screen.getAllByRole("button", { name: "Search" })[0]); expect(screen.getByRole("searchbox")).toHaveFocus(); @@ -265,11 +265,11 @@ it("closes the search form when the escape key is pressed", async () => { } searchProps={{ onSearch: jest.fn() }} - /> + />, ); await userEvent.click(screen.getAllByRole("button", { name: "Search" })[0]); expect(screen.getByRole("banner").className.includes("has-search-open")).toBe( - true + true, ); expect(screen.getByRole("searchbox")).toBeInTheDocument(); fireEvent.keyDown(document, { key: "Escape", code: "Escape" }); @@ -282,7 +282,7 @@ it("closes the search form when opening the mobile menu", async () => { items={items} logo={} searchProps={{ onSearch: jest.fn() }} - /> + />, ); const banner = screen.getByRole("banner"); // Open the search form. @@ -298,7 +298,7 @@ it("closes the search form when clicking on the overlay", async () => { } searchProps={{ onSearch: jest.fn() }} - /> + />, ); const banner = screen.getByRole("banner"); // Open the search form. @@ -306,7 +306,7 @@ it("closes the search form when clicking on the overlay", async () => { expect(banner.className.includes("has-search-open")).toBe(true); expect(screen.getByRole("searchbox")).toBeInTheDocument(); await userEvent.click( - document.querySelector(".p-navigation__search-overlay") + document.querySelector(".p-navigation__search-overlay"), ); expect(banner.className.includes("has-search-open")).toBe(false); expect(screen.queryByRole("searchbox")).not.toBeInTheDocument(); @@ -318,7 +318,7 @@ it("closes the mobile menu when opening the search form", async () => { items={items} logo={} searchProps={{ onSearch: jest.fn() }} - /> + />, ); const banner = screen.getByRole("banner"); // Open the mobile menu. @@ -339,11 +339,11 @@ it("can open the mobile menu", async () => { it("hides the mobile menu button when there are no navigation items to display", () => { render( - } /> + } />, ); const banner = screen.getByRole("banner"); expect( - within(banner).queryByRole("button", { name: "Menu" }) + within(banner).queryByRole("button", { name: "Menu" }), ).not.toBeInTheDocument(); }); @@ -352,7 +352,7 @@ it("closes the mobile menu when clicking on a nav link", async () => { } - /> + />, ); const banner = screen.getByRole("banner"); await userEvent.click(screen.getByRole("button", { name: "Menu" })); @@ -366,7 +366,7 @@ it("does not close the mobile menu when clicking on a nav menu", async () => { } - /> + />, ); const banner = screen.getByRole("banner"); await userEvent.click(screen.getByRole("button", { name: "Menu" })); diff --git a/src/components/Navigation/Navigation.tsx b/src/components/Navigation/Navigation.tsx index 7a8392654..5dd87c2f0 100644 --- a/src/components/Navigation/Navigation.tsx +++ b/src/components/Navigation/Navigation.tsx @@ -131,7 +131,7 @@ const generateLogo = (logo: Props["logo"], generateLink: GenerateLink) => { const generateItems = ( items: NavItem[], closeMobileMenu: () => void, - generateLink?: GenerateLink | null + generateLink?: GenerateLink | null, ) => items.map((item, i) => isMenu(item) ? ( @@ -155,7 +155,7 @@ const generateItems = ( }} /> - ) + ), ); /** diff --git a/src/components/Navigation/NavigationLink/NavigationLink.test.tsx b/src/components/Navigation/NavigationLink/NavigationLink.test.tsx index 911ace66d..ebecde4d9 100644 --- a/src/components/Navigation/NavigationLink/NavigationLink.test.tsx +++ b/src/components/Navigation/NavigationLink/NavigationLink.test.tsx @@ -9,7 +9,7 @@ it("generates a standard anchor", () => { expect( screen.getByRole("link", { name: "Go here", - }) + }), ).toBeInTheDocument(); }); @@ -18,7 +18,7 @@ it("generates a button", () => { expect( screen.getByRole("button", { name: "Go here", - }) + }), ).toBeInTheDocument(); }); @@ -26,12 +26,12 @@ it("can select an anchor", () => { render( + />, ); expect( screen.getByRole("link", { name: "Go here", - }) + }), ).toHaveAttribute("aria-current", "page"); }); @@ -40,12 +40,12 @@ it("generates a custom link", () => { } link={{ label: "Go here", url: "/to/here" }} - /> + />, ); expect( screen.getByRole("button", { name: "Go here", - }) + }), ).toBeInTheDocument(); }); @@ -56,11 +56,11 @@ it("can select a custom link", () => { )} link={{ isSelected: true, label: "Go here", url: "/to/here" }} - /> + />, ); expect( screen.getByRole("button", { name: "Go here", - }) + }), ).toHaveAttribute("aria-current", "page"); }); diff --git a/src/components/Navigation/NavigationMenu/NavigationMenu.test.tsx b/src/components/Navigation/NavigationMenu/NavigationMenu.test.tsx index b3ebac744..3d607b907 100644 --- a/src/components/Navigation/NavigationMenu/NavigationMenu.test.tsx +++ b/src/components/Navigation/NavigationMenu/NavigationMenu.test.tsx @@ -12,7 +12,7 @@ it("can display when closed", () => { expect( screen.getByRole("button", { name: "Today's menu", - }) + }), ).toBeInTheDocument(); }); @@ -21,13 +21,13 @@ it("can open the menu", async () => { expect(screen.queryByRole("list")).not.toBeInTheDocument(); await userEvent.click(screen.getByRole("button", { name: "Today's menu" })); expect(screen.getByRole("listitem").className.includes("is-active")).toBe( - true + true, ); expect(screen.getByRole("list")).toHaveAttribute("aria-hidden", "false"); expect( screen.getByRole("button", { name: "Today's menu", - }) + }), ).toBeInTheDocument(); }); @@ -35,7 +35,9 @@ it("can align menu items to the right", async () => { render(); await userEvent.click(screen.getByRole("button", { name: "Today's menu" })); expect( - screen.getByRole("list").className.includes("p-navigation__dropdown--right") + screen + .getByRole("list") + .className.includes("p-navigation__dropdown--right"), ).toBe(true); }); @@ -44,14 +46,14 @@ it("can display links using a standard anchor", async () => { + />, ); // Open the menu so the links are displayed. await userEvent.click(screen.getByRole("button", { name: "Today's menu" })); expect( screen.getByRole("link", { name: "Eggs florentine", - }) + }), ).toBeInTheDocument(); }); @@ -61,14 +63,14 @@ it("can display links using a custom link", async () => { generateLink={({ label }) => } items={[{ label: "Eggs benedict", url: "/eggs/benedict" }]} label="Today's menu" - /> + />, ); // Open the menu so the links are displayed. await userEvent.click(screen.getByRole("button", { name: "Today's menu" })); expect( screen.getByRole("button", { name: "Eggs benedict", - }) + }), ).toBeInTheDocument(); }); @@ -83,13 +85,13 @@ it("can pass additional classes to the links", async () => { }, ]} label="Today's menu" - /> + />, ); // Open the menu so the links are displayed. await userEvent.click(screen.getByRole("button", { name: "Today's menu" })); expect( screen.getByRole("link", { name: "Smashed avo", - }) + }), ).toHaveClass("p-navigation__dropdown-item on-24-hour-rye"); }); diff --git a/src/components/Navigation/NavigationMenu/NavigationMenu.tsx b/src/components/Navigation/NavigationMenu/NavigationMenu.tsx index ff74a1b50..e6dee8ddf 100644 --- a/src/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/src/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -38,7 +38,7 @@ const NavigationMenu = ({ "p-navigation__item--dropdown-toggle", { "is-active": isOpen, - } + }, )} ref={menuRef} > @@ -67,7 +67,7 @@ const NavigationMenu = ({ ...item, className: classNames( "p-navigation__dropdown-item", - item.className + item.className, ), }} /> diff --git a/src/components/Notification/Notification.test.tsx b/src/components/Notification/Notification.test.tsx index 424c84450..2190e1f08 100644 --- a/src/components/Notification/Notification.test.tsx +++ b/src/components/Notification/Notification.test.tsx @@ -17,7 +17,7 @@ describe("Notification", () => { title="Permissions changed" > Anyone with access can view your invited users. - + , ); expect(screen.getByTestId("notification")).toMatchSnapshot(); }); @@ -52,11 +52,11 @@ describe("Notification", () => { const onDismiss = jest.fn(); const { rerender } = render(); expect( - screen.queryByRole("button", { name: Label.Close }) + screen.queryByRole("button", { name: Label.Close }), ).not.toBeInTheDocument(); rerender(); expect( - screen.getByRole("button", { name: Label.Close }) + screen.getByRole("button", { name: Label.Close }), ).toBeInTheDocument(); const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); await user.click(screen.getByRole("button", { name: Label.Close })); @@ -70,7 +70,7 @@ describe("Notification", () => { rerender(); expect(screen.getByText(timestamp)).toBeInTheDocument(); expect(screen.getByText(timestamp)).toHaveClass( - "p-notification__timestamp" + "p-notification__timestamp", ); }); @@ -80,7 +80,7 @@ describe("Notification", () => { expect(screen.queryByRole("button")).not.toBeInTheDocument(); rerender( - + , ); expect(screen.getByRole("button", { name: "Action" })).toBeInTheDocument(); const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); diff --git a/src/components/Notification/Notification.tsx b/src/components/Notification/Notification.tsx index 79c62fae4..46ea259c6 100644 --- a/src/components/Notification/Notification.tsx +++ b/src/components/Notification/Notification.tsx @@ -150,7 +150,7 @@ const Notification = ({ if (IS_DEV && (close || status || type)) { console.warn( - "The Notification component is using deprecated props. Refer to the deprecated list for details: https://canonical.github.io/react-components/?path=/docs/notification--information#deprecated" + "The Notification component is using deprecated props. Refer to the deprecated list for details: https://canonical.github.io/react-components/?path=/docs/notification--information#deprecated", ); } diff --git a/src/components/NotificationProvider/NotificationProvider.test.tsx b/src/components/NotificationProvider/NotificationProvider.test.tsx index 3a1297c59..81143bd8e 100644 --- a/src/components/NotificationProvider/NotificationProvider.test.tsx +++ b/src/components/NotificationProvider/NotificationProvider.test.tsx @@ -28,7 +28,7 @@ describe("NotificationProvider", () => { label: "Retry", onClick: handleRetry, }, - ] + ], ); return ( @@ -49,7 +49,7 @@ describe("NotificationProvider", () => { - + , ); const clickBtn = async (testId: string) => diff --git a/src/components/NotificationProvider/NotificationProvider.tsx b/src/components/NotificationProvider/NotificationProvider.tsx index ac193c00d..30b12408f 100644 --- a/src/components/NotificationProvider/NotificationProvider.tsx +++ b/src/components/NotificationProvider/NotificationProvider.tsx @@ -31,7 +31,7 @@ export const NotificationProvider: FC = ({ pathname, }) => { const [notification, setNotification] = useState( - null + null, ); const clear = () => notification !== null && setNotification(null); diff --git a/src/components/NotificationProvider/messageBuilder.tsx b/src/components/NotificationProvider/messageBuilder.tsx index f3fe3efe3..921b03de1 100644 --- a/src/components/NotificationProvider/messageBuilder.tsx +++ b/src/components/NotificationProvider/messageBuilder.tsx @@ -20,7 +20,7 @@ export const info = (message: ReactNode, title?: string): NotificationType => { export const success = ( message: ReactNode, - title?: string + title?: string, ): NotificationType => { return { message, @@ -33,7 +33,7 @@ export const failure = ( title: string, error: unknown, message?: ReactNode, - actions?: NotificationAction[] + actions?: NotificationAction[], ): NotificationType => { return { actions, diff --git a/src/components/NotificationProvider/types.ts b/src/components/NotificationProvider/types.ts index 9b3bee529..852247876 100644 --- a/src/components/NotificationProvider/types.ts +++ b/src/components/NotificationProvider/types.ts @@ -36,7 +36,7 @@ export interface NotificationHelper { title: string, error: unknown, message?: ReactNode, - actions?: NotificationAction[] + actions?: NotificationAction[], ) => NotificationType; info: (message: ReactNode, title?: string) => NotificationType; success: (message: ReactNode, title?: string) => NotificationType; diff --git a/src/components/Pagination/Pagination.test.tsx b/src/components/Pagination/Pagination.test.tsx index a0b172e42..22b2caca1 100644 --- a/src/components/Pagination/Pagination.test.tsx +++ b/src/components/Pagination/Pagination.test.tsx @@ -16,7 +16,7 @@ describe("", () => { totalItems={50} paginate={jest.fn()} currentPage={1} - /> + />, ); expect(screen.getByRole("navigation")).toMatchSnapshot(); @@ -30,7 +30,7 @@ describe("", () => { totalItems={5} paginate={jest.fn()} currentPage={1} - /> + />, ); expect(screen.queryByRole("navigation")).not.toBeInTheDocument(); @@ -43,17 +43,17 @@ describe("", () => { totalItems={50} paginate={jest.fn()} currentPage={1} - /> + />, ); expect( - screen.queryByRole("listitem", { name: "…" }) + screen.queryByRole("listitem", { name: "…" }), ).not.toBeInTheDocument(); expect( - screen.getByRole("button", { name: PaginationButtonLabel.Next }) + screen.getByRole("button", { name: PaginationButtonLabel.Next }), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: PaginationButtonLabel.Previous }) + screen.getByRole("button", { name: PaginationButtonLabel.Previous }), ).toBeInTheDocument(); expect(screen.getByRole("button", { name: "1" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "2" })).toBeInTheDocument(); @@ -69,15 +69,15 @@ describe("", () => { totalItems={1000} paginate={jest.fn()} currentPage={5} - /> + />, ); expect(screen.getAllByText("…")).toHaveLength(2); expect( - screen.getByRole("button", { name: PaginationButtonLabel.Next }) + screen.getByRole("button", { name: PaginationButtonLabel.Next }), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: PaginationButtonLabel.Previous }) + screen.getByRole("button", { name: PaginationButtonLabel.Previous }), ).toBeInTheDocument(); expect(screen.getByRole("button", { name: "1" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "4" })).toBeInTheDocument(); @@ -93,7 +93,7 @@ describe("", () => { totalItems={1000} paginate={jest.fn()} currentPage={2} - /> + />, ); // There should only be one ellipsis. @@ -107,7 +107,7 @@ describe("", () => { totalItems={1000} paginate={jest.fn()} currentPage={98} - /> + />, ); // There should only be one ellipsis. @@ -124,7 +124,7 @@ describe("", () => { paginate={jest.fn()} currentPage={98} /> - + , ); await userEvent.click(screen.getByRole("button", { name: "Next page" })); @@ -140,10 +140,10 @@ describe("", () => { paginate={jest.fn()} currentPage={98} centered - /> + />, ); expect(document.querySelector(".p-pagination__items")).toHaveClass( - "u-align--center" + "u-align--center", ); }); @@ -155,25 +155,25 @@ describe("", () => { paginate={jest.fn()} currentPage={1} showLabels - /> + />, ); const previousButton = screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Previous), }); expect(previousButton.querySelector("span")).toHaveTextContent( - PaginationButtonLabel.Previous + PaginationButtonLabel.Previous, ); const nextButton = screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Next), }); expect(nextButton.querySelector("span")).toHaveTextContent( - PaginationButtonLabel.Next + PaginationButtonLabel.Next, ); expect( previousButton && nextButton && previousButton.compareDocumentPosition(nextButton) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -187,25 +187,25 @@ describe("", () => { showLabels forwardLabel={CustomButtonLabel.Next} backLabel={CustomButtonLabel.Previous} - /> + />, ); const previousButton = screen.getByRole("button", { name: new RegExp(CustomButtonLabel.Previous), }); expect(previousButton.querySelector("span")).toHaveTextContent( - CustomButtonLabel.Previous + CustomButtonLabel.Previous, ); const nextButton = screen.getByRole("button", { name: new RegExp(CustomButtonLabel.Next), }); expect(nextButton.querySelector("span")).toHaveTextContent( - CustomButtonLabel.Next + CustomButtonLabel.Next, ); expect( previousButton && nextButton && previousButton.compareDocumentPosition(nextButton) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -218,17 +218,17 @@ describe("", () => { currentPage={1} forwardDisabled backDisabled - /> + />, ); expect( screen.getByRole("button", { name: PaginationButtonLabel.Next, - }) + }), ).toBeDisabled(); expect( screen.getByRole("button", { name: PaginationButtonLabel.Previous, - }) + }), ).toBeDisabled(); }); @@ -242,12 +242,12 @@ describe("", () => { paginate={mockHandlePaginate} currentPage={1} onForward={mockHandleForward} - /> + />, ); await userEvent.click( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Next), - }) + }), ); expect(mockHandlePaginate).toHaveBeenCalledTimes(1); expect(mockHandlePaginate).toHaveBeenCalledWith(2); @@ -265,12 +265,12 @@ describe("", () => { paginate={mockHandlePaginate} currentPage={2} onBack={mockHandleBack} - /> + />, ); await userEvent.click( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Previous), - }) + }), ); expect(mockHandlePaginate).toHaveBeenCalledTimes(1); expect(mockHandlePaginate).toHaveBeenCalledWith(1); @@ -286,18 +286,18 @@ describe("", () => { paginate={jest.fn()} currentPage={2} hideNumbers - /> + />, ); expect(screen.getAllByRole("button")).toHaveLength(2); expect( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Next), - }) + }), ).toBeVisible(); expect( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Previous), - }) + }), ).toBeVisible(); }); @@ -309,7 +309,7 @@ describe("", () => { it("should center the buttons-only pagination", () => { render(); expect(document.querySelector(".p-pagination__items")).toHaveClass( - "u-align--center" + "u-align--center", ); }); @@ -319,19 +319,19 @@ describe("", () => { name: new RegExp(PaginationButtonLabel.Previous), }); expect(previousButton.querySelector("span")).toHaveTextContent( - PaginationButtonLabel.Previous + PaginationButtonLabel.Previous, ); const nextButton = screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Next), }); expect(nextButton.querySelector("span")).toHaveTextContent( - PaginationButtonLabel.Next + PaginationButtonLabel.Next, ); expect( previousButton && nextButton && previousButton.compareDocumentPosition(nextButton) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -343,25 +343,25 @@ describe("", () => { showLabels forwardLabel={CustomButtonLabel.Next} backLabel={CustomButtonLabel.Previous} - /> + />, ); const previousButton = screen.getByRole("button", { name: new RegExp(CustomButtonLabel.Previous), }); expect(previousButton.querySelector("span")).toHaveTextContent( - CustomButtonLabel.Previous + CustomButtonLabel.Previous, ); const nextButton = screen.getByRole("button", { name: new RegExp(CustomButtonLabel.Next), }); expect(nextButton.querySelector("span")).toHaveTextContent( - CustomButtonLabel.Next + CustomButtonLabel.Next, ); expect( previousButton && nextButton && previousButton.compareDocumentPosition(nextButton) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -372,17 +372,17 @@ describe("", () => { onBack={jest.fn()} backDisabled forwardDisabled - /> + />, ); expect( screen.getByRole("button", { name: PaginationButtonLabel.Next, - }) + }), ).toBeDisabled(); expect( screen.getByRole("button", { name: PaginationButtonLabel.Previous, - }) + }), ).toBeDisabled(); }); @@ -392,7 +392,7 @@ describe("", () => { await userEvent.click( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Next), - }) + }), ); expect(mockHandleForward).toHaveBeenCalledTimes(1); }); @@ -403,7 +403,7 @@ describe("", () => { await userEvent.click( screen.getByRole("button", { name: new RegExp(PaginationButtonLabel.Previous), - }) + }), ); expect(mockHandleBack).toHaveBeenCalledTimes(1); }); @@ -416,7 +416,7 @@ describe("", () => { paginate={jest.fn()} currentPage={1} truncateThreshold={3} - /> + />, ); expect(await screen.findAllByRole("button", { name: "1" })).toHaveLength(1); @@ -434,7 +434,7 @@ describe("", () => { paginate={jest.fn()} currentPage={2} truncateThreshold={3} - /> + />, ); expect(await screen.findAllByRole("button", { name: "1" })).toHaveLength(1); @@ -452,7 +452,7 @@ describe("", () => { paginate={jest.fn()} currentPage={3} truncateThreshold={3} - /> + />, ); expect(await screen.findAllByRole("button", { name: "1" })).toHaveLength(1); @@ -470,7 +470,7 @@ describe("", () => { paginate={jest.fn()} currentPage={4} truncateThreshold={3} - /> + />, ); expect(await screen.findAllByRole("button", { name: "1" })).toHaveLength(1); @@ -488,7 +488,7 @@ describe("", () => { paginate={jest.fn()} currentPage={4} truncateThreshold={3} - /> + />, ); expect(await screen.findAllByRole("button", { name: "1" })).toHaveLength(1); @@ -496,7 +496,7 @@ describe("", () => { expect(await screen.findAllByRole("button", { name: "4" })).toHaveLength(1); expect(await screen.findAllByRole("button", { name: "5" })).toHaveLength(1); expect(await screen.findAllByRole("button", { name: "10" })).toHaveLength( - 1 + 1, ); expect(screen.queryAllByText("…")).toHaveLength(2); }); diff --git a/src/components/Pagination/Pagination.tsx b/src/components/Pagination/Pagination.tsx index f5777c4e2..e90d5e365 100644 --- a/src/components/Pagination/Pagination.tsx +++ b/src/components/Pagination/Pagination.tsx @@ -14,7 +14,7 @@ const generatePaginationItems = ( pageNumbers: number[], currentPage: number, truncateThreshold: number, - changePage: (page: number) => void + changePage: (page: number) => void, ) => { const lastPage = pageNumbers.length; const truncated = lastPage > truncateThreshold; @@ -53,7 +53,7 @@ const generatePaginationItems = ( number={1} isActive={currentPage === 1} onClick={() => changePage(1)} - /> + />, ); if (!visiblePages.includes(2)) { items.push(); @@ -68,7 +68,7 @@ const generatePaginationItems = ( isActive={number === currentPage} onClick={() => changePage(number)} /> - )) + )), ); if (truncated) { @@ -82,7 +82,7 @@ const generatePaginationItems = ( number={lastPage} isActive={currentPage === lastPage} onClick={() => changePage(lastPage)} - /> + />, ); } return items; @@ -286,7 +286,7 @@ const Pagination = ({ pageNumbers, currentPage, truncateThreshold, - changeNumberedPage + changeNumberedPage, ) : null} { it("should contain default label before the forward icon", () => { render( - {}} showLabel /> + {}} showLabel />, ); const defaultLabel = screen .getByRole("button", { name: new RegExp(Label.Next) }) @@ -29,7 +29,7 @@ describe("PaginationButton", () => { defaultLabel && icon && defaultLabel.compareDocumentPosition(icon) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -44,7 +44,7 @@ describe("PaginationButton", () => { defaultLabel && icon && defaultLabel.compareDocumentPosition(icon) & - Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_PRECEDING, ).toBeTruthy(); }); @@ -55,7 +55,7 @@ describe("PaginationButton", () => { onClick={() => {}} showLabel label={CustomLabel.Next} - /> + />, ); const customLabel = screen .getByRole("button", { name: new RegExp(CustomLabel.Next) }) @@ -66,7 +66,7 @@ describe("PaginationButton", () => { customLabel && icon && customLabel.compareDocumentPosition(icon) & - Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -77,7 +77,7 @@ describe("PaginationButton", () => { onClick={() => {}} showLabel label={CustomLabel.Previous} - /> + />, ); const customLabel = screen .getByRole("button", { name: new RegExp(CustomLabel.Previous) }) @@ -88,7 +88,7 @@ describe("PaginationButton", () => { customLabel && icon && customLabel.compareDocumentPosition(icon) & - Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_PRECEDING, ).toBeTruthy(); }); @@ -113,7 +113,7 @@ describe("PaginationButton", () => { direction="forward" onClick={mockHandleClick} disabled - /> + />, ); const disabledButton = screen.getByRole("button", { name: Label.Next }); expect(disabledButton).toBeDisabled(); @@ -124,7 +124,7 @@ describe("PaginationButton", () => { it("should be diabled and onClick will not be called when clicking the back button", async () => { const mockHandleClick = jest.fn(); render( - + , ); const disabledButton = screen.getByRole("button", { name: Label.Previous }); expect(disabledButton).toBeDisabled(); diff --git a/src/components/Pagination/PaginationItem/PaginationItem.test.tsx b/src/components/Pagination/PaginationItem/PaginationItem.test.tsx index d878fc718..d8ece8b31 100644 --- a/src/components/Pagination/PaginationItem/PaginationItem.test.tsx +++ b/src/components/Pagination/PaginationItem/PaginationItem.test.tsx @@ -7,7 +7,7 @@ describe("", () => { // snapshot tests it("renders and matches the snapshot", () => { const { container } = render( - + , ); expect(container).toMatchSnapshot(); diff --git a/src/components/Panel/Panel.test.tsx b/src/components/Panel/Panel.test.tsx index c7cbd5312..feff651e0 100644 --- a/src/components/Panel/Panel.test.tsx +++ b/src/components/Panel/Panel.test.tsx @@ -21,17 +21,17 @@ it("displays a logo", () => { name: "name.svg", nameAlt: "Name SVG", }} - /> + />, ); const link = screen.getByRole("link", { name: "Icon SVG Name SVG" }); expect(link).toHaveAttribute("href", "http://example.com"); expect(within(link).getByRole("img", { name: "Icon SVG" })).toHaveAttribute( "src", - "icon.svg" + "icon.svg", ); expect(within(link).getByRole("img", { name: "Name SVG" })).toHaveAttribute( "src", - "name.svg" + "name.svg", ); }); @@ -49,10 +49,10 @@ it("logo handles different components", () => { name: "name.svg", nameAlt: "Name SVG", }} - /> + />, ); expect( - screen.getByRole("button", { name: "Icon SVG Name SVG" }) + screen.getByRole("button", { name: "Icon SVG Name SVG" }), ).toHaveAttribute("title", "http://example.com"); }); diff --git a/src/components/PasswordToggle/PasswordToggle.test.tsx b/src/components/PasswordToggle/PasswordToggle.test.tsx index 0df83024e..505784e1a 100644 --- a/src/components/PasswordToggle/PasswordToggle.test.tsx +++ b/src/components/PasswordToggle/PasswordToggle.test.tsx @@ -7,10 +7,10 @@ import userEvent from "@testing-library/user-event"; describe("PasswordToggle", () => { it("can add additional classes", () => { render( - + , ); expect(screen.getByLabelText("password")).toHaveClass( - "p-form-validation__input" + "p-form-validation__input", ); expect(screen.getByLabelText("password")).toHaveClass("extra-class"); }); @@ -26,7 +26,7 @@ describe("PasswordToggle", () => { render(); expect(screen.getByLabelText("password")).toHaveAttribute( "type", - "password" + "password", ); await userEvent.click(screen.getByRole("button", { name: Label.Show })); expect(screen.getByLabelText("password")).toHaveAttribute("type", "text"); @@ -39,18 +39,18 @@ describe("PasswordToggle", () => { id="test-id" value="My test value" onChange={() => null} - /> + />, ); expect(screen.getByLabelText("password")).toHaveAttribute( "value", - "My test value" + "My test value", ); }); it("can display an error", async () => { render(); expect(screen.getByLabelText("password")).toHaveAccessibleErrorMessage( - "Uh oh!" + "Uh oh!", ); }); diff --git a/src/components/PasswordToggle/PasswordToggle.tsx b/src/components/PasswordToggle/PasswordToggle.tsx index 0af1b3a8f..5cc5a0e62 100644 --- a/src/components/PasswordToggle/PasswordToggle.tsx +++ b/src/components/PasswordToggle/PasswordToggle.tsx @@ -87,7 +87,7 @@ const PasswordToggle = React.forwardRef( wrapperClassName, ...inputProps }, - ref + ref, ): JSX.Element => { const [isPassword, setIsPassword] = useState(true); const validationId = useId(); @@ -152,7 +152,7 @@ const PasswordToggle = React.forwardRef( /> ); - } + }, ); export default PasswordToggle; diff --git a/src/components/Row/Row.test.tsx b/src/components/Row/Row.test.tsx index ed8021b67..1a351651a 100644 --- a/src/components/Row/Row.test.tsx +++ b/src/components/Row/Row.test.tsx @@ -13,7 +13,7 @@ describe("Row ", () => { render( Test content - + , ); const row = screen.getByTestId("row"); expect(row).toHaveClass("row"); diff --git a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx index ec64b0f97..a18843d2a 100644 --- a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx +++ b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx @@ -18,7 +18,7 @@ describe("Filter panel section", () => { searchTerm="" toggleSelected={jest.fn()} data={sampleData} - /> + />, ); // eslint-disable-next-line testing-library/no-node-access expect(document.querySelector(".p-filter-panel-section")).toMatchSnapshot(); @@ -31,23 +31,23 @@ describe("Filter panel section", () => { searchTerm="" toggleSelected={jest.fn()} data={sampleData} - /> + />, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-filter-panel-section") + document.querySelector(".p-filter-panel-section"), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: "us-east1" }) + screen.getByRole("button", { name: "us-east1" }), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: "us-east2" }) + screen.getByRole("button", { name: "us-east2" }), ).toBeInTheDocument(); expect( - screen.getByRole("button", { name: "us-east3" }) + screen.getByRole("button", { name: "us-east3" }), ).toBeInTheDocument(); expect( - screen.getByRole("heading", { name: "Regions" }) + screen.getByRole("heading", { name: "Regions" }), ).toBeInTheDocument(); }); @@ -68,11 +68,11 @@ describe("Filter panel section", () => { searchTerm="" toggleSelected={jest.fn()} data={sampleData} - /> + />, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-search-and-filter__selected-count") + document.querySelector(".p-search-and-filter__selected-count"), ).not.toBeInTheDocument(); }); @@ -93,13 +93,13 @@ describe("Filter panel section", () => { searchTerm="" toggleSelected={jest.fn()} data={sampleData} - /> + />, ); expect( // Use a query selector because the element's text is split up over // multiple elements so it can't be selected by its content. // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-filter-panel-section__counter")?.textContent + document.querySelector(".p-filter-panel-section__counter")?.textContent, ).toBe("+3"); }); @@ -111,21 +111,21 @@ describe("Filter panel section", () => { toggleSelected={jest.fn()} data={sampleData} sectionHidden={false} - /> + />, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-filter-panel-section__chips") + document.querySelector(".p-filter-panel-section__chips"), ).toHaveAttribute("aria-expanded", "false"); await userEvent.click( // Use a query selector because the element's text is split up over // multiple elements so it can't be selected by its content. // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-filter-panel-section__counter") as HTMLElement + document.querySelector(".p-filter-panel-section__counter") as HTMLElement, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-filter-panel-section__chips") + document.querySelector(".p-filter-panel-section__chips"), ).toHaveAttribute("aria-expanded", "true"); }); }); diff --git a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx index e0c371809..b6d6b0d7d 100644 --- a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx +++ b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx @@ -63,7 +63,7 @@ const FilterPanelSection = ({ // Search chips for character match with search term const searchTermInChips = highlightSubString( chipValues.toString(), - searchTerm + searchTerm, ).match; const panelSectionVisible = @@ -114,7 +114,7 @@ const FilterPanelSection = ({ // should display const searchTermInChip = highlightSubString( chip.value, - searchTerm + searchTerm, ).match; const chipVisible = searchTermInChip || diff --git a/src/components/SearchAndFilter/SearchAndFilter.test.tsx b/src/components/SearchAndFilter/SearchAndFilter.test.tsx index ef46bbdb5..595c4c5a0 100644 --- a/src/components/SearchAndFilter/SearchAndFilter.test.tsx +++ b/src/components/SearchAndFilter/SearchAndFilter.test.tsx @@ -41,7 +41,7 @@ describe("Search and filter", () => { data-testid="searchandfilter" filterPanelData={[]} returnSearchData={returnSearchData} - /> + />, ); expect(screen.getByTestId("searchandfilter")).toMatchSnapshot(); }); @@ -52,10 +52,10 @@ describe("Search and filter", () => { + />, ); expect( - screen.queryByRole("button", { name: Label.Clear }) + screen.queryByRole("button", { name: Label.Clear }), ).not.toBeInTheDocument(); }); @@ -66,7 +66,7 @@ describe("Search and filter", () => { data-testid="searchandfilter" filterPanelData={sampleData} returnSearchData={returnSearchData} - /> + />, ); expect(getPanel()).toHaveAttribute("aria-hidden", "true"); await waitFor(async () => { @@ -81,12 +81,12 @@ describe("Search and filter", () => { + />, ); expect(getPanel()).toHaveAttribute("aria-hidden", "true"); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); expect(getPanel()).toHaveAttribute("aria-hidden", "false"); @@ -108,11 +108,11 @@ describe("Search and filter", () => { + />, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-search-and-filter__selected-count") + document.querySelector(".p-search-and-filter__selected-count"), ).not.toBeInTheDocument(); }); @@ -132,15 +132,15 @@ describe("Search and filter", () => { + />, ); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-search-and-filter__selected-count") + document.querySelector(".p-search-and-filter__selected-count"), ).not.toBeInTheDocument(); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { @@ -165,12 +165,12 @@ describe("Search and filter", () => { + />, ); expect(getSearchContainer()).toHaveAttribute("aria-expanded", "false"); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { @@ -188,30 +188,30 @@ describe("Search and filter", () => { + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); expect( // eslint-disable-next-line testing-library/no-node-access - document.querySelector(".p-search-and-filter__search-prompt") + document.querySelector(".p-search-and-filter__search-prompt"), ).not.toBeInTheDocument(); await waitFor(async () => { await userEvent.clear( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.type( screen.getByRole("searchbox", { name: Label.SearchAndFilter }), - "My new value" + "My new value", ); }); expect( - screen.getByRole("button", { name: "Search for My new value ..." }) + screen.getByRole("button", { name: "Search for My new value ..." }), ).toBeInTheDocument(); }); @@ -221,31 +221,31 @@ describe("Search and filter", () => { + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); // eslint-disable-next-line testing-library/no-node-access expect(document.querySelectorAll(".p-filter-panel-section").length).toEqual( - 3 + 3, ); await waitFor(async () => { await userEvent.clear( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.type( screen.getByRole("searchbox", { name: Label.SearchAndFilter }), - "Unknown value" + "Unknown value", ); }); // eslint-disable-next-line testing-library/no-node-access expect(document.querySelectorAll(".p-filter-panel-section").length).toEqual( - 0 + 0, ); }); @@ -255,42 +255,42 @@ describe("Search and filter", () => { + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.clear( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.type( screen.getByRole("searchbox", { name: Label.SearchAndFilter }), - "Google" + "Google", ); }); // eslint-disable-next-line testing-library/no-node-access expect(document.querySelectorAll(".p-filter-panel-section").length).toEqual( - 1 + 1, ); await waitFor(async () => { await userEvent.clear( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.type( screen.getByRole("searchbox", { name: Label.SearchAndFilter }), - "re" + "re", ); }); // eslint-disable-next-line testing-library/no-node-access expect(document.querySelectorAll(".p-filter-panel-section").length).toEqual( - 2 + 2, ); }); @@ -300,22 +300,22 @@ describe("Search and filter", () => { + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.clear( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { await userEvent.type( screen.getByRole("searchbox", { name: Label.SearchAndFilter }), - "Google" + "Google", ); }); const boldText = document @@ -333,15 +333,15 @@ describe("Search and filter", () => { filterPanelData={sampleData} returnSearchData={returnSearchData} existingSearchData={[{ lead: "Cloud", value: "Google" }]} - /> + />, ); // eslint-disable-next-line testing-library/no-node-access const lead = document.querySelector( - ".p-search-and-filter__search-container .p-chip__lead" + ".p-search-and-filter__search-container .p-chip__lead", )?.textContent; // eslint-disable-next-line testing-library/no-node-access const value = document.querySelector( - ".p-search-and-filter__search-container .p-chip__value" + ".p-search-and-filter__search-container .p-chip__value", )?.textContent; expect(lead).toBe("CLOUD"); expect(value).toBe("Google"); @@ -357,23 +357,23 @@ describe("Search and filter", () => { { lead: "Cloud", value: "Google" }, { lead: "Region", value: "eu-west-1" }, ]} - /> + />, ); // eslint-disable-next-line testing-library/no-node-access const chips = document.querySelectorAll( - ".p-search-and-filter__search-container .p-chip" + ".p-search-and-filter__search-container .p-chip", ); expect(chips.length).toBe(2); // eslint-disable-next-line testing-library/no-node-access const chip1Value = document.querySelector( - ".p-search-and-filter__search-container .p-chip:nth-child(1) .p-chip__value" + ".p-search-and-filter__search-container .p-chip:nth-child(1) .p-chip__value", )?.textContent; expect(chip1Value).toEqual("Google"); // eslint-disable-next-line testing-library/no-node-access const chip2Value = document.querySelector( - ".p-search-and-filter__search-container .p-chip:nth-child(2) .p-chip__value" + ".p-search-and-filter__search-container .p-chip:nth-child(2) .p-chip__value", )?.textContent; expect(chip2Value).toEqual("eu-west-1"); }); @@ -386,11 +386,11 @@ describe("Search and filter", () => { filterPanelData={sampleData} returnSearchData={returnSearchData} onPanelToggle={onPanelToggle} - /> + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); expect(onPanelToggle).toHaveBeenCalled(); @@ -414,11 +414,11 @@ describe("Search and filter", () => { filterPanelData={sampleData} returnSearchData={returnSearchData} onExpandChange={onExpandChange} - /> + />, ); await waitFor(async () => { await userEvent.click( - screen.getByRole("searchbox", { name: Label.SearchAndFilter }) + screen.getByRole("searchbox", { name: Label.SearchAndFilter }), ); }); await waitFor(async () => { diff --git a/src/components/SearchAndFilter/SearchAndFilter.tsx b/src/components/SearchAndFilter/SearchAndFilter.tsx index 685d75141..98ec155fd 100644 --- a/src/components/SearchAndFilter/SearchAndFilter.tsx +++ b/src/components/SearchAndFilter/SearchAndFilter.tsx @@ -128,7 +128,7 @@ const SearchAndFilter = ({ const updatedCurrentSelected = currentSelected.filter( (currentSelectedChip) => { return currentSelectedChip.value !== chip.value; - } + }, ); setSearchData(updatedCurrentSelected); } @@ -138,7 +138,7 @@ const SearchAndFilter = ({ const removeFromSelected = (chip: SearchAndFilterChip) => { if (searchData.includes(chip)) { const updatedSelected = searchData.filter( - (searchDataChip) => searchDataChip !== chip + (searchDataChip) => searchDataChip !== chip, ); setSearchData(updatedSelected); } @@ -203,7 +203,7 @@ const SearchAndFilter = ({ searchAndFilterRef.current, (fitsWindow) => setMaxHeight(fitsWindow.fromBottom.spaceBelow - 16), 0, - !filterPanelHidden + !filterPanelHidden, ); // Add search prompt value to search on Enter key diff --git a/src/components/SearchAndFilter/utils.tsx b/src/components/SearchAndFilter/utils.tsx index 2c036aaee..70117ac6f 100644 --- a/src/components/SearchAndFilter/utils.tsx +++ b/src/components/SearchAndFilter/utils.tsx @@ -23,5 +23,5 @@ export const overflowingChipsCount = (chips, overflowRowLimit) => { export const isChipInArray = (chip, existingArr) => existingArr?.some( (searchDataItem) => - searchDataItem.lead === chip.lead && searchDataItem.value === chip.value + searchDataItem.lead === chip.lead && searchDataItem.value === chip.value, ); diff --git a/src/components/SearchBox/SearchBox.test.tsx b/src/components/SearchBox/SearchBox.test.tsx index da398b822..7af21f22a 100644 --- a/src/components/SearchBox/SearchBox.test.tsx +++ b/src/components/SearchBox/SearchBox.test.tsx @@ -14,17 +14,17 @@ describe("SearchBox ", () => { it("shows the clear button when there is a value", () => { render(); expect( - screen.getByRole("button", { name: Label.Clear }) + screen.getByRole("button", { name: Label.Clear }), ).toBeInTheDocument(); }); it("can externally control the value", () => { const { rerender } = render( - + , ); expect(screen.getByRole("searchbox")).toHaveAttribute("value", "admin"); rerender( - + , ); expect(screen.getByRole("searchbox")).toHaveAttribute("value", "new-admin"); }); @@ -55,7 +55,7 @@ describe("SearchBox ", () => { render(); expect(screen.getByRole("searchbox")).toHaveAttribute( "data-testid", - "testID" + "testID", ); }); @@ -68,7 +68,7 @@ describe("SearchBox ", () => { it("after pressing the clear button focus remains on the button", async () => { render( - + , ); const searchInput = screen.getByRole("searchbox"); const clearButton = screen.getByRole("button", { @@ -86,7 +86,7 @@ describe("SearchBox ", () => { shouldRefocusAfterReset onChange={jest.fn()} value="admin" - /> + />, ); const searchInput = screen.getByRole("searchbox"); const clearButton = screen.getByRole("button", { @@ -105,7 +105,7 @@ describe("SearchBox ", () => { onChange={jest.fn()} onClear={handleOnClear} value="admin" - /> + />, ); await userEvent.click(screen.getByRole("button", { name: Label.Clear })); expect(handleOnClear).toBeCalled(); diff --git a/src/components/SearchBox/SearchBox.tsx b/src/components/SearchBox/SearchBox.tsx index 36f89d800..0ac5688f7 100644 --- a/src/components/SearchBox/SearchBox.tsx +++ b/src/components/SearchBox/SearchBox.tsx @@ -85,7 +85,7 @@ const SearchBox = React.forwardRef( value, ...props }: Props, - forwardedRef + forwardedRef, ): JSX.Element => { const internalRef = useRef(); const resetInput = () => { @@ -157,7 +157,7 @@ const SearchBox = React.forwardRef( ); - } + }, ); SearchBox.displayName = "SearchBox"; diff --git a/src/components/Select/Select.test.tsx b/src/components/Select/Select.test.tsx index 0d11cee02..f6f67fa1d 100644 --- a/src/components/Select/Select.test.tsx +++ b/src/components/Select/Select.test.tsx @@ -15,7 +15,7 @@ describe("Select", () => { { value: "3", label: "Xenial Xerus" }, ]} wrapperClassName="select" - /> + />, ); expect(screen.getByRole("combobox")).toMatchSnapshot(); }); @@ -30,7 +30,7 @@ describe("Select", () => { render(