Skip to content

Commit

Permalink
Updated mock creation in unit tests to avoid unexpected test breaks (#…
Browse files Browse the repository at this point in the history
…759)

Signed-off-by: Eric Le Ponner <eric.leponner@icloud.com>
  • Loading branch information
ericleponner authored Nov 21, 2023
1 parent 7556217 commit f2a6ce4
Show file tree
Hide file tree
Showing 43 changed files with 21,827 additions and 57 deletions.
1 change: 1 addition & 0 deletions tests/unit/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe("App.vue", () => {
expect(logos[4].attributes('alt')).toBe("Built On Hedera")
expect(logos[5].attributes('alt')).toBe("Sponsor Logo")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/account/AccountDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe("AccountDetails.vue", () => {
expect(wrapper.find("#recentTransactions").exists()).toBe(true)
expect(wrapper.findComponent(TransactionTable).exists()).toBe(true)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -239,6 +240,7 @@ describe("AccountDetails.vue", () => {
expect(wrapper.get("#maxAutoAssociationValue").text()).toBe("10")
expect(wrapper.get("#receiverSigRequiredValue").text()).toBe("true")

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -319,6 +321,7 @@ describe("AccountDetails.vue", () => {
expect(banner.exists()).toBe(true)
expect(banner.text()).toBe("Account is deleted")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -371,6 +374,7 @@ describe("AccountDetails.vue", () => {
expect(wrapper.get("#pendingRewardValue").text()).toBe("0.12345678$0.03037Period Started Nov 11, 2022, 00:00 UTC")
expect(wrapper.get("#declineRewardValue").text()).toBe("Accepted")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -423,6 +427,7 @@ describe("AccountDetails.vue", () => {
expect(wrapper.get("#pendingRewardValue").text()).toBe("0.00000000$0.00000")
expect(wrapper.find("#declineRewardValue").exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/account/Accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe("Accounts.vue", () => {
"23.42647909"
)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/account/AdminKeyDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe("AdminKeyDetails.vue", () => {
expect(wrapper.text()).toMatch("Account Account ID:" + SAMPLE_ACCOUNT_PROTOBUF_KEY.account)
expect(wrapper.get("#keyValue").text()).toBe("Complex Key (6 levels) See details")

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -162,6 +163,7 @@ describe("AdminKeyDetails.vue", () => {

expect(key.text()).toBe("ED25519: aa2f7b3e759f4531ec2e7941afa449e6a6e610efb52adae89e9cd8e9d40ddcbf")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/block/BlockDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe("BlockDetails.vue", () => {
"123423\n" + "\n" +
"0.0.296939115:12:31.6676 AMFeb 28, 2022, UTC")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -149,6 +150,7 @@ describe("BlockDetails.vue", () => {
"123423\n" + "\n" +
"0.0.296939115:12:31.6676 AMFeb 28, 2022, UTC")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -244,6 +246,7 @@ describe("BlockDetails.vue", () => {
"Contract ID: 0.0.749723" +
"2:42:34.8669 PMMar 7, 2022, UTC")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -355,6 +358,7 @@ describe("BlockDetails.vue", () => {
expect(table.get('thead').text()).toBe("ID Type Content Time & Date")
expect(table.get('tbody').text()).toBe("")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -394,6 +398,7 @@ describe("BlockDetails.vue", () => {
expect(table.get('thead').text()).toBe("ID Type Content Time & Date")
expect(table.get('tbody').text()).toBe("")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/block/Blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe("Blocks.vue", () => {
"25175997" + "6:58:28.2114 AMSep 23, 2022, UTC" + "5" + "0"
)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/contract/ContractDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe("ContractDetails.vue", () => {

expect(wrapper.findComponent(ContractResultTable).exists()).toBe(true)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -166,6 +167,7 @@ describe("ContractDetails.vue", () => {
expect(cells[2].text()).toBe("None")
expect(cells[3].text()).toBe("0.00000000")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -235,6 +237,7 @@ describe("ContractDetails.vue", () => {
expect(wrapper.get("#fileValue").text()).toBe("0.0.803267")
expect(wrapper.get("#evmAddress").text()).toBe("EVM Address:0x00000000000000000000000000000000000b70cfCopy")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -277,6 +280,7 @@ describe("ContractDetails.vue", () => {
expect(banner.exists()).toBe(true)
expect(banner.text()).toBe("Contract has expired and is in grace period")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -318,6 +322,7 @@ describe("ContractDetails.vue", () => {
const banner = wrapper.findComponent(NotificationBanner)
expect(banner.exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -359,6 +364,7 @@ describe("ContractDetails.vue", () => {
expect(banner.exists()).toBe(true)
expect(banner.text()).toBe("Contract is deleted")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -421,6 +427,7 @@ describe("ContractDetails.vue", () => {
expect(wrapper.find("#swarmHashValue").exists()).toBe(false)
expect(wrapper.find("#ipfsHash").exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -458,6 +465,7 @@ describe("ContractDetails.vue", () => {
expect(cards[1].text()).toMatch(RegExp("^Contract Bytecode"))
expect(cards[1].get('a').text()).toBe("Verify contract (beta)")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/contract/ContractResult.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe("ContractResult.vue", () => {

expect(wrapper.findAll("#logIndexValue").length).toBe(3)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/contract/Contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("Contracts.vue", () => {
"Mirror Node acceptance test: 2022-03-07T15:09:15.228564328Z Create contract"
)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down
1 change: 1 addition & 0 deletions tests/unit/dashboard/HbarMarketDashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("HbarMarketDashboard.vue ", () => {
expect(logos[0].attributes('alt')).toBe("Trend Up")
expect(logos[1].attributes('alt')).toBe("Trend Up")

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down
1 change: 1 addition & 0 deletions tests/unit/dashboard/MainDashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe("MainDashboard.vue", () => {
"0.0.120438" + "None" + "1:59:03.9622 PMMar 8, 2022, UTC"
)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/node/NodeDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe("NodeDetails.vue", () => {
expect(wrapper.get("#notRewardedPercent").text()).toBe("20% of total")
expect(wrapper.get("#stakingPeriod").text()).toBe("Current Staking Period24HOURS")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -187,6 +188,7 @@ describe("NodeDetails.vue", () => {
expect(wrapper.get("#maxAutoAssociationValue").text()).toBe("10")
expect(wrapper.get("#receiverSigRequiredValue").text()).toBe("true")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/node/NodeTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ describe("NodeTable.vue", () => {
const tooltipPercentage = "Total amount of HBAR staked to this validator for consensus / total amount of HBAR staked to all validators for consensus."
const tooltipRewardRate = "Approximate annual reward rate based on the reward earned during the last 24h period."

const mock = new MockAdapter(axios);
const matcher1 = "/api/v1/network/nodes"
mock.onGet(matcher1).reply(200, SAMPLE_NETWORK_NODES);

it("should list the 3 nodes in the table", async () => {

process.env = Object.assign(process.env, { VITE_APP_ENABLE_STAKING: true });

await router.push("/") // To avoid "missing required param 'network'" error

const mock = new MockAdapter(axios);
const matcher1 = "/api/v1/network/nodes"
mock.onGet(matcher1).reply(200, SAMPLE_NETWORK_NODES);

let testTotalStaked = 0
for (const node of SAMPLE_NETWORK_NODES.nodes) {
testTotalStaked += node.stake
Expand Down Expand Up @@ -96,6 +96,7 @@ describe("NodeTable.vue", () => {
tooltipRewardRate + "3%"
)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/node/Nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe("Nodes.vue", () => {
tooltipRewardRate + "3%"
)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/staking/RewardsCalculator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe("Staking.vue", () => {
expect(wrapper.find('#yearlyReward').text()).toBe("Approx Yearly Reward0HBAR")
expect(wrapper.find('#yearlyRate').text()).toBe("Approx Yearly Reward Rate0%")

mock.restore()
wrapper.unmount()
await flushPromises()
})
Expand Down Expand Up @@ -138,6 +139,7 @@ describe("Staking.vue", () => {
expect(wrapper.find('#yearlyReward').text()).toBe("Approx Yearly Reward200HBAR")
expect(wrapper.find('#yearlyRate').text()).toBe("Approx Yearly Reward Rate2%")

mock.restore()
wrapper.unmount()
await flushPromises()
})
Expand Down
1 change: 1 addition & 0 deletions tests/unit/staking/Staking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ describe("Staking.vue", () => {
expect(walletManager.accountIds.value).toStrictEqual([])
expect(walletManager.accountId.value).toBeNull()

mock.restore()
wrapper.unmount()
await flushPromises()
})
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/token/TokenDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe("TokenDetails.vue", () => {
expect(wrapper.findComponent(TokenBalanceTable).exists()).toBe(true)
expect(wrapper.findComponent(NftHolderTable).exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -165,6 +166,7 @@ describe("TokenDetails.vue", () => {
expect(wrapper.findComponent(NftHolderTable).exists()).toBe(true)
expect(wrapper.findComponent(TokenBalanceTable).exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -232,6 +234,7 @@ describe("TokenDetails.vue", () => {
expect(wrapper.findComponent(NftHolderTable).exists()).toBe(false)
expect(wrapper.findComponent(TokenBalanceTable).exists()).toBe(true)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -302,6 +305,7 @@ describe("TokenDetails.vue", () => {
expect(wrapper.find("#feeScheduleKey").text()).toBe("Fee Schedule Keyc539 536f 9599 daef eeb7 7767 7aa1 aeea 2242 dfc7 cca9 2348 c228 a518 7a0f af2bCopyED25519")
expect(wrapper.find("#pauseKey").text()).toBe("Pause Keyc539 536f 9599 daef eeb7 7767 7aa1 aeea 2242 dfc7 cca9 2348 c228 a518 7a0f af2bCopyED25519")

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -349,6 +353,7 @@ describe("TokenDetails.vue", () => {
expect(wrapper.find("#feeScheduleKey").text()).toBe("Fee Schedule KeyNoneCustom fee schedule is immutable")
expect(wrapper.find("#pauseKey").text()).toBe("Pause KeyNoneToken cannot be paused")

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down Expand Up @@ -389,6 +394,7 @@ describe("TokenDetails.vue", () => {
+ 'EVM Address:' + testTokenEVMAddress + "Copy"))
expect(wrapper.text()).toMatch("Token is deleted")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -445,6 +451,7 @@ describe("TokenDetails.vue", () => {

expect(customFees.findComponent(RoyaltyFeeTable).exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -501,6 +508,7 @@ describe("TokenDetails.vue", () => {
"0.1%" + "0.0.617889" + "100" + "0.0.748383" + "Ħ Frens Kingdom" +
"0.2%" + "0.0.617890" + "200" + "0.0.748383" + "Ħ Frens Kingdom")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -536,6 +544,7 @@ describe("TokenDetails.vue", () => {
const customFees = wrapper.findComponent(TokenCustomFees)
expect(customFees.exists()).toBe(false)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/token/Tokens.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe("Tokens.vue", () => {
"ĦFRENSKINGDOM"
)

mock.restore()
wrapper.unmount()
await flushPromises()

Expand Down
Binary file modified tests/unit/topic/TopicDetails.spec.ts
Binary file not shown.
1 change: 1 addition & 0 deletions tests/unit/topic/Topics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("Topics.vue", () => {
"Mirror Node acceptance test: 2022-03-07T15:14:18.167555058Z Create Topic"
)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/transaction/TransactionByIdTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("TransactionByIdTable.vue", () => {
"1:29:17.0144 PMSep 6, 2022, UTCCRYPTO TRANSFER0.0.48113503\n\n0.0.48193741Reptilian Egg NFT\n\n0.0.48193739Child2"
)

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down Expand Up @@ -118,6 +119,7 @@ describe("TransactionByIdTable.vue", () => {
expect(cells[3].text()).toBe("Scheduled")
expect(cells[4].text()).toBe("0")

mock.restore()
wrapper.unmount()
await flushPromises()
});
Expand Down
Loading

0 comments on commit f2a6ce4

Please sign in to comment.