Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WD-8394 - Add secrets tab #1684

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/pages/EntityDetails/EntityDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "testing/factories/juju/model-watcher";
import { renderComponent } from "testing/utils";
import urls from "urls";
import { ModelTab } from "urls";

import EntityDetails, { Label } from "./EntityDetails";

Expand Down Expand Up @@ -115,7 +116,7 @@ describe("Entity Details Container", () => {
it("lists the correct tabs", () => {
renderComponent(<EntityDetails />, { path, url, state });
expect(screen.getByTestId("view-selector")).toHaveTextContent(
/^ApplicationsIntegrationsLogsMachines$/,
/^ApplicationsIntegrationsLogsSecretsMachines$/,
);
});

Expand All @@ -134,7 +135,7 @@ describe("Entity Details Container", () => {
};
renderComponent(<EntityDetails />, { path, url, state });
expect(screen.getByTestId("view-selector")).toHaveTextContent(
/^ApplicationsIntegrationsLogs$/,
/^ApplicationsIntegrationsLogsSecrets$/,
);
});

Expand All @@ -144,19 +145,23 @@ describe("Entity Details Container", () => {
const sections = [
{
text: "Applications",
query: "apps",
query: ModelTab.APPS,
},
{
text: "Integrations",
query: "integrations",
query: ModelTab.INTEGRATIONS,
},
{
text: "Logs",
query: "logs",
query: ModelTab.LOGS,
},
{
text: "Machines",
query: "machines",
query: ModelTab.MACHINES,
},
{
text: "Secrets",
query: ModelTab.SECRETS,
},
];
sections.forEach((section) => {
Expand Down
7 changes: 7 additions & 0 deletions src/pages/EntityDetails/EntityDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ const EntityDetails = ({ modelWatcherError }: Props) => {
to: urls.model.tab({ userName, modelName, tab: ModelTab.LOGS }),
component: Link,
},
{
active: activeView === "secrets",
label: "Secrets",
onClick: (e: MouseEvent) => handleNavClick(e),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

to: urls.model.tab({ userName, modelName, tab: ModelTab.SECRETS }),
component: Link,
},
];

if (modelInfo?.type !== "kubernetes") {
Expand Down
11 changes: 11 additions & 0 deletions src/pages/EntityDetails/Model/Model.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,17 @@ describe("Model", () => {
expect(screen.getByTestId(TestId.CONSUMED)).toBeInTheDocument();
});

it("can display the secrets tab via the URL", async () => {
renderComponent(<Model />, {
state,
url: "/models/eggman@external/test1?activeView=secrets",
path,
});
expect(
within(screen.getByTestId(TestId.MAIN)).getByText("Secrets"),
).toBeInTheDocument();
});

it("renders the details pane for models shared-with-me", () => {
state.juju.modelWatcherData = {
abc123: modelWatcherModelDataFactory.build({
Expand Down
6 changes: 5 additions & 1 deletion src/pages/EntityDetails/Model/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import {

import ApplicationsTab from "./ApplicationsTab/ApplicationsTab";
import Logs from "./Logs";
import Secrets from "./Secrets";

export enum Label {
ACCESS_BUTTON = "Model access",
}

export enum TestId {
CONSUMED = "consumed",
MAIN = "entity-details-main",
OFFERS = "offers",
}

Expand All @@ -56,6 +58,7 @@ const shouldShow = (segment: string, activeView: string) => {
case "machines":
case "integrations":
case "logs":
case "secrets":
if (segment === "relations-title") {
return true;
}
Expand Down Expand Up @@ -160,7 +163,7 @@ const Model = () => {
/>
)}
</div>
<div className="entity-details__main">
<div className="entity-details__main" data-testid={TestId.MAIN}>
{shouldShow("apps", query.activeView) && <ApplicationsTab />}
{shouldShow("machines", query.activeView) &&
(machinesTableRows.length > 0 ? (
Expand Down Expand Up @@ -242,6 +245,7 @@ const Model = () => {
</>
)}
{shouldShow("logs", query.activeView) && <Logs />}
{shouldShow("secrets", query.activeView) && <Secrets />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need to add case "secrets": in the definition of shouldShow. Currently, the Secrets page doesn't render.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks!

</div>
</>
);
Expand Down
12 changes: 12 additions & 0 deletions src/pages/EntityDetails/Model/Secrets/Secrets.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { screen } from "@testing-library/react";

import { renderComponent } from "testing/utils";

import Secrets from "./Secrets";

describe("Secrets", () => {
it("can display the action logs tab", async () => {
renderComponent(<Secrets />);
expect(screen.getByText("Secrets")).toBeInTheDocument();
});
});
5 changes: 5 additions & 0 deletions src/pages/EntityDetails/Model/Secrets/Secrets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Secrets = () => {
return <div>Secrets</div>;
};

export default Secrets;
1 change: 1 addition & 0 deletions src/pages/EntityDetails/Model/Secrets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Secrets";
1 change: 1 addition & 0 deletions src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ModelTab {
MACHINES = "machines",
INTEGRATIONS = "integrations",
LOGS = "logs",
SECRETS = "secrets",
}

export type AppTab = "machines" | "units";
Expand Down