WikiEduDashboard icon indicating copy to clipboard operation
WikiEduDashboard copied to clipboard

Write tests for Redux reducers that cover all action types and ensure that state is not mutated

Open ragesoss opened this issue 6 years ago • 11 comments

The reducers that make up the main Redux reducer should all be pure functions that are free of side effects and do not mutate their inputs. This makes unit tests particularly easy to implement, but important for making sure we avoid state-mutation bugs.

The handful of existing specs in test/reducers offer clear examples for how individual actions can be tested for these reducers, with deepFreeze being called on the initial state to guarantee that nothing in the reducer is mutating it.

Choose one or more reducers, and add tests for the functionality of each action type supported by that reducer. This should be done one reducer per commit. If you're working on this, please post a comment to say which reducer you're working on, so that others can work on different reducers.

Ideally, the set of tests for each reducer will provide 100% coverage of that reducer. You can check the coverage by running npm test and then opening coverage/lcov-report/index.html, which includes coverages maps of each javascript file.

ragesoss avatar Oct 10 '18 23:10 ragesoss

(GCI 2018)

I'll be making tests for uploads.js

sunny-lan avatar Oct 29 '18 00:10 sunny-lan

Is it possible to get the tests working without setting up the whole env? I tried just doing yarn and gulp to build, but that results in a large amount of errors from gulp concerning bundler (I have bundler installed)

sunny-lan avatar Oct 30 '18 15:10 sunny-lan

@sunny-lan you must do bundle install before gulp will run, because one of the steps in the gulp pipeline involves calling the ruby script that generates the JS versions of the interface message translations.

ragesoss avatar Oct 30 '18 16:10 ragesoss

That said, I don't think the javascript tests even depend on generating the assets. If you did yarn and it ran without error, you should be able to do yarn test to just run the jest tests.

ragesoss avatar Oct 30 '18 16:10 ragesoss

@ragesoss can I work on adding some of the tests? I have set up the development environment (and opened a PR for #2197).

kagehina919 avatar Nov 08 '18 08:11 kagehina919

I'll take user related reducers: user_profile user_revisions user_training_status user

If someone is doing these let me know.

AZReed avatar Nov 09 '18 16:11 AZReed

Here's what the current coverage on the reducers looks like: reducer coverage

ragesoss avatar Mar 31 '22 17:03 ragesoss

@ragesoss I want to work for adding test for some of the reducers. Plz assign this issue to me.

shruti862 avatar Dec 14 '23 13:12 shruti862

@ragesoss I would like to pick up this issue, can you assign it to me.

fillingtothemomo avatar Dec 17 '23 17:12 fillingtothemomo

We do not assign issues, but you can choose a reducer and work on it.

ragesoss avatar Dec 17 '23 20:12 ragesoss

@ragesoss I opened a PR for the correction I did. Could you please confirm if my correction meets your approval? Once confirmed, I'll proceed to begin implementing tests for reducers.

zhjiang1103 avatar Feb 08 '24 19:02 zhjiang1103