-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WD-11592 - refactor: remove nested components in ApplicationsTab (#1772)
- Loading branch information
1 parent
136ccb8
commit 592b3c4
Showing
12 changed files
with
279 additions
and
73 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/pages/EntityDetails/Model/ApplicationsTab/AppOffersTable/AppOffersTable.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { screen, within } from "@testing-library/react"; | ||
|
||
import type { RootState } from "store/store"; | ||
import { rootStateFactory } from "testing/factories"; | ||
import { applicationOfferStatusFactory } from "testing/factories/juju/ClientV6"; | ||
import { | ||
modelDataFactory, | ||
modelDataInfoFactory, | ||
} from "testing/factories/juju/juju"; | ||
import { renderComponent } from "testing/utils"; | ||
|
||
import AppOffersTable from "./AppOffersTable"; | ||
import { Label } from "./types"; | ||
|
||
describe("ApplicationsTab", () => { | ||
let state: RootState; | ||
const path = "/models/:userName/:modelName"; | ||
const url = "/models/test@external/test-model"; | ||
|
||
beforeEach(() => { | ||
state = rootStateFactory.build({}); | ||
}); | ||
|
||
it("should show empty message", () => { | ||
renderComponent(<AppOffersTable />, { path, url, state }); | ||
expect(within(screen.getByRole("grid")).getAllByRole("row")).toHaveLength( | ||
1, | ||
); | ||
expect(screen.getByText(Label.NO_OFFERS)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show application offers", () => { | ||
state.juju.modelData = { | ||
test123: modelDataFactory.build({ | ||
info: modelDataInfoFactory.build({ | ||
uuid: "test123", | ||
name: "test-model", | ||
}), | ||
offers: { | ||
db: applicationOfferStatusFactory.build({ | ||
endpoints: { | ||
mockEndpoint: { | ||
interface: "mockInterface", | ||
limit: 1, | ||
name: "mockName", | ||
role: "mockRole", | ||
}, | ||
}, | ||
}), | ||
}, | ||
}), | ||
}; | ||
renderComponent(<AppOffersTable />, { path, url, state }); | ||
const rows = within(screen.getByRole("grid")).getAllByRole("row"); | ||
expect(rows).toHaveLength(2); | ||
const headers = within(rows[0]).getAllByRole("columnheader"); | ||
expect(headers).toHaveLength(4); | ||
expect(headers[0]).toHaveTextContent("offers"); | ||
expect(headers[1]).toHaveTextContent("interface"); | ||
expect(headers[2]).toHaveTextContent("connection"); | ||
expect(headers[3]).toHaveTextContent("offer url"); | ||
const appOffersRow = within(rows[1]).getAllByRole("gridcell"); | ||
expect(appOffersRow).toHaveLength(4); | ||
expect(appOffersRow[0]).toHaveTextContent("db"); | ||
expect(appOffersRow[1]).toHaveTextContent("mockEndpoint"); | ||
expect(appOffersRow[2]).toHaveTextContent("1 / 2"); | ||
expect(appOffersRow[3]).toHaveTextContent("-"); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/pages/EntityDetails/Model/ApplicationsTab/AppOffersTable/AppOffersTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MainTable } from "@canonical/react-components"; | ||
import { useMemo } from "react"; | ||
|
||
import useModelStatus from "hooks/useModelStatus"; | ||
import { appsOffersTableHeaders } from "tables/tableHeaders"; | ||
import { generateAppOffersRows } from "tables/tableRows"; | ||
|
||
import { Label } from "./types"; | ||
|
||
const AppOffersTable = () => { | ||
const modelStatusData = useModelStatus(); | ||
const appOffersRows = useMemo( | ||
() => generateAppOffersRows(modelStatusData), | ||
[modelStatusData], | ||
); | ||
|
||
return ( | ||
<MainTable | ||
headers={appsOffersTableHeaders} | ||
rows={appOffersRows} | ||
className="entity-details__offers p-main-table" | ||
sortable | ||
emptyStateMsg={Label.NO_OFFERS} | ||
/> | ||
); | ||
}; | ||
|
||
export default AppOffersTable; |
1 change: 1 addition & 0 deletions
1
src/pages/EntityDetails/Model/ApplicationsTab/AppOffersTable/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./AppOffersTable"; |
3 changes: 3 additions & 0 deletions
3
src/pages/EntityDetails/Model/ApplicationsTab/AppOffersTable/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum Label { | ||
NO_OFFERS = "There are no offers associated with this model", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/pages/EntityDetails/Model/ApplicationsTab/ContentRevealTitle/ContentRevealTitle.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { screen } from "@testing-library/react"; | ||
|
||
import { renderComponent } from "testing/utils"; | ||
|
||
import ContentRevealTitle from "./ContentRevealTitle"; | ||
|
||
describe("ContentRevealTitle", () => { | ||
it("should display correct info for single offer and no chip group", () => { | ||
renderComponent( | ||
<ContentRevealTitle count={1} subject="Offer" chips={null} />, | ||
); | ||
expect(screen.getByText("1 Offer")).toBeInTheDocument(); | ||
expect(document.querySelector(".chip-group")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("should display correct info for multiple local applications and no chip group", () => { | ||
renderComponent( | ||
<ContentRevealTitle count={3} subject="Local application" chips={null} />, | ||
); | ||
expect(screen.getByText("3 Local applications")).toBeInTheDocument(); | ||
expect(document.querySelector(".chip-group")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("should display correct info for single remote application and chip group", () => { | ||
const fakeChips = { | ||
foo: 1, | ||
bar: 2, | ||
baz: 3, | ||
}; | ||
renderComponent( | ||
<ContentRevealTitle | ||
count={1} | ||
subject="Remote application" | ||
chips={fakeChips} | ||
/>, | ||
); | ||
expect(screen.getByText("1 Remote application")).toBeInTheDocument(); | ||
expect(document.querySelector(".chip-group")).toBeInTheDocument(); | ||
expect(screen.getByText("1 foo")).toHaveClass("is-foo"); | ||
expect(screen.getByText("2 bar")).toHaveClass("is-bar"); | ||
expect(screen.getByText("3 baz")).toHaveClass("is-baz"); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/pages/EntityDetails/Model/ApplicationsTab/ContentRevealTitle/ContentRevealTitle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Chip } from "components/ChipGroup"; | ||
import ChipGroup from "components/ChipGroup"; | ||
import { pluralize } from "store/juju/utils/models"; | ||
|
||
type Props = { | ||
count: number; | ||
subject: "Offer" | "Local application" | "Remote application"; | ||
chips: Chip | null; | ||
}; | ||
|
||
const ContentRevealTitle = ({ count, subject, chips }: Props) => ( | ||
<> | ||
<span> | ||
{count} {pluralize(count, subject)} | ||
</span> | ||
<ChipGroup chips={chips} className="u-no-margin" descriptor={null} /> | ||
</> | ||
); | ||
|
||
export default ContentRevealTitle; |
1 change: 1 addition & 0 deletions
1
src/pages/EntityDetails/Model/ApplicationsTab/ContentRevealTitle/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./ContentRevealTitle"; |
66 changes: 66 additions & 0 deletions
66
src/pages/EntityDetails/Model/ApplicationsTab/RemoteAppsTable/RemoteAppsTable.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { screen, within } from "@testing-library/react"; | ||
|
||
import type { RootState } from "store/store"; | ||
import { rootStateFactory } from "testing/factories"; | ||
import { remoteApplicationStatusFactory } from "testing/factories/juju/ClientV6"; | ||
import { | ||
modelDataFactory, | ||
modelDataInfoFactory, | ||
} from "testing/factories/juju/juju"; | ||
import { renderComponent } from "testing/utils"; | ||
|
||
import RemoteAppsTable from "./RemoteAppsTable"; | ||
import { Label } from "./types"; | ||
|
||
describe("ApplicationsTab", () => { | ||
let state: RootState; | ||
const path = "/models/:userName/:modelName"; | ||
const url = "/models/test@external/test-model"; | ||
|
||
beforeEach(() => { | ||
state = rootStateFactory.build({}); | ||
}); | ||
|
||
it("should show empty message", () => { | ||
renderComponent(<RemoteAppsTable />, { path, url, state }); | ||
expect(within(screen.getByRole("grid")).getAllByRole("row")).toHaveLength( | ||
1, | ||
); | ||
expect(screen.getByText(Label.NO_REMOTE_APPS)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show remote applications", () => { | ||
state.juju.modelData = { | ||
test123: modelDataFactory.build({ | ||
info: modelDataInfoFactory.build({ | ||
uuid: "test123", | ||
name: "test-model", | ||
}), | ||
"remote-applications": { | ||
mysql: remoteApplicationStatusFactory.build({ | ||
relations: { mockRelation: [] }, | ||
}), | ||
}, | ||
}), | ||
}; | ||
renderComponent(<RemoteAppsTable />, { path, url, state }); | ||
const rows = within(screen.getByRole("grid")).getAllByRole("row"); | ||
expect(rows).toHaveLength(2); | ||
const headers = within(rows[0]).getAllByRole("columnheader"); | ||
expect(headers).toHaveLength(5); | ||
expect(headers[0]).toHaveTextContent("remote apps"); | ||
expect(headers[1]).toHaveTextContent("status"); | ||
expect(headers[2]).toHaveTextContent("interface"); | ||
expect(headers[3]).toHaveTextContent("offer url"); | ||
expect(headers[4]).toHaveTextContent("store"); | ||
const remoteAppsRow = within(rows[1]).getAllByRole("gridcell"); | ||
expect(remoteAppsRow).toHaveLength(5); | ||
expect(remoteAppsRow[0]).toHaveTextContent("mysql"); | ||
expect(remoteAppsRow[1]).toHaveTextContent("active"); | ||
expect(remoteAppsRow[2]).toHaveTextContent("mockRelation"); | ||
expect(remoteAppsRow[3]).toHaveTextContent( | ||
"juju-controller:admin/cmr.mysql", | ||
); | ||
expect(remoteAppsRow[4]).toHaveTextContent("-"); | ||
}); | ||
}); |
Oops, something went wrong.