diff --git a/components/loading-spinner.tsx b/components/loading-spinner.tsx index 26ce375d..6bc5bc55 100644 --- a/components/loading-spinner.tsx +++ b/components/loading-spinner.tsx @@ -21,7 +21,11 @@ function LoadingSpinner({ styles, }: LoadingSpinnerProps) { return ( - + { if (!isValidElement(child)) return null; - if (child.type === TableRowGroup) { + const hasRowGroup = child.type === TableRowGroup; + const hasRow = child.type === TableRow; + + if (hasRowGroup) { return cloneElement(child, { selectable, selectedData, @@ -244,7 +247,7 @@ function Table({ }); } - if (child.type === TableRow) { + if (hasRow) { const props = child.props as TableRowProps; const isSelected = selectedData.some( @@ -578,24 +581,41 @@ function Table({ })()} )} + - {isLoading && ( - + - - - )} - + label="Loading" + gap={10} + iconSize={24} + /> + + )} @@ -702,9 +722,9 @@ const PaginationSelectedItem = styled.span<{ $style?: CSSProp }>` `; const TableContainer = styled.div<{ $hasSelected: boolean }>` + position: relative; display: flex; flex-direction: column; - position: relative; height: 100%; overflow: hidden; diff --git a/test/component/table.cy.tsx b/test/component/table.cy.tsx index 8f633008..ff591f01 100644 --- a/test/component/table.cy.tsx +++ b/test/component/table.cy.tsx @@ -61,29 +61,92 @@ describe("Table", () => { type: TYPES_DATA[i % TYPES_DATA.length], })); - function BasicTable(props: Omit) { + function BasicTable( + props: Omit & { hasRowGroup?: boolean } + ) { const [selectedItems, setSelectedItems] = useState([]); + const pageNumberText = props?.labels?.pageNumberText ?? "12"; + + const groupedRows = props.hasRowGroup + ? TYPES_DATA.map((type) => ({ + type, + rows: rawRows.filter((r) => r.type === type), + })) + : null; + return ( - {rawRows?.map((row, index) => ( - - {[row.name, row.type].map((rowCell, i) => ( - - {rowCell} - + {props.hasRowGroup + ? groupedRows?.map((group, gi) => ( + + {group.rows.map((row, ri) => ( + + {[row.name, row.type].map((cell, ci) => ( + + {cell} + + ))} + + ))} + + )) + : rawRows?.map((row, index) => ( + + {[row.name, row.type].map((rowCell, i) => ( + + {rowCell} + + ))} + ))} - - ))}
); } + context("isLoading", () => { + context("when given true", () => { + it("renders spinner positioned ~10px from the top and ~10px from the left", () => { + cy.mount(); + + cy.findByLabelText("overlay-blocker").then(($overlay) => { + const overlayRect = $overlay[0].getBoundingClientRect(); + + cy.findByLabelText("circle").then(($spinner) => { + const spinnerRect = $spinner[0].getBoundingClientRect(); + + const paddingTop = spinnerRect.top - overlayRect.top; + const paddingLeft = spinnerRect.left - overlayRect.left; + + expect(paddingTop).to.be.closeTo(10, 2); + expect(paddingLeft).to.be.closeTo(10, 2); + }); + }); + }); + + it("renders spinner with padding 4px and with caption loading", () => { + cy.mount(); + + cy.findByText("Loading").should("exist"); + + cy.findByLabelText("loading-spinner") + .should("have.css", "background-color", "rgb(0, 0, 0)") + .and("have.css", "opacity", "0.8") + .and("have.css", "padding", "4px 8px 4px 4px"); + }); + }); + }); context("selected", () => { context("when selected", () => { @@ -1166,7 +1229,7 @@ describe("Table", () => { ); cy.findByLabelText("pagination-wrapper") - .should("have.css", "width", "432px") + .should("have.css", "width", "447px") .and("have.css", "justify-content", "end"); }); });