Skip to content

Commit

Permalink
test(jest): unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdisalvo-crd committed Jul 15, 2024
1 parent 03a34e3 commit 3855f92
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/ui/__fixtures__/filteredIdentifierFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const filteredIdentifierFix: IdentifierShortDetails[] = [
theme: 0,
isPending: true,
signifyName: "Test",
multisigManageAid: "123",
},
];

Expand Down
48 changes: 47 additions & 1 deletion src/ui/__fixtures__/identifierFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,58 @@ import { IdentifierDetails } from "../../core/agent/services/identifier.types";

const identifierFix: IdentifierDetails[] = [
{
signifyName: "Test",
id: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb",
displayName: "Professional ID",
createdAtUTC: "2023-01-01T19:23:24Z",
theme: 0,
isPending: false,
signifyName: "Test",
s: "4", // Sequence number, only show if s > 0
dt: "2023-06-12T14:07:53.224866+00:00", // Last key rotation timestamp, if s > 0
kt: 2, // Keys signing threshold (only show if kt > 1)
k: [
// List of signing keys - array
"DCF6b0c5aVm_26_sCTgLB4An6oUxEM5pVDDLqxxXDxH-",
],
nt: 3, // Next keys signing threshold, only show if nt > 1
n: [
// Next keys digests - array
"EIZ-n_hHHY5ERGTzvpXYBkB6_yBAM4RXcjQG3-JykFvF",
],
bt: 1, // Backer threshold and backer keys below
b: ["BIe_q0F4EkYPEne6jUnSV1exxOYeGf_AMSMvegpF4XQP"], // List of backers
di: "test", // Delegated identifier prefix, don't show if ""
},
{
id: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inx",
displayName: "Professional ID",
createdAtUTC: "2023-01-01T19:23:24Z",
theme: 1,
isPending: false,
signifyName: "Test",
s: "4", // Sequence number, only show if s > 0
dt: "2023-06-12T14:07:53.224866+00:00", // Last key rotation timestamp, if s > 0
kt: 2, // Keys signing threshold (only show if kt > 1)
k: [
// List of signing keys - array
"DCF6b0c5aVm_26_sCTgLB4An6oUxEM5pVDDLqxxXDxH-",
],
nt: 3, // Next keys signing threshold, only show if nt > 1
n: [
// Next keys digests - array
"EIZ-n_hHHY5ERGTzvpXYBkB6_yBAM4RXcjQG3-JykFvF",
],
bt: 1, // Backer threshold and backer keys below
b: ["BIe_q0F4EkYPEne6jUnSV1exxOYeGf_AMSMvegpF4XQP"], // List of backers
di: "test", // Delegated identifier prefix, don't show if ""
},
{
id: "ECHG-cxboMQ78Hwlm2-w6OS3iU275bAKkqC1LjwICPyi",
displayName: "Test MS",
createdAtUTC: "2024-03-07T11:54:56.886Z",
theme: 0,
isPending: true,
signifyName: "Test",
s: "4", // Sequence number, only show if s > 0
dt: "2023-06-12T14:07:53.224866+00:00", // Last key rotation timestamp, if s > 0
kt: 2, // Keys signing threshold (only show if kt > 1)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/CardSlider/CardSlider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("Card slider", () => {
<Provider store={mockedStore}>
<CardSlider
cardType={CardType.IDENTIFIERS}
cardsData={identifierFix}
cardsData={[identifierFix[0]]}
title="title"
name="allidentifiers"
/>
Expand Down
66 changes: 64 additions & 2 deletions src/ui/pages/IdentifierDetails/IdentifierDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { setToastMsg } from "../../../store/reducers/stateCache";
import { ToastMsgType } from "../../globals/types";

const path = TabsRoutePath.IDENTIFIERS + "/" + identifierFix[0].id;
const combineMock = jest.fn(() => identifierFix[0]);

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
Expand Down Expand Up @@ -51,7 +52,7 @@ jest.mock("../../../core/agent/agent", () => ({
Agent: {
agent: {
identifiers: {
getIdentifier: jest.fn().mockResolvedValue(identifierFix[0]),
getIdentifier: () => combineMock(),
rotateIdentifier: (id: string) => rotateIdentifierMock(id),
},
connections: {
Expand Down Expand Up @@ -95,10 +96,14 @@ const storeMockedAidKeri = {
dispatch: dispatchMock,
};

describe("Cards Details page", () => {
describe("Cards Details page (not multi-sig)", () => {
beforeAll(async () => {
await new ConfigurationService().start();
});
beforeEach(() => {
combineMock.mockReturnValue(identifierFix[0]);
});

test("It opens the sharing modal", async () => {
const { getByTestId, queryByTestId } = render(
<Provider store={storeMockedAidKeri}>
Expand Down Expand Up @@ -536,3 +541,60 @@ describe("Cards Details page", () => {
});
});
});

describe("Cards Details page (multi-sig)", () => {
beforeAll(async () => {
await new ConfigurationService().start();
});
beforeEach(() => {
combineMock.mockReturnValue(identifierFix[2]);
});

test("Cannot rotate key", async () => {
const initialStateKeri = {
stateCache: {
routes: [TabsRoutePath.IDENTIFIERS],
authentication: {
loggedIn: true,
time: Date.now(),
passcodeIsSet: true,
passwordIsSet: false,
},
},
seedPhraseCache: {
seedPhrase: "",
bran: "bran",
},
identifiersCache: {
identifiers: [filteredIdentifierFix[2]],
favourites: [],
},
};

const storeMockedAidKeri = {
...mockStore(initialStateKeri),
dispatch: dispatchMock,
};

const { queryByTestId } = render(
<Provider store={storeMockedAidKeri}>
<MemoryRouter initialEntries={[path]}>
<Route
path={path}
component={IdentifierDetails}
/>
</MemoryRouter>
</Provider>
);

await waitFor(() =>
expect(queryByTestId("identifier-card-detail-spinner-container")).toBe(
null
)
);

await waitFor(() =>
expect(queryByTestId("signing-key-0-action-icon")).toBe(null)
);
});
});

0 comments on commit 3855f92

Please sign in to comment.