Add tests for file deletion in files reducer#3853
Add tests for file deletion in files reducer#3853aashu2006 wants to merge 3 commits intoprocessing:developfrom
Conversation
|
Taking up @clairep94 suggestion to add more test coverage to the web editor. Beginning with the file deletion logic in the files reducer. 🙂 |
There was a problem hiding this comment.
Small nits, and potentially some tests you can delete.
I think re: not using CREATE_FILE in your setup, you could do something like:
// helper function above your tests
const createTestState = (files) => {
return [...initialState(), ...files] // or whatever equivalent with push, to your preference
}
// tests
it('blah blah blah I need two extra files in addition to the initialState to start' () => {
let state = createTestState([
{
id: 'firstFile',
_id: 'firstFile,
name: 'firstFile',
content: '',
children: [],
fileType: 'file',
parentId: rootId
},
{
id: 'secondFile',
_id: 'secondFile',
name: 'secondFile',
content: '',
children: [],
fileType: 'file',
parentId: rootId
},
])
// rest of your test
})Great stuff though, thanks for doing this and it was very easy to read
Thanks for the suggestion! I refactored the tests to avoid using CREATE_FILE in setup. Instead of dispatching actions, I added a small createTestState helper to construct the reducer state directly, so the DELETE_FILE tests are now fully isolated from other reducer logic. I also consolidated a couple of redundant tests while making these changes. Let me know if you would prefer a different approach for the helper 🙂 |
|
I have made the changes based on @clairep94 feedback:
Everything is passing locally. Please let me know if anything else should be adjusted 🙂 |
Changes:
Refactored and expanded reducer tests for the DELETE_FILE action in
client/modules/IDE/reducers/files.js.Accessibility: Not applicable, this PR adds tests only and does not modify UI, markup, or styles.
I have verified that this pull request:
npm run lint)npm run test)npm run typecheck)developbranch.