From 86a8796b1a11c6b570cb342c297cf27dee783450 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Wed, 7 Feb 2024 13:43:32 +0700 Subject: [PATCH 1/4] test(utils): add unit test for account store (mobx) --- src/lib/stores/account.test.ts | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/lib/stores/account.test.ts diff --git a/src/lib/stores/account.test.ts b/src/lib/stores/account.test.ts new file mode 100644 index 000000000..d4e50e404 --- /dev/null +++ b/src/lib/stores/account.test.ts @@ -0,0 +1,67 @@ +import { zBechAddr } from "lib/types"; + +import { AccountStore } from "./account"; + +jest.mock("mobx-persist-store", () => ({ + isHydrated: jest.fn().mockReturnValue(true), + makePersistable: jest.fn(), +})); + +describe("accountStore", () => { + let accountStore: AccountStore; + + beforeEach(() => { + accountStore = new AccountStore(); + }); + + test("user key management", () => { + expect(accountStore.isAccountUserKeyExist()).toBeFalsy(); + + accountStore.setAccountUserKey("user-key"); + + expect(accountStore.isAccountUserKeyExist()).toBeTruthy(); + }); + + test("account info", () => { + expect( + accountStore.getAccountLocalInfo(zBechAddr.parse("address")) + ).toBeUndefined(); + + accountStore.updateAccountLocalInfo( + zBechAddr.parse("address"), + "name", + "description" + ); + + expect( + accountStore.getAccountLocalInfo(zBechAddr.parse("address")) + ).toEqual({ + address: zBechAddr.parse("address"), + name: "name", + description: "description", + }); + }); + + test("saved account", () => { + expect(accountStore.savedAccounts).toEqual({}); + expect(accountStore.isAccountSaved(zBechAddr.parse("address"))).toBeFalsy(); + + accountStore.updateAccountLocalInfo( + zBechAddr.parse("address"), + "name", + "description" + ); + + expect( + accountStore.isAccountSaved(zBechAddr.parse("address")) + ).toBeTruthy(); + + expect(accountStore.getSavedAccounts()).toEqual([ + { + address: zBechAddr.parse("address"), + name: "name", + description: "description", + }, + ]); + }); +}); From 076e024e0c935bd2d26cb6a55c6e463e78d0da3c Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Wed, 7 Feb 2024 13:47:58 +0700 Subject: [PATCH 2/4] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69012617..9385b17a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +- [#770](https://github.com/alleslabs/celatone-frontend/pull/770) Add unit test for account store (mobx) - [#769](https://github.com/alleslabs/celatone-frontend/pull/769) Add unit test for format.test.ts on shortenName function - [#768](https://github.com/alleslabs/celatone-frontend/pull/768) Add unit test for truncate.test.ts - [#767](https://github.com/alleslabs/celatone-frontend/pull/767) Add unit test for fee.test.ts From cd3a7aebd829cdf80c12e167b208f6f0bf61047a Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Wed, 7 Feb 2024 13:55:28 +0700 Subject: [PATCH 3/4] test(utils): update unit test for account store mobx --- src/lib/stores/account.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib/stores/account.test.ts b/src/lib/stores/account.test.ts index d4e50e404..8c13eab36 100644 --- a/src/lib/stores/account.test.ts +++ b/src/lib/stores/account.test.ts @@ -2,11 +2,6 @@ import { zBechAddr } from "lib/types"; import { AccountStore } from "./account"; -jest.mock("mobx-persist-store", () => ({ - isHydrated: jest.fn().mockReturnValue(true), - makePersistable: jest.fn(), -})); - describe("accountStore", () => { let accountStore: AccountStore; From 723c610110fc9a87023759a0be87f0b988568539 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Thu, 8 Feb 2024 11:17:03 +0700 Subject: [PATCH 4/4] refactor(utils): update account test file --- src/lib/stores/account.test.ts | 35 +++++++++++----------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/lib/stores/account.test.ts b/src/lib/stores/account.test.ts index 8c13eab36..d7ac78af7 100644 --- a/src/lib/stores/account.test.ts +++ b/src/lib/stores/account.test.ts @@ -4,6 +4,7 @@ import { AccountStore } from "./account"; describe("accountStore", () => { let accountStore: AccountStore; + const address = zBechAddr.parse("address"); beforeEach(() => { accountStore = new AccountStore(); @@ -18,20 +19,12 @@ describe("accountStore", () => { }); test("account info", () => { - expect( - accountStore.getAccountLocalInfo(zBechAddr.parse("address")) - ).toBeUndefined(); - - accountStore.updateAccountLocalInfo( - zBechAddr.parse("address"), - "name", - "description" - ); - - expect( - accountStore.getAccountLocalInfo(zBechAddr.parse("address")) - ).toEqual({ - address: zBechAddr.parse("address"), + expect(accountStore.getAccountLocalInfo(address)).toBeUndefined(); + + accountStore.updateAccountLocalInfo(address, "name", "description"); + + expect(accountStore.getAccountLocalInfo(address)).toEqual({ + address: "address", name: "name", description: "description", }); @@ -39,21 +32,15 @@ describe("accountStore", () => { test("saved account", () => { expect(accountStore.savedAccounts).toEqual({}); - expect(accountStore.isAccountSaved(zBechAddr.parse("address"))).toBeFalsy(); + expect(accountStore.isAccountSaved(address)).toBeFalsy(); - accountStore.updateAccountLocalInfo( - zBechAddr.parse("address"), - "name", - "description" - ); + accountStore.updateAccountLocalInfo(address, "name", "description"); - expect( - accountStore.isAccountSaved(zBechAddr.parse("address")) - ).toBeTruthy(); + expect(accountStore.isAccountSaved(address)).toBeTruthy(); expect(accountStore.getSavedAccounts()).toEqual([ { - address: zBechAddr.parse("address"), + address: "address", name: "name", description: "description", },