Skip to content

Commit 537e0e8

Browse files
Change orderBy status in clusterList (#142)
1 parent f9d0570 commit 537e0e8

4 files changed

Lines changed: 94 additions & 2 deletions

File tree

apps/cluster-orch/src/components/organism/ClusterList/ClusterList.cy.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,48 @@ describe("<ClusterList/>", () => {
5555
});
5656
});
5757
});
58+
59+
describe("<ClusterList/> - Sorting by Status", () => {
60+
beforeEach(() => {
61+
pom.interceptApis([pom.api.clusterMocked]);
62+
cy.mount(
63+
<ClusterList
64+
onSelect={cy.stub().as("onSelectStub")}
65+
onShowDetails={cy.stub().as("onShowDetailsStub")}
66+
isForm={true}
67+
/>,
68+
);
69+
pom.waitForApis();
70+
});
71+
72+
it("should sort by lifecyclePhase when clicking on the Status column header", () => {
73+
cy.get("th:contains('Status') .caret.caret-up").click({ force: true });
74+
cy.wait(`@${pom.api.clusterMocked}`).then(({ request }) => {
75+
expect(request.url).to.include("orderBy=lifecyclePhase");
76+
expect(request.url).to.include("asc");
77+
});
78+
79+
cy.get("th:contains('Status') .caret.caret-down").click({ force: true });
80+
cy.wait(`@${pom.api.clusterMocked}`).then(({ request }) => {
81+
expect(request.url).to.include("orderBy=lifecyclePhase");
82+
expect(request.url).to.include("desc");
83+
});
84+
});
85+
86+
it("should NOT sort by a wrong field when clicking Status column", () => {
87+
cy.get("th:contains('Status') .caret.caret-up").click({ force: true });
88+
cy.get(`@${pom.api.clusterMocked}`)
89+
.its("request.url")
90+
.then((url: string) => {
91+
expect(url).not.to.include("orderBy=status");
92+
expect(url).not.to.include("orderBy=name");
93+
});
94+
});
95+
96+
it("should not trigger sort if Status column is missing", () => {
97+
cy.get("th:contains('Status')").invoke("remove");
98+
cy.get("th:contains('Status') .caret.caret-up").should("not.exist");
99+
cy.get("body").click();
100+
cy.get(`@${pom.api.clusterMocked}`).should("exist");
101+
});
102+
});

apps/cluster-orch/src/components/organism/ClusterList/ClusterList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const ClusterList = ({
6363
clusterToStatuses(item as cm.ClusterInfoRead),
6464
"lifecyclePhase",
6565
).message,
66-
apiName: "status",
66+
apiName: "lifecyclePhase",
6767
Cell: (table) => (
6868
<AggregatedStatuses<AggregatedStatusesMap>
6969
statuses={clusterToStatuses(table.row.original)}

apps/cluster-orch/src/components/organism/cluster/ClusterList.cy.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,50 @@ describe("<ClusterList />", () => {
209209
});
210210
});
211211
});
212+
213+
describe("<ClusterList /> - Sorting by Cluster Status", () => {
214+
const pom = new ClusterListPom("clusterList");
215+
216+
beforeEach(() => {
217+
pom.interceptApis([pom.api.clusterListSuccess]);
218+
cy.mount(<ClusterList hasPermission={true} />, { runtimeConfig });
219+
pom.waitForApis();
220+
});
221+
222+
it("should sort by lifecyclePhase when clicking on the Cluster Status column header", () => {
223+
cy.get("th:contains('Cluster Status') .caret.caret-up").click({
224+
force: true,
225+
});
226+
cy.wait(`@${pom.api.clusterListSuccess}`).then(({ request }) => {
227+
expect(request.url).to.include("orderBy=lifecyclePhase");
228+
expect(request.url).to.include("asc");
229+
});
230+
231+
cy.get("th:contains('Cluster Status') .caret.caret-down").click({
232+
force: true,
233+
});
234+
cy.wait(`@${pom.api.clusterListSuccess}`).then(({ request }) => {
235+
expect(request.url).to.include("orderBy=lifecyclePhase");
236+
expect(request.url).to.include("desc");
237+
});
238+
});
239+
240+
it("should NOT sort by a wrong field when clicking Cluster Status column", () => {
241+
cy.get("th:contains('Cluster Status') .caret.caret-up").click({
242+
force: true,
243+
});
244+
cy.get(`@${pom.api.clusterListSuccess}`)
245+
.its("request.url")
246+
.then((url: string) => {
247+
expect(url).not.to.include("orderBy=status");
248+
expect(url).not.to.include("orderBy=name");
249+
});
250+
});
251+
252+
it("should not trigger sort if Cluster Status column is missing", () => {
253+
cy.get("th:contains('Cluster Status')").invoke("remove");
254+
cy.get("th:contains('Cluster Status') .caret.caret-up").should("not.exist");
255+
cy.get("body").click();
256+
cy.get(`@${pom.api.clusterListSuccess}`).should("exist");
257+
});
258+
});

apps/cluster-orch/src/components/organism/cluster/ClusterList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
240240
Header: "Cluster Status",
241241
accessor: (item) =>
242242
aggregateStatuses(clusterToStatuses(item), "lifecyclePhase").message,
243-
apiName: "status",
243+
apiName: "lifecyclePhase",
244244
Cell: (table) => {
245245
return (
246246
<AggregatedStatuses<AggregatedStatusesMap>

0 commit comments

Comments
 (0)