bitwarden-estensione-browser/libs/common/spec/models/view/loginView.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
943 B
TypeScript
Raw Normal View History

2022-06-28 02:25:29 +02:00
import { LoginUriView } from "@bitwarden/common/models/view/loginUriView";
import { LoginView } from "@bitwarden/common/models/view/loginView";
jest.mock("@bitwarden/common/models/view/loginUriView");
2022-06-29 05:23:53 +02:00
const testValues = {
username: "myUsername",
password: "myPassword",
totp: "totpSeed",
autofillOnPageLoad: true,
uris: ["uri1", "uri2", "uri3"],
passwordRevisionDate: new Date(),
};
2022-06-28 02:25:29 +02:00
describe("LoginView", () => {
beforeEach(() => {
(LoginUriView as any).mockClear();
});
2022-06-29 05:23:53 +02:00
it("fromJSON hydrates new view object", () => {
2022-06-29 05:42:15 +02:00
const parsed = JSON.parse(JSON.stringify(testValues));
2022-06-29 05:23:53 +02:00
jest
.spyOn(LoginUriView, "fromJSON")
2022-06-29 06:00:05 +02:00
.mockImplementation((key: any) => (key + "fromJSON") as any);
2022-06-28 02:25:29 +02:00
2022-06-29 05:42:15 +02:00
const login = LoginView.fromJSON(parsed);
2022-06-28 02:25:29 +02:00
2022-06-29 05:23:53 +02:00
expect(login).toEqual({
...testValues,
2022-06-28 03:46:29 +02:00
uris: ["uri1fromJSON", "uri2fromJSON", "uri3fromJSON"],
});
2022-06-29 05:23:53 +02:00
expect(login).toBeInstanceOf(LoginView);
2022-06-28 02:25:29 +02:00
});
});