From 3bb56cea6f9a42862f6f459a53f03aced759d720 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 23 Jan 2021 00:21:12 +0300 Subject: [PATCH] Add tests for users filters --- test/views/users/usersFilters.test.js | 109 +++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/test/views/users/usersFilters.test.js b/test/views/users/usersFilters.test.js index 308c12c6..493d15e2 100644 --- a/test/views/users/usersFilters.test.js +++ b/test/views/users/usersFilters.test.js @@ -41,7 +41,7 @@ describe('Filters users', () => { await flushPromises() }) - it('enables local and active filters when component is mounted, toggles local filter on button click', () => { + it('enables local and active filters when component is mounted, toggles local filter on button click', async (done) => { const wrapper = mount(Filters, { store, localVue @@ -55,5 +55,112 @@ describe('Filters users', () => { expect(actions.ToggleActorTypeFilter).toHaveBeenCalled() expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['active'], undefined) expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined) + await flushPromises() + done() + }) + + it('applies three filters', async (done) => { + const wrapper = mount(Filters, { + store, + localVue + }) + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined) + + const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${2})`) + filter1.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['external', 'active'], undefined) + expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined) + await flushPromises() + + const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${3})`) + filter2.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['external', 'need_approval'], undefined) + expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined) + await flushPromises() + + const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${1})`) + filter3.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(4, expect.anything(), ['external', 'need_approval'], undefined) + expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), ['Person'], undefined) + await flushPromises() + done() + }) + + it('removes all filters', async (done) => { + const wrapper = mount(Filters, { + store, + localVue + }) + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined) + + const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${1})`) + filter1.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['active'], undefined) + expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined) + await flushPromises() + + const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${1})`) + filter2.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), [], undefined) + expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined) + await flushPromises() + + done() + }) + + it('applies actor type filters', async (done) => { + const wrapper = mount(Filters, { + store, + localVue + }) + + const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${1})`) + filter1.trigger('click') + expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['Person'], undefined) + await flushPromises() + + const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${2})`) + filter2.trigger('click') + expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['Person', 'Service'], undefined) + await flushPromises() + + const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${3})`) + filter3.trigger('click') + expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['Person', 'Service', 'Application'], undefined) + await flushPromises() + + done() + }) + + it('applies opposite filters', async (done) => { + const wrapper = mount(Filters, { + store, + localVue + }) + + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined) + + const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${2})`) + filter1.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['local', 'deactivated'], undefined) + await flushPromises() + + const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${3})`) + filter2.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['local', 'need_approval'], undefined) + await flushPromises() + + const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${4})`) + filter3.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(4, expect.anything(), ['local', 'unconfirmed'], undefined) + await flushPromises() + + const filter4 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${2})`) + filter4.trigger('click') + expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(5, expect.anything(), ['external', 'unconfirmed'], undefined) + await flushPromises() + + + done() }) })