Skip to content

Commit 8ca1758

Browse files
chore: DOC-1534 update deprecated packs documentation and enhance PacksTable component (#5163) (#5168)
- Set 'hide_table_of_contents' to true in deprecated packs documentation. - Added responsive styles for table container and wrapper in PacksTable. - Improved search functionality and added unique row keys in PacksTable. - Updated tests to ensure proper rendering and functionality of the PacksTable component. (cherry picked from commit de1812f) Co-authored-by: Karl Cardenas <[email protected]>
1 parent 8feae54 commit 8ca1758

File tree

7 files changed

+163
-78
lines changed

7 files changed

+163
-78
lines changed

docs/docs-content/integrations/deprecated-packs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sidebar_label: "Deprecated Packs"
33
title: "Deprecated Packs"
44
description: "Deprecated Packs"
55
icon: ""
6-
hide_table_of_contents: false
6+
hide_table_of_contents: true
77
sidebar_position: 40
88
tags: ["packs", "deprecation"]
99
---

src/components/PacksTable/PackTable.test.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,36 @@ import { render, waitFor, screen, fireEvent } from "@testing-library/react";
33
import fetchMock from "jest-fetch-mock";
44
import FilteredTable from "./PacksTable";
55
import { toTitleCase } from "./PacksTable";
6+
7+
// Mock the Docusaurus dependencies
8+
jest.mock("@docusaurus/theme-common", () => ({
9+
useColorMode: () => ({
10+
colorMode: "light",
11+
setColorMode: jest.fn(),
12+
}),
13+
}));
14+
15+
jest.mock("@theme/Admonition");
16+
617
// Enable fetch mocking
718
fetchMock.enableMocks();
819

20+
beforeAll(() => {
21+
Object.defineProperty(window, "matchMedia", {
22+
writable: true,
23+
value: jest.fn().mockImplementation((query) => ({
24+
matches: false,
25+
media: query,
26+
onchange: null,
27+
addListener: jest.fn(), // deprecated
28+
removeListener: jest.fn(), // deprecated
29+
addEventListener: jest.fn(),
30+
removeEventListener: jest.fn(),
31+
dispatchEvent: jest.fn(),
32+
})),
33+
});
34+
});
35+
936
describe("FilteredTable Tests", () => {
1037
const mockPacks = [
1138
{
@@ -23,6 +50,7 @@ describe("FilteredTable Tests", () => {
2350
releaseType: "Experimental",
2451
contributor: "",
2552
docsURL: "",
53+
hash: "mock-hash-1",
2654
},
2755
{
2856
name: "amazon-linux-eks",
@@ -39,6 +67,7 @@ describe("FilteredTable Tests", () => {
3967
releaseType: "Stable",
4068
contributor: "",
4169
docsURL: "",
70+
hash: "mock-hash-2",
4271
},
4372
];
4473

@@ -49,14 +78,14 @@ describe("FilteredTable Tests", () => {
4978

5079
it("should show loader initially", () => {
5180
const { container } = render(<FilteredTable />);
52-
expect(container.querySelector(".loader")).toBeInTheDocument();
81+
expect(container.querySelector(".ant-spin")).toBeInTheDocument();
5382
});
5483

5584
it("should hide loader and display packs after API call", async () => {
5685
fetchMock.mockResponseOnce(JSON.stringify({ dateCreated: "2022-08-25", Packs: mockPacks }));
5786
const { container } = render(<FilteredTable />);
5887

59-
await waitFor(() => expect(container.querySelector(".loader")).not.toBeInTheDocument());
88+
await waitFor(() => expect(container.querySelector(".ant-spin")).not.toBeInTheDocument());
6089
expect(screen.getByText("Alpine")).toBeInTheDocument();
6190
expect(screen.getByText("Amazon EKS optimized Linux")).toBeInTheDocument();
6291
});
@@ -102,6 +131,18 @@ describe("FilteredTable Tests", () => {
102131

103132
expect(screen.getByText("EKS, vSphere")).toBeInTheDocument();
104133
});
134+
135+
it("should have unique row keys", async () => {
136+
fetchMock.mockResponseOnce(JSON.stringify({ dateCreated: "2022-08-25", Packs: mockPacks }));
137+
const { container } = render(<FilteredTable />);
138+
139+
await waitFor(() => {
140+
const rows = container.querySelectorAll(".ant-table-row");
141+
const keys = Array.from(rows).map((row) => row.getAttribute("data-row-key"));
142+
const uniqueKeys = new Set(keys);
143+
expect(keys.length).toBe(uniqueKeys.size);
144+
});
145+
});
105146
});
106147

107148
describe("toTitleCase", () => {

src/components/PacksTable/PacksTable.module.scss

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@
4646
}
4747
}
4848

49+
.tableContainer {
50+
margin: 16px 0;
51+
overflow: auto;
52+
53+
@media screen and (max-width: 768px) {
54+
display: none;
55+
}
56+
57+
:global {
58+
.ant-input-search {
59+
margin-bottom: 16px;
60+
}
61+
}
62+
}
63+
64+
.tableWrapper {
65+
border: 1px solid var(--ifm-toc-border-color);
66+
border-radius: 4px;
67+
padding: 16px;
68+
69+
@media screen and (max-width: 768px) {
70+
padding: 8px;
71+
}
72+
}
73+
4974
.green {
5075
background-color: var(--ifm-color-success-contrast-background);
5176
color: var(--ifm-color-success-contrast-foreground);
@@ -60,38 +85,46 @@
6085
border-radius: 16px;
6186
}
6287

63-
.tableWrapper {
64-
border: 1px solid var(--ifm-toc-border-color);
65-
padding: 16px;
88+
.disabled,
89+
.deleted,
90+
.deprecated {
6691
padding: 4px 8px;
67-
border-radius: 4px;
92+
border-radius: 16px;
93+
display: inline-block;
6894
}
6995

7096
.disabled {
7197
background-color: var(--ifm-color-warning-contrast-background);
7298
color: var(--ifm-color-warning-contrast-foreground);
73-
padding: 4px 8px;
74-
border-radius: 16px;
7599
}
76100

77101
.deleted {
78102
background-color: var(--ifm-color-danger-contrast-background);
79103
color: var(--ifm-color-danger-contrast-foreground);
80-
padding: 4px 8px;
81-
border-radius: 16px;
82104
}
83105

84106
.deprecated {
85107
background-color: var(--ifm-color-info-contrast-background);
86108
color: var(--ifm-color-info-contrast-foreground);
87-
padding: 4px 8px;
88-
border-radius: 16px;
89109
}
90110

91111
.error {
92112
display: flex;
93113
justify-content: center;
94114
align-items: center;
95115
min-height: 400px;
96-
color: red;
116+
color: var(--ifm-color-danger);
117+
}
118+
119+
.unsupportedMessage {
120+
display: none;
121+
margin: 16px 0;
122+
123+
@media screen and (max-width: 768px) {
124+
display: block;
125+
}
126+
}
127+
128+
.searchContainer {
129+
margin-bottom: 16px;
97130
}

0 commit comments

Comments
 (0)