From 8e7eb99f1f0d8e8479b2b2758006b259f1b112dd Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 10 May 2020 18:49:11 +0300 Subject: [PATCH 01/12] Update api that fetches statuses count --- src/api/status.js | 4 ++-- src/store/modules/status.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/status.js b/src/api/status.js index fcc820e0..e3bb3fd4 100644 --- a/src/api/status.js +++ b/src/api/status.js @@ -30,10 +30,10 @@ export async function fetchStatuses({ godmode, localOnly, authHost, token, pageS }) } -export async function fetchStatusesCount(authHost, token) { +export async function fetchStatusesCount(instance, authHost, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/stats`, + url: instance ? `/api/pleroma/admin/stats?instance=${instance}` : `/api/pleroma/admin/stats`, method: 'get', headers: authHeaders(token) }) diff --git a/src/store/modules/status.js b/src/store/modules/status.js index 8847e8bf..3d853e61 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -68,13 +68,15 @@ const status = { dispatch('FetchStatusesByInstance') } }, - async FetchStatusesCount({ commit, getters }) { + async FetchStatusesCount({ commit, getters }, instance) { commit('SET_LOADING', true) - const { data } = await fetchStatusesCount(getters.authHost, getters.token) + const { data } = await fetchStatusesCount(instance, getters.authHost, getters.token) commit('SET_STATUS_VISIBILITY', data.status_visibility) commit('SET_LOADING', false) }, async FetchStatusesByInstance({ commit, getters, state, rootState }) { + const { data } = await fetchStatusesCount(state.statusesByInstance.selectedInstance, getters.authHost, getters.token) + commit('SET_STATUS_VISIBILITY', data.status_visibility) commit('SET_LOADING', true) if (state.statusesByInstance.selectedInstance === '') { commit('SET_STATUSES_BY_INSTANCE', []) From 8d1d9940c97e6fe4ebd681b9278f5603802ccbd4 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 10 May 2020 21:13:29 +0300 Subject: [PATCH 02/12] Clear state after vue instance was destroyed --- src/store/modules/status.js | 13 ++++++++++--- src/views/statuses/index.vue | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/store/modules/status.js b/src/store/modules/status.js index 3d853e61..74fb6641 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -58,6 +58,14 @@ const status = { dispatch('FetchStatusesByInstance') } }, + ClearState({ commit }) { + commit('CHANGE_SELECTED_INSTANCE', '') + commit('SET_STATUSES_BY_INSTANCE', []) + commit('CHANGE_LOCAL_CHECKBOX_VALUE', false) + commit('CHANGE_GODMODE_CHECKBOX_VALUE', false) + commit('SET_ALL_LOADED', false) + commit('CHANGE_PAGE', 1) + }, async DeleteStatus({ dispatch, getters }, { statusId, reportCurrentPage, userId, godmode, fetchStatusesByInstance }) { await deleteStatus(statusId, getters.authHost, getters.token) if (reportCurrentPage !== 0) { // called from Reports @@ -74,10 +82,9 @@ const status = { commit('SET_STATUS_VISIBILITY', data.status_visibility) commit('SET_LOADING', false) }, - async FetchStatusesByInstance({ commit, getters, state, rootState }) { - const { data } = await fetchStatusesCount(state.statusesByInstance.selectedInstance, getters.authHost, getters.token) - commit('SET_STATUS_VISIBILITY', data.status_visibility) + async FetchStatusesByInstance({ commit, dispatch, getters, state, rootState }) { commit('SET_LOADING', true) + dispatch('FetchStatusesCount', state.statusesByInstance.selectedInstance) if (state.statusesByInstance.selectedInstance === '') { commit('SET_STATUSES_BY_INSTANCE', []) } else { diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index 0d17316f..84b88a4c 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -142,6 +142,9 @@ export default { this.$store.dispatch('FetchPeers') this.$store.dispatch('FetchStatusesCount') }, + destroyed() { + this.$store.dispatch('ClearState') + }, methods: { handleFilterChange() { this.$store.dispatch('HandlePageChange', 1) From 791f576543aedb4523e45d28f4ceb90cf19f2e86 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 10 May 2020 23:12:33 +0300 Subject: [PATCH 03/12] Remove focus and hover styles for statuses count --- src/views/statuses/index.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index 84b88a4c..1e8435ed 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -178,6 +178,13 @@ export default { margin: 0 0 10px; } } +.statuses-header-container { + .el-button.is-plain:focus, .el-button.is-plain:hover { + border-color: #DCDFE6; + color: #606266; + cursor: default + } +} .checkbox-container { margin-bottom: 15px; } From fddc20600d222d2d0ccac1721ef24a5d70137066 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 11 May 2020 00:19:00 +0300 Subject: [PATCH 04/12] Update style for mobile UI --- src/views/statuses/index.vue | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index 1e8435ed..c2193363 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -8,10 +8,10 @@
- {{ $t('statuses.direct') }}: {{ statusVisibility.direct }} - {{ $t('statuses.private') }}: {{ statusVisibility.private }} - {{ $t('statuses.public') }}: {{ statusVisibility.public }} - {{ $t('statuses.unlisted') }}: {{ statusVisibility.unlisted }} + {{ $t('statuses.direct') }}: {{ statusVisibility.direct }} + {{ $t('statuses.private') }}: {{ statusVisibility.private }} + {{ $t('statuses.public') }}: {{ statusVisibility.public }} + {{ $t('statuses.unlisted') }}: {{ statusVisibility.unlisted }}
@@ -238,8 +238,26 @@ export default { .statuses-header-container { flex-direction: column; align-items: flex-start; + .el-button-group { + width: 100%; + } .el-button { padding: 10px 6.5px; + width: 50%; + } + .el-button-group>.el-button:first-child { + border-bottom-left-radius: 0; + } + .el-button-group>.el-button:not(:first-child):not(:last-child).private-button { + border-top-right-radius: 4px; + } + .el-button-group>.el-button:not(:first-child):not(:last-child).public-button { + border-bottom-left-radius: 4px; + border-top: white; + } + .el-button-group>.el-button:last-child { + border-top-right-radius: 0; + border-top: white; } .reboot-button { margin: 10px 0 0 0; From 8c2cc6cac1ea3d8bd03ed7e61d9e938feaf852cd Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 11 May 2020 00:32:54 +0300 Subject: [PATCH 05/12] Add numeral to normalize count --- src/views/statuses/index.vue | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index c2193363..1cb184c3 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -8,10 +8,18 @@
- {{ $t('statuses.direct') }}: {{ statusVisibility.direct }} - {{ $t('statuses.private') }}: {{ statusVisibility.private }} - {{ $t('statuses.public') }}: {{ statusVisibility.public }} - {{ $t('statuses.unlisted') }}: {{ statusVisibility.unlisted }} + + {{ $t('statuses.direct') }}: {{ normalizedCount(990934093) }} + + + {{ $t('statuses.private') }}: {{ normalizedCount(statusVisibility.private) }} + + + {{ $t('statuses.public') }}: {{ normalizedCount(statusVisibility.public) }} + + + {{ $t('statuses.unlisted') }}: {{ normalizedCount(statusVisibility.unlisted) }} +
@@ -61,6 +69,7 @@ import MultipleUsersMenu from '@/views/users/components/MultipleUsersMenu' import Status from '@/components/Status' import RebootButton from '@/components/RebootButton' +import numeral from 'numeral' export default { name: 'Statuses', @@ -146,6 +155,9 @@ export default { this.$store.dispatch('ClearState') }, methods: { + clearSelection() { + this.selectedUsers = [] + }, handleFilterChange() { this.$store.dispatch('HandlePageChange', 1) this.$store.dispatch('FetchStatusesByInstance') @@ -155,14 +167,14 @@ export default { this.$store.dispatch('FetchStatusesPageByInstance') }, - clearSelection() { - this.selectedUsers = [] - }, handleStatusSelection(user) { if (this.selectedUsers.find(selectedUser => user.id === selectedUser.id) !== undefined) { return } this.selectedUsers = [...this.selectedUsers, user] + }, + normalizedCount(count) { + return numeral(count).format('0a') } } } From 744872d64ab07031e125e66045b42ab59916b91b Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 11 May 2020 20:33:16 +0300 Subject: [PATCH 06/12] Fix typo --- src/views/statuses/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index 1cb184c3..3ddc3ce1 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -9,7 +9,7 @@
- {{ $t('statuses.direct') }}: {{ normalizedCount(990934093) }} + {{ $t('statuses.direct') }}: {{ normalizedCount(statusVisibility.direct) }} {{ $t('statuses.private') }}: {{ normalizedCount(statusVisibility.private) }} From 6ec7d89a916d026f5413b82f6c3564f777601e50 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 11 May 2020 21:20:52 +0300 Subject: [PATCH 07/12] Add test for running on mounted actions in Statuses --- src/api/__mocks__/peers.js | 4 +++ src/api/__mocks__/status.js | 8 ++++++ test/views/statuses/index.test.js | 41 +++++++++++++++++++++++++++++++ test/views/statuses/store.conf.js | 17 +++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/api/__mocks__/peers.js create mode 100644 test/views/statuses/index.test.js create mode 100644 test/views/statuses/store.conf.js diff --git a/src/api/__mocks__/peers.js b/src/api/__mocks__/peers.js new file mode 100644 index 00000000..da61938f --- /dev/null +++ b/src/api/__mocks__/peers.js @@ -0,0 +1,4 @@ +export async function fetchPeers(authHost, token) { + const data = ['lain.com', 'heaven.com'] + return Promise.resolve({ data }) +} diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index 0e7bc9fb..88623f33 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -5,3 +5,11 @@ export async function changeStatusScope(id, sensitive, visibility, authHost, tok export async function deleteStatus(id, authHost, token) { return Promise.resolve() } + +export async function fetchStatusesCount(instance, authHost, token) { + const data = { + 'status_visibility': + { 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 } + } + return Promise.resolve({ data }) +} diff --git a/test/views/statuses/index.test.js b/test/views/statuses/index.test.js new file mode 100644 index 00000000..d8ff6321 --- /dev/null +++ b/test/views/statuses/index.test.js @@ -0,0 +1,41 @@ +import Vuex from 'vuex' +import { mount, createLocalVue, config } from '@vue/test-utils' +import flushPromises from 'flush-promises' +import Element from 'element-ui' +import Statuses from '@/views/statuses/index' +import storeConfig from './store.conf' +import { cloneDeep } from 'lodash' + +config.mocks["$t"] = () => {} + +const localVue = createLocalVue() +localVue.use(Vuex) +localVue.use(Element) + +jest.mock('@/api/app') +jest.mock('@/api/status') +jest.mock('@/api/peers') +jest.mock('@/api/nodeInfo') + +describe('Statuses', () => { + let store + + beforeEach(() => { + store = new Vuex.Store(cloneDeep(storeConfig)) + }) + + it('fetches peers and statuses count', async (done) => { + mount(Statuses, { + store, + localVue + }) + + await flushPromises() + const statusVisibilityCount = store.state.status.statusVisibility + expect(statusVisibilityCount.direct).toEqual(4) + expect(statusVisibilityCount.private).toEqual(10) + expect(statusVisibilityCount.public).toEqual(4) + expect(statusVisibilityCount.unlisted).toEqual(10) + done() + }) +}) diff --git a/test/views/statuses/store.conf.js b/test/views/statuses/store.conf.js new file mode 100644 index 00000000..0876f9d2 --- /dev/null +++ b/test/views/statuses/store.conf.js @@ -0,0 +1,17 @@ +import app from '@/store/modules/app' +import peers from '@/store/modules/peers' +import user from '@/store/modules/user' +import settings from '@/store/modules/settings' +import status from '@/store/modules/status' +import getters from '@/store/getters' + +export default { + modules: { + app, + peers, + settings, + status, + user + }, + getters +} From 8e671ac9842618d3e34f23d03cdc83c31ca7bcf1 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 12 May 2020 03:53:57 +0300 Subject: [PATCH 08/12] Update Changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d75c63d1..19b74ca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Changed + +- Statuses count changes when an instance is selected and shows the amount of statuses from an originating instance +- Add a dialog window with a confirmation when a remove button is clicked on the Settings page + +### Fixed + +- Send `true` and `false` as booleans if they are values of single selects on the Settings page + ## [2.0.3] - 2020-04-29 ### Added From bcc1ea16ff176154443bf09f980fc9483b21c472 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 12 May 2020 22:43:15 +0300 Subject: [PATCH 09/12] Test for fetching statuses from a selected instance --- src/api/__mocks__/status.js | 47 +++++++++++++++++++++++++++---- test/views/statuses/index.test.js | 20 +++++++++++++ test/views/statuses/store.conf.js | 2 +- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index 88623f33..afb8363c 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -6,10 +6,47 @@ export async function deleteStatus(id, authHost, token) { return Promise.resolve() } -export async function fetchStatusesCount(instance, authHost, token) { - const data = { - 'status_visibility': - { 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 } - } +export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { + const data = [ + { + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + 'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.', + 'created_at': '2020-01-31T18:20:01.000Z', + 'id': '9rZIr0Jzao5Gjgfmro', + 'sensitive': false, + 'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98', + 'visibility': 'unlisted' + }, + { + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + 'content': 'the happiest man ever', + 'created_at': '2019-11-23T12:56:18.000Z', + 'id': '9pFoVfWMU3A96Rzq3k', + 'sensitive': false, + 'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25', + 'visibility': 'unlisted' + } + ] + return Promise.resolve({ data }) +} + +export async function fetchStatusesCount(instance, authHost, token) { + const data = instance === 'heaven.com' + ? { + 'status_visibility': + { 'direct': 1, 'private': 2, 'public': 3, 'unlisted': 0 } + } + : { + 'status_visibility': + { 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 } + } return Promise.resolve({ data }) } diff --git a/test/views/statuses/index.test.js b/test/views/statuses/index.test.js index d8ff6321..d83c4960 100644 --- a/test/views/statuses/index.test.js +++ b/test/views/statuses/index.test.js @@ -38,4 +38,24 @@ describe('Statuses', () => { expect(statusVisibilityCount.unlisted).toEqual(10) done() }) + + it('fetches statuses from selected instance and updates the count', async (done) => { + const wrapper = mount(Statuses, { + store, + localVue + }) + await flushPromises() + + store.dispatch('HandleFilterChange', 'heaven.com') + wrapper.vm.handleFilterChange() + await flushPromises() + const statusVisibilityCount = store.state.status.statusVisibility + + expect(statusVisibilityCount.direct).toEqual(1) + expect(statusVisibilityCount.private).toEqual(2) + expect(statusVisibilityCount.public).toEqual(3) + expect(statusVisibilityCount.unlisted).toEqual(0) + expect(store.state.status.fetchedStatuses.length).toEqual(2) + done() + }) }) diff --git a/test/views/statuses/store.conf.js b/test/views/statuses/store.conf.js index 0876f9d2..6e22b617 100644 --- a/test/views/statuses/store.conf.js +++ b/test/views/statuses/store.conf.js @@ -11,7 +11,7 @@ export default { peers, settings, status, - user + user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }} }, getters } From cb99014af53dfee9f59f163b0054f699bf013748 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 13 May 2020 01:45:34 +0300 Subject: [PATCH 10/12] Add test for pagination on Statuses page --- src/api/__mocks__/status.js | 72 ++++++++++++------- test/views/statuses/pagination.test.js | 53 ++++++++++++++ .../views/statuses/storeForPagination.conf.js | 17 +++++ 3 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 test/views/statuses/pagination.test.js create mode 100644 test/views/statuses/storeForPagination.conf.js diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index afb8363c..c8f98545 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -7,34 +7,52 @@ export async function deleteStatus(id, authHost, token) { } export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { - const data = [ - { - 'account': { - 'avatar': 'http://localhost:4000/images/avi.png', - 'display_name': 'sky', - 'url': 'http://localhost:4000/users/sky' + let data + if (pageSize === 1) { + data = page === 1 || page === 2 + ? [{ + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + 'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.', + 'created_at': '2020-01-31T18:20:01.000Z', + 'id': '9rZIr0Jzao5Gjgfmro', + 'sensitive': false, + 'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98', + 'visibility': 'unlisted' + }] + : [] + } else { + data = [ + { + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + 'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.', + 'created_at': '2020-01-31T18:20:01.000Z', + 'id': '9rZIr0Jzao5Gjgfmro', + 'sensitive': false, + 'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98', + 'visibility': 'unlisted' }, - 'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.', - 'created_at': '2020-01-31T18:20:01.000Z', - 'id': '9rZIr0Jzao5Gjgfmro', - 'sensitive': false, - 'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98', - 'visibility': 'unlisted' - }, - { - 'account': { - 'avatar': 'http://localhost:4000/images/avi.png', - 'display_name': 'sky', - 'url': 'http://localhost:4000/users/sky' - }, - 'content': 'the happiest man ever', - 'created_at': '2019-11-23T12:56:18.000Z', - 'id': '9pFoVfWMU3A96Rzq3k', - 'sensitive': false, - 'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25', - 'visibility': 'unlisted' - } - ] + { + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + 'content': 'the happiest man ever', + 'created_at': '2019-11-23T12:56:18.000Z', + 'id': '9pFoVfWMU3A96Rzq3k', + 'sensitive': false, + 'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25', + 'visibility': 'unlisted' + }] + } return Promise.resolve({ data }) } diff --git a/test/views/statuses/pagination.test.js b/test/views/statuses/pagination.test.js new file mode 100644 index 00000000..2cbfb823 --- /dev/null +++ b/test/views/statuses/pagination.test.js @@ -0,0 +1,53 @@ +import Vuex from 'vuex' +import { mount, createLocalVue, config } from '@vue/test-utils' +import flushPromises from 'flush-promises' +import Element from 'element-ui' +import Statuses from '@/views/statuses/index' +import storeConfig from './storeForPagination.conf' +import { cloneDeep } from 'lodash' + +config.mocks["$t"] = () => {} + +const localVue = createLocalVue() +localVue.use(Vuex) +localVue.use(Element) + +jest.mock('@/api/app') +jest.mock('@/api/status') +jest.mock('@/api/peers') +jest.mock('@/api/nodeInfo') + +describe('Statuses', () => { + let store + + beforeEach(() => { + store = new Vuex.Store(cloneDeep(storeConfig)) + }) + + it('pagination', async (done) => { + const wrapper = mount(Statuses, { + store, + localVue + }) + await flushPromises() + + store.dispatch('HandleFilterChange', 'heaven.com') + wrapper.vm.handleFilterChange() + await flushPromises() + + expect(store.state.status.statusesByInstance.allLoaded).toBe(false) + expect(store.state.status.statusesByInstance.page).toBe(1) + wrapper.find('.statuses-pagination button').trigger('click') + await flushPromises() + + expect(store.state.status.statusesByInstance.allLoaded).toBe(false) + expect(store.state.status.statusesByInstance.page).toBe(2) + + wrapper.find('.statuses-pagination button').trigger('click') + await flushPromises() + + expect(store.state.status.statusesByInstance.allLoaded).toBe(true) + + done() + }) +}) diff --git a/test/views/statuses/storeForPagination.conf.js b/test/views/statuses/storeForPagination.conf.js new file mode 100644 index 00000000..76747f97 --- /dev/null +++ b/test/views/statuses/storeForPagination.conf.js @@ -0,0 +1,17 @@ +import app from '@/store/modules/app' +import peers from '@/store/modules/peers' +import user from '@/store/modules/user' +import settings from '@/store/modules/settings' +import status from '@/store/modules/status' +import getters from '@/store/getters' + +export default { + modules: { + app, + peers, + settings, + status: { ...status, state: { ...status.state, statusesByInstance: { ...status.state.statusesByInstance, pageSize: 1 }}}, + user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }} + }, + getters +} From 008162c508e7b6013ae41daddff8832d54bdb539 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 13 May 2020 20:34:47 +0300 Subject: [PATCH 11/12] Tests for handling status select and clearing the state after component was destroyed --- test/views/statuses/index.test.js | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/views/statuses/index.test.js b/test/views/statuses/index.test.js index d83c4960..e6173883 100644 --- a/test/views/statuses/index.test.js +++ b/test/views/statuses/index.test.js @@ -58,4 +58,46 @@ describe('Statuses', () => { expect(store.state.status.fetchedStatuses.length).toEqual(2) done() }) + + it('handles status select', async (done) => { + const wrapper = mount(Statuses, { + store: store, + localVue + }) + await flushPromises() + + store.dispatch('HandleFilterChange', 'heaven.com') + wrapper.vm.handleFilterChange() + await flushPromises() + wrapper.find('.status-checkbox input').setChecked() + await flushPromises() + + expect(wrapper.vm.selectedUsers.length).toEqual(1) + expect(wrapper.vm.selectedUsers[0].display_name).toBe('sky') + done() + }) + + it('clear state after component was destroyed', async (done) => { + const wrapper = mount(Statuses, { + store: store, + localVue + }) + await flushPromises() + + store.dispatch('HandleFilterChange', 'heaven.com') + wrapper.vm.handleFilterChange() + await flushPromises() + wrapper.find('.status-checkbox input').setChecked() + await flushPromises() + + expect(wrapper.vm.selectedUsers.length).toEqual(1) + expect(store.state.status.statusesByInstance.selectedInstance).toBe('heaven.com') + expect(store.state.status.fetchedStatuses.length).toEqual(2) + wrapper.destroy() + + expect(wrapper.vm.selectedUsers.length).toEqual(0) + expect(store.state.status.statusesByInstance.selectedInstance).toBe('') + expect(store.state.status.fetchedStatuses.length).toEqual(0) + done() + }) }) From 861eb1680b111ca9d3844f23e8618f1d0900e4e4 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 13 May 2020 20:35:35 +0300 Subject: [PATCH 12/12] Clear selected users after vue instance was destroyed --- src/views/statuses/index.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index 3ddc3ce1..6b5c3db5 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -152,6 +152,7 @@ export default { this.$store.dispatch('FetchStatusesCount') }, destroyed() { + this.clearSelection() this.$store.dispatch('ClearState') }, methods: {