dfinity / nns-dapp

The Dapp of the Internet Computer's Network Nervous System.
https://nns.ic0.app/
Other
112 stars 38 forks source link

Clean up NnsProposals.spec.ts #5402

Closed dskloetd closed 2 months ago

dskloetd commented 2 months ago

Motivation

NnsProposals.spec.ts was mocking several the proposalsStore and the authStore. Mocking stores is fragile and unnecessary.

Because the test mocked the proposalsStore it completely ignored the fact that the component empties the store and then fills it with the result of queryProposals.

As a result one test was supposed to check that a spinner is shown while proposals are being loaded, but this is not even the case. Skeleton cards are being shown while proposals are loaded. A spinner is shown when additional proposals are loaded into the infinite scroll. Because of the mocked proposals store, the component thought there were already proposals loaded and additional ones were being loaded, showing the spinner instead of the skeleton cards as a result.

Changes

  1. Stop mocking authStore and instead just set the identity using resetIdentity.
  2. Stop mocking proposalsStore and instead mock queryProposals so the NnsProposals can reset and fill the proposalsStore itself.
  3. Use fake timers to work around the debouncing used by NnsProposals.
  4. Fix the test which does the initial load of proposals to expect skeleton cards and check that the skeleton cards go away after loading finishes.
  5. Add a new test which expects a spinner when additional pages of proposals are loaded.

Tests

test only

Todos