Skip to content

Commit

Permalink
fix: remove button for multi sigs (#578)
Browse files Browse the repository at this point in the history
* fix: remove button for multi sigs

* test(jest): unit tests

* test(jest): unit tests for modal

* fix: removing duplicate identifierData

* fix: remove unused keyboardIsOpen
  • Loading branch information
sdisalvo-crd authored Jul 15, 2024
1 parent d0e1b80 commit 1ca71fb
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 42 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
47 changes: 35 additions & 12 deletions src/ui/components/IdentifierOptions/IdentifierOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,33 @@ describe("Identifier Options modal", () => {
);
await waitForIonicReact();

expect(getByTestId("view-json-identifier-options")).toBeVisible();
expect(getByTestId("edit-identifier-options")).toBeVisible();
expect(getByTestId("share-identifier-options")).toBeVisible();
expect(getByTestId("delete-identifier-options")).toBeVisible();
expect(getByTestId("view-json-identifier-option")).toBeVisible();
expect(getByTestId("edit-identifier-option")).toBeVisible();
expect(getByTestId("rotate-keys-option")).toBeVisible();
expect(getByTestId("share-identifier-option")).toBeVisible();
expect(getByTestId("delete-identifier-option")).toBeVisible();
});

test("should not display the rotate-keys-option inside the modal", async () => {
const setIdentifierOptionsIsOpen = jest.fn();
const setCardData = jest.fn();
const { queryByTestId } = render(
<Provider store={mockedStore}>
<IdentifierOptions
handleRotateKey={jest.fn()}
optionsIsOpen={true}
setOptionsIsOpen={setIdentifierOptionsIsOpen}
cardData={identifierFix[2]}
setCardData={setCardData}
handleDeleteIdentifier={async () => {
jest.fn();
}}
/>
</Provider>
);
await waitForIonicReact();

await waitFor(() => expect(queryByTestId("rotate-keys-option")).toBe(null));
});
});

Expand Down Expand Up @@ -109,7 +132,7 @@ describe("Identifier Options function test", () => {
test("Display JSON view", async () => {
const setIdentifierOptionsIsOpen = jest.fn();
const setCardData = jest.fn();
const { getByTestId, getByText } = render(
const { getByTestId } = render(
<Provider store={mockedStore}>
<IdentifierOptions
handleRotateKey={jest.fn()}
Expand All @@ -125,10 +148,10 @@ describe("Identifier Options function test", () => {
);
await waitForIonicReact();

expect(getByTestId("view-json-identifier-options")).toBeVisible();
expect(getByTestId("view-json-identifier-option")).toBeVisible();

act(() => {
fireEvent.click(getByTestId("view-json-identifier-options"));
fireEvent.click(getByTestId("view-json-identifier-option"));
});

await waitFor(() => {
Expand Down Expand Up @@ -170,10 +193,10 @@ describe("Identifier Options function test", () => {
);
await waitForIonicReact();

expect(getByTestId("edit-identifier-options")).toBeVisible();
expect(getByTestId("edit-identifier-option")).toBeVisible();

act(() => {
fireEvent.click(getByTestId("edit-identifier-options"));
fireEvent.click(getByTestId("edit-identifier-option"));
});

await waitFor(() => {
Expand Down Expand Up @@ -208,7 +231,7 @@ describe("Identifier Options function test", () => {
const setIdentifierOptionsIsOpen = jest.fn();
const setCardData = jest.fn();
const mockDelete = jest.fn();
const { getByTestId, getAllByText } = render(
const { getByTestId } = render(
<Provider store={mockedStore}>
<IdentifierOptions
handleRotateKey={jest.fn()}
Expand All @@ -222,10 +245,10 @@ describe("Identifier Options function test", () => {
);
await waitForIonicReact();

expect(getByTestId("delete-identifier-options")).toBeVisible();
expect(getByTestId("delete-identifier-option")).toBeVisible();

act(() => {
fireEvent.click(getByTestId("delete-identifier-options"));
fireEvent.click(getByTestId("delete-identifier-option"));
});

await waitFor(() => {
Expand Down
43 changes: 21 additions & 22 deletions src/ui/components/IdentifierOptions/IdentifierOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { OptionItem, OptionModal } from "../OptionsModal";
import "./IdentifierOptions.scss";
import { IdentifierOptionsProps } from "./IdentifierOptions.types";
import { IdentifierJsonModal } from "./components";
import { RotateKeyModal } from "../../pages/IdentifierDetails/components/RotateKeyModal/RotateKeyModal";

const IdentifierOptions = ({
optionsIsOpen,
Expand All @@ -41,12 +40,19 @@ const IdentifierOptions = ({
handleRotateKey,
}: IdentifierOptionsProps) => {
const dispatch = useAppDispatch();
const identifierData = useAppSelector(getIdentifiersCache);
const identifiersData = useAppSelector(getIdentifiersCache);
const [editorOptionsIsOpen, setEditorIsOpen] = useState(false);
const [newDisplayName, setNewDisplayName] = useState(cardData.displayName);
const [newSelectedTheme, setNewSelectedTheme] = useState(cardData.theme);
const [viewIsOpen, setViewIsOpen] = useState(false);
const [keyboardIsOpen, setkeyboardIsOpen] = useState(false);
const [isMultiSig, setIsMultiSig] = useState(false);

useEffect(() => {
const identifier = identifiersData.find((data) => data.id === cardData.id);
if (identifier && identifier.multisigManageAid) {
setIsMultiSig(true);
}
}, [identifiersData, cardData.id]);

const verifyDisplayName =
newDisplayName.length > 0 &&
Expand All @@ -58,17 +64,6 @@ const IdentifierOptions = ({
setNewDisplayName(cardData.displayName);
}, [cardData.displayName]);

useEffect(() => {
if (Capacitor.isNativePlatform()) {
Keyboard.addListener("keyboardWillShow", () => {
setkeyboardIsOpen(true);
});
Keyboard.addListener("keyboardWillHide", () => {
setkeyboardIsOpen(false);
});
}
}, []);

useEffect(() => {
setNewSelectedTheme(cardData.theme);
}, [editorOptionsIsOpen]);
Expand All @@ -86,7 +81,7 @@ const IdentifierOptions = ({
const handleSubmit = async () => {
setEditorIsOpen(false);
setOptionsIsOpen(false);
const updatedIdentifiers = [...identifierData];
const updatedIdentifiers = [...identifiersData];
const index = updatedIdentifiers.findIndex(
(identifier) => identifier.id === cardData.id
);
Expand Down Expand Up @@ -148,39 +143,43 @@ const IdentifierOptions = ({
dispatch(setCurrentOperation(OperationType.IDLE));
};

const options: OptionItem[] = [
const optionsRotate: OptionItem[] = [
{
icon: codeSlashOutline,
label: i18n.t("identifiers.details.options.view"),
onClick: viewJson,
testId: "view-json-identifier-options",
testId: "view-json-identifier-option",
},
{
icon: pencilOutline,
label: i18n.t("identifiers.details.options.edit"),
onClick: updateIdentifier,
testId: "edit-identifier-options",
testId: "edit-identifier-option",
},
{
icon: refreshOutline,
label: i18n.t("identifiers.details.options.rotatekeys"),
onClick: rotateKey,
testId: "rotate-keys",
testId: "rotate-keys-option",
},
{
icon: shareOutline,
label: i18n.t("identifiers.details.options.share"),
onClick: share,
testId: "share-identifier-options",
testId: "share-identifier-option",
},
{
icon: trashOutline,
label: i18n.t("identifiers.details.options.delete"),
onClick: deleteIdentifier,
testId: "delete-identifier-options",
testId: "delete-identifier-option",
},
];

const optionsNoRotate = optionsRotate.filter(
(option) => option.testId !== "rotate-keys-option"
);

return (
<>
<OptionModal
Expand All @@ -190,7 +189,7 @@ const IdentifierOptions = ({
header={{
title: `${i18n.t("identifiers.details.options.title")}`,
}}
items={options}
items={isMultiSig ? optionsNoRotate : optionsRotate}
/>
<OptionModal
modalIsOpen={editorOptionsIsOpen}
Expand Down
70 changes: 66 additions & 4 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 @@ -186,7 +191,7 @@ describe("Cards Details page", () => {
});

await waitFor(() => {
expect(getByTestId("edit-identifier-options")).toBeInTheDocument();
expect(getByTestId("edit-identifier-option")).toBeInTheDocument();
});
});

Expand Down Expand Up @@ -256,7 +261,7 @@ describe("Cards Details page", () => {
});

await waitFor(() => {
expect(getByTestId("delete-identifier-options")).toBeInTheDocument();
expect(getByTestId("delete-identifier-option")).toBeInTheDocument();
});

act(() => {
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)
);
});
});
Loading

0 comments on commit 1ca71fb

Please sign in to comment.