-
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.
* Add secrets table.
- Loading branch information
Showing
10 changed files
with
292 additions
and
56 deletions.
There are no files selected for viewing
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
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,21 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
import RelativeDate from "./RelativeDate"; | ||
|
||
describe("RelativeDate", () => { | ||
const yesterday = new Date(Date.now() - 60 * 1000 * 60 * 24); | ||
|
||
it("displays a relative date", async () => { | ||
render(<RelativeDate datetime={yesterday.toISOString()} />); | ||
expect(screen.getByText("1 day ago")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays the tooltip if the content is truncated", async () => { | ||
render(<RelativeDate datetime={yesterday.toISOString()} />); | ||
const fullDate = yesterday.toLocaleString(); | ||
expect(screen.queryByText(fullDate)).not.toBeInTheDocument(); | ||
await userEvent.hover(screen.getByText("1 day ago")); | ||
expect(screen.getByText(fullDate)).toBeInTheDocument(); | ||
}); | ||
}); |
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 { Tooltip } from "@canonical/react-components"; | ||
|
||
import { formatFriendlyDateToNow } from "components/utils"; | ||
|
||
type Props = { | ||
datetime: string; | ||
}; | ||
|
||
const RelativeDate = ({ datetime }: Props) => { | ||
return ( | ||
<Tooltip | ||
message={new Date(datetime).toLocaleString()} | ||
position="top-center" | ||
> | ||
{formatFriendlyDateToNow(datetime)} | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default RelativeDate; |
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 "./RelativeDate"; |
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
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
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
125 changes: 125 additions & 0 deletions
125
src/pages/EntityDetails/Model/Secrets/SecretsTable/SecretsTable.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,125 @@ | ||
import { screen } from "@testing-library/react"; | ||
|
||
import { TestId as LoadingTestId } from "components/LoadingSpinner/LoadingSpinner"; | ||
import type { RootState } from "store/store"; | ||
import { rootStateFactory } from "testing/factories"; | ||
import { | ||
configFactory, | ||
generalStateFactory, | ||
credentialFactory, | ||
} from "testing/factories/general"; | ||
import { | ||
modelListInfoFactory, | ||
secretsStateFactory, | ||
listSecretResultFactory, | ||
modelSecretsFactory, | ||
} from "testing/factories/juju/juju"; | ||
import { renderComponent } from "testing/utils"; | ||
import urls from "urls"; | ||
|
||
import SecretsTable, { TestId } from "./SecretsTable"; | ||
|
||
describe("SecretsTable", () => { | ||
let state: RootState; | ||
const path = urls.model.index(null); | ||
const url = urls.model.index({ | ||
userName: "eggman@external", | ||
modelName: "test-model", | ||
}); | ||
|
||
beforeEach(() => { | ||
state = rootStateFactory.build({ | ||
general: generalStateFactory.build({ | ||
credentials: { | ||
"wss://example.com/api": credentialFactory.build(), | ||
}, | ||
config: configFactory.build({ | ||
controllerAPIEndpoint: "wss://example.com/api", | ||
}), | ||
}), | ||
juju: { | ||
models: { | ||
abc123: modelListInfoFactory.build({ | ||
wsControllerURL: "wss://example.com/api", | ||
uuid: "abc123", | ||
}), | ||
}, | ||
secrets: secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
items: [ | ||
listSecretResultFactory.build({ label: "secret1" }), | ||
listSecretResultFactory.build({ label: "secret2" }), | ||
], | ||
loaded: true, | ||
}), | ||
}), | ||
}, | ||
}); | ||
}); | ||
|
||
it("displays the loading state", async () => { | ||
state.juju.secrets = secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
loading: true, | ||
}), | ||
}); | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect(screen.queryByTestId(LoadingTestId.LOADING)).toBeInTheDocument(); | ||
}); | ||
|
||
it("handles no secrets", async () => { | ||
state.juju.secrets = secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
loaded: true, | ||
}), | ||
}); | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect(screen.queryByTestId(TestId.SECRETS_TABLE)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display secrets", async () => { | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect(screen.getByRole("cell", { name: "secret1" })).toBeInTheDocument(); | ||
expect(screen.getByRole("cell", { name: "secret2" })).toBeInTheDocument(); | ||
}); | ||
|
||
it("should remove the prefix from the id", async () => { | ||
state.juju.secrets = secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
items: [listSecretResultFactory.build({ uri: "secret:aabbccdd" })], | ||
loaded: true, | ||
}), | ||
}); | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect(screen.getByRole("cell", { name: "aabbccdd" })).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays 'Model' instead of UUID", async () => { | ||
state.juju.secrets = secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
items: [listSecretResultFactory.build({ "owner-tag": "model-abc123" })], | ||
loaded: true, | ||
}), | ||
}); | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect(screen.getByRole("cell", { name: "Model" })).toBeInTheDocument(); | ||
}); | ||
|
||
it("does not change application owners", async () => { | ||
state.juju.secrets = secretsStateFactory.build({ | ||
abc123: modelSecretsFactory.build({ | ||
items: [ | ||
listSecretResultFactory.build({ "owner-tag": "application-def456" }), | ||
], | ||
loaded: true, | ||
}), | ||
}); | ||
renderComponent(<SecretsTable />, { state, path, url }); | ||
expect( | ||
screen.queryByRole("cell", { name: "Model" }), | ||
).not.toBeInTheDocument(); | ||
expect( | ||
screen.getByRole("cell", { name: "application-def456" }), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.