From 4f3a220487c3c8b3596e5a8de7b65cc7c4f0c981 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 8 Mar 2019 22:40:57 +0200 Subject: Since BE doesn't support fetching user by screen name over MastoAPI we'll gonna just fetching it over QvitterAPI real quick :DDDDDDDDD --- test/unit/specs/components/user_profile.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 41fd9cd0..1524c4eb 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -13,8 +13,7 @@ const mutations = { } const testGetters = { - userByName: state => getters.userByName(state.users), - userById: state => getters.userById(state.users) + findUser: state => getters.findUser(state.users) } const localUser = { -- cgit v1.2.3-70-g09d2 From f3a9200b7c17de04bbedf16cb1ac5d9681ab73f4 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sat, 9 Mar 2019 02:47:20 +0200 Subject: some test fixes, disabled one test for now since logic now is even more async in general --- test/unit/specs/components/user_profile.spec.js | 3 ++- test/unit/specs/modules/users.spec.js | 31 +++++++++---------------- 2 files changed, 13 insertions(+), 21 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 1524c4eb..23e5ce20 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -160,7 +160,8 @@ const localProfileStore = new Vuex.Store({ } }) -describe('UserProfile', () => { +// It's a little bit more complicated now +describe.skip('UserProfile', () => { it('renders external profile', () => { const wrapper = mount(UserProfile, { localVue, diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index dae7e580..a7f18dce 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -34,36 +34,27 @@ describe('The users module', () => { }) }) - describe('getUserByName', () => { + describe('findUser', () => { it('returns user with matching screen_name', () => { + const user = { screen_name: 'Guy', id: '1' } const state = { - users: [ - { screen_name: 'Guy', id: '1' } - ] + usersObject: { + 1: user, + Guy: user + } } const name = 'Guy' const expected = { screen_name: 'Guy', id: '1' } expect(getters.findUser(state)(name)).to.eql(expected) }) - it('returns user with matching screen_name with different case', () => { - const state = { - users: [ - { screen_name: 'guy', id: '1' } - ] - } - const name = 'Guy' - const expected = { screen_name: 'guy', id: '1' } - expect(getters.findUser(state)(name)).to.eql(expected) - }) - }) - - describe('getUserById', () => { it('returns user with matching id', () => { + const user = { screen_name: 'Guy', id: '1' } const state = { - users: [ - { screen_name: 'Guy', id: '1' } - ] + usersObject: { + 1: user, + Guy: user + } } const id = '1' const expected = { screen_name: 'Guy', id: '1' } -- cgit v1.2.3-70-g09d2 From 06d39b62a8358c911b18f5acc378047035840465 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 11 Mar 2019 02:17:49 +0200 Subject: fixed tests, review fixes, now storing local users with downcase screen name for better compatibility --- src/components/user_profile/user_profile.js | 7 ++++--- src/modules/statuses.js | 2 +- src/modules/users.js | 4 ++-- test/unit/specs/components/user_profile.spec.js | 14 ++++++++++---- test/unit/specs/modules/users.spec.js | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) (limited to 'test/unit/specs/components') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 2d186bc5..a8dfce2f 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -68,7 +68,7 @@ const UserProfile = { }, userInStore () { const routeParams = this.$route.params - return this.$store.getters.findUser(routeParams.name || routeParams.iid) + return this.$store.getters.findUser(routeParams.name || routeParams.id) }, user () { if (this.timeline.statuses[0]) { @@ -135,13 +135,14 @@ const UserProfile = { } }, watch: { - userId (newVal, oldVal) { + // userId can be undefined if we don't know it yet + userId (newVal) { if (newVal) { this.cleanUp() this.startUp() } }, - userName (newVal, oldVal) { + userName () { if (this.$route.params.name) { this.fetchUserId() this.cleanUp() diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 2b0215f0..ea1b2de0 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -73,7 +73,7 @@ const mergeOrAdd = (arr, obj, item) => { if (oldItem) { // We already have this, so only merge the new info. // We ignore null values to avoid overwriting existing properties with missing data - // we also skip 'used' because that is handled by users module + // we also skip 'user' because that is handled by users module merge(oldItem, omitBy(item, (v, k) => v === null || k === 'user')) // Reactivity fix. oldItem.attachments.splice(oldItem.attachments.length) diff --git a/src/modules/users.js b/src/modules/users.js index e4146c31..5eabb1ec 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -18,7 +18,7 @@ export const mergeOrAdd = (arr, obj, item) => { arr.push(item) obj[item.id] = item if (item.screen_name && !item.screen_name.includes('@')) { - obj[item.screen_name] = item + obj[item.screen_name.toLowerCase()] = item } return { item, new: true } } @@ -132,7 +132,7 @@ export const mutations = { } export const getters = { - findUser: state => query => state.usersObject[query] + findUser: state => query => state.usersObject[typeof query === 'string' ? query.toLowerCase() : query] } export const defaultState = { diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 23e5ce20..847481f3 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -12,6 +12,11 @@ const mutations = { setError: () => {} } +const actions = { + fetchUser: () => {}, + fetchUserByScreenName: () => {} +} + const testGetters = { findUser: state => getters.findUser(state.users) } @@ -30,6 +35,7 @@ const extUser = { const externalProfileStore = new Vuex.Store({ mutations, + actions, getters: testGetters, state: { api: { @@ -88,7 +94,7 @@ const externalProfileStore = new Vuex.Store({ currentUser: { credentials: '' }, - usersObject: [extUser], + usersObject: { 100: extUser }, users: [extUser] } } @@ -96,6 +102,7 @@ const externalProfileStore = new Vuex.Store({ const localProfileStore = new Vuex.Store({ mutations, + actions, getters: testGetters, state: { api: { @@ -154,14 +161,13 @@ const localProfileStore = new Vuex.Store({ currentUser: { credentials: '' }, - usersObject: [localUser], + usersObject: { 100: localUser, 'testuser': localUser }, users: [localUser] } } }) -// It's a little bit more complicated now -describe.skip('UserProfile', () => { +describe('UserProfile', () => { it('renders external profile', () => { const wrapper = mount(UserProfile, { localVue, diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index a7f18dce..c8bc0ae7 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -40,7 +40,7 @@ describe('The users module', () => { const state = { usersObject: { 1: user, - Guy: user + guy: user } } const name = 'Guy' @@ -53,7 +53,7 @@ describe('The users module', () => { const state = { usersObject: { 1: user, - Guy: user + guy: user } } const id = '1' -- cgit v1.2.3-70-g09d2 From 3e685149816d3b0bd7a8a25030ed448d1b51bbb5 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 28 Apr 2019 20:46:01 +0300 Subject: fix tests --- test/unit/specs/components/user_profile.spec.js | 2 ++ yarn.lock | 16 ---------------- 2 files changed, 2 insertions(+), 16 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 847481f3..6de9491a 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -39,6 +39,7 @@ const externalProfileStore = new Vuex.Store({ getters: testGetters, state: { api: { + fetchers: {}, backendInteractor: backendInteractorService('') }, interface: { @@ -106,6 +107,7 @@ const localProfileStore = new Vuex.Store({ getters: testGetters, state: { api: { + fetchers: {}, backendInteractor: backendInteractorService('') }, interface: { diff --git a/yarn.lock b/yarn.lock index 489bd9f3..cfc600c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8120,13 +8120,6 @@ vue-chat-scroll@^1.2.1: resolved "https://registry.yarnpkg.com/vue-chat-scroll/-/vue-chat-scroll-1.3.5.tgz#a5ee5bae5058f614818a96eac5ee3be4394a2f68" integrity sha512-bOBIv3AQp9D+YkhUBwVG4vBblRTeAtqQqx3Agl8fHNNm33aHMWB74U1m45Ll+JI3B0xfyWw6htJ2o5qoiFX9ZQ== -vue-compose@^0.7.1: - version "0.7.1" - resolved "https://registry.yarnpkg.com/vue-compose/-/vue-compose-0.7.1.tgz#1c11c4cd5e2c8f2743b03fce8ab43d78aabc20b3" - integrity sha512-OAObuO3n0qH5sSupLxrNxdkRNz8p+CiIBcsczp5x8QofnoWrEiluVIsW1xwIbW7aTcnDvkDSGlrlXQn6E3xqDw== - dependencies: - vue-hoc "0.x.x" - vue-eslint-parser@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-5.0.0.tgz#00f4e4da94ec974b821a26ff0ed0f7a78402b8a1" @@ -8139,20 +8132,11 @@ vue-eslint-parser@^5.0.0: esquery "^1.0.1" lodash "^4.17.11" -vue-hoc@0.x.x: - version "0.4.7" - resolved "https://registry.yarnpkg.com/vue-hoc/-/vue-hoc-0.4.7.tgz#4d3322ba89b8b0e42b19045ef536c21d948a4fac" - integrity sha512-bFHE7mf1bBBQSYg36Zg3ON0BawtRSxhiVS2wkDXq4LldSyBoH84WmfR+JijYenICiZTv81dbrYVFTf8S/FT1aQ== - vue-hot-reload-api@^2.2.0: version "2.3.3" resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.3.tgz#2756f46cb3258054c5f4723de8ae7e87302a1ccf" integrity sha512-KmvZVtmM26BQOMK1rwUZsrqxEGeKiYSZGA7SNWE6uExx8UX/cj9hq2MRV/wWC3Cq6AoeDGk57rL9YMFRel/q+g== -vue-hot-reload-api@^2.0.11: - version "2.3.1" - resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.1.tgz#b2d3d95402a811602380783ea4f566eb875569a2" - vue-i18n@^7.3.2: version "7.8.1" resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-7.8.1.tgz#2ce4b6efde679a1e05ddb5d907bfc1bc218803b2" -- cgit v1.2.3-70-g09d2 From 65ef03931661561db0791ee7d560292dda6b7d48 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 08:03:41 -0400 Subject: add unit test for elimination logic --- src/components/timeline/timeline.js | 28 +++++++++++++++++----------- test/unit/specs/components/timeline.spec.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 test/unit/specs/components/timeline.spec.js (limited to 'test/unit/specs/components') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index a5c6418b..aac3869f 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -1,7 +1,20 @@ import Status from '../status/status.vue' import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js' import Conversation from '../conversation/conversation.vue' -import { throttle } from 'lodash' +import { throttle, keyBy } from 'lodash' + +export const getExcludedStatusIdsByPinning = (statuses, pinnedStatusIds) => { + const ids = [] + if (pinnedStatusIds && pinnedStatusIds.length > 0) { + for (let status of statuses) { + if (!pinnedStatusIds.includes(status.id)) { + break + } + ids.push(status.id) + } + } + return ids +} const Timeline = { props: [ @@ -43,16 +56,9 @@ const Timeline = { }, // id map of statuses which need to be hidden in the main list due to pinning logic excludedStatusIdsObject () { - const result = {} - if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { - for (let status of this.timeline.visibleStatuses) { - if (!this.pinnedStatusIds.includes(status.id)) { - break - } - result[status.id] = true - } - } - return result + const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds) + // Convert id array to object + return keyBy(ids, id => id) } }, components: { diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js new file mode 100644 index 00000000..b13d3e20 --- /dev/null +++ b/test/unit/specs/components/timeline.spec.js @@ -0,0 +1,17 @@ +import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' +import { difference } from 'lodash' + +describe('Timeline', () => { + describe('getExcludedStatusIdsByPinning', () => { + it('should not return unpinned status ids', () => { + const statuses = [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + { id: 4 } + ] + const pinnedStatusIds = [1, 3] + expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) + }) + }) +}) \ No newline at end of file -- cgit v1.2.3-70-g09d2 From a443a5203e19eb43cdff76b1e3e6502a5b917bc9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 14:17:48 -0400 Subject: add more unit tests for elimination logic --- test/unit/specs/components/timeline.spec.js | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index b13d3e20..48796cd3 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -3,15 +3,28 @@ import { difference } from 'lodash' describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { - it('should not return unpinned status ids', () => { - const statuses = [ - { id: 1 }, - { id: 2 }, - { id: 3 }, - { id: 4 } - ] - const pinnedStatusIds = [1, 3] + const mockStatuses = (ids) => ids.map(id => ({ id })) + + it('should not return any unpinned status ids', () => { + const statuses = mockStatuses([1, 2, 3, 4]) + const pinnedStatusIds = [1, 3, 5] expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) }) + + it('should not return any status ids not listed in the given statuses', () => { + const statusIds = [1, 2, 3, 4] + const statuses = mockStatuses(statusIds) + const pinnedStatusIds = [1, 3, 5] + expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), statusIds)).to.eql([]) + }) + + it('should return ids of pinned statuses not posted before any unpinned status', () => { + const pinnedStatusIdSet1 = ['PINNED1', 'PINNED2'] + const pinnedStatusIdSet2 = ['PINNED3', 'PINNED4'] + const pinnedStatusIds = [...pinnedStatusIdSet1, ...pinnedStatusIdSet2] + const statusIds = [...pinnedStatusIdSet1, 'UNPINNED1', ...pinnedStatusIdSet2] + const statuses = mockStatuses(statusIds) + expect(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)).to.eql(pinnedStatusIdSet1) + }) }) -}) \ No newline at end of file +}) -- cgit v1.2.3-70-g09d2 From d785ed5a05b3123d95e8627a0f82f0f9cddec33f Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 23:34:56 -0400 Subject: rewrite unit tests --- test/unit/specs/components/timeline.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index 48796cd3..c1fdd0dd 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -1,5 +1,4 @@ import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' -import { difference } from 'lodash' describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { @@ -8,14 +7,14 @@ describe('Timeline', () => { it('should not return any unpinned status ids', () => { const statuses = mockStatuses([1, 2, 3, 4]) const pinnedStatusIds = [1, 3, 5] - expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) + expect(pinnedStatusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) }) it('should not return any status ids not listed in the given statuses', () => { const statusIds = [1, 2, 3, 4] const statuses = mockStatuses(statusIds) const pinnedStatusIds = [1, 3, 5] - expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), statusIds)).to.eql([]) + expect(statusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) }) it('should return ids of pinned statuses not posted before any unpinned status', () => { -- cgit v1.2.3-70-g09d2 From 18a41e785ed85531f032a0aa1b6bfdce5a892fa9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 28 Jul 2019 16:55:34 -0400 Subject: update unit test --- test/unit/specs/components/timeline.spec.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index c1fdd0dd..0c8674a8 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -4,17 +4,15 @@ describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { const mockStatuses = (ids) => ids.map(id => ({ id })) - it('should not return any unpinned status ids', () => { - const statuses = mockStatuses([1, 2, 3, 4]) - const pinnedStatusIds = [1, 3, 5] - expect(pinnedStatusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) - }) - - it('should not return any status ids not listed in the given statuses', () => { + it('should return only members of both pinnedStatusIds and ids of the given statuses', () => { const statusIds = [1, 2, 3, 4] const statuses = mockStatuses(statusIds) const pinnedStatusIds = [1, 3, 5] - expect(statusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) + const result = getExcludedStatusIdsByPinning(statuses, pinnedStatusIds) + result.forEach(item => { + expect(item).to.be.oneOf(statusIds) + expect(item).to.be.oneOf(pinnedStatusIds) + }) }) it('should return ids of pinned statuses not posted before any unpinned status', () => { -- cgit v1.2.3-70-g09d2 From db961af3c8ee11823a4b33c3127635c280996183 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 15 Sep 2019 16:01:57 +0300 Subject: unit test for emoji input, for now covering only insertion mechanism --- test/unit/specs/components/emoji_input.spec.js | 122 +++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 test/unit/specs/components/emoji_input.spec.js (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js new file mode 100644 index 00000000..5f24331a --- /dev/null +++ b/test/unit/specs/components/emoji_input.spec.js @@ -0,0 +1,122 @@ +import { shallowMount, createLocalVue } from '@vue/test-utils' +import EmojiInput from 'src/components/emoji_input/emoji_input.vue' + +const generateInput = (value) => { + const localVue = createLocalVue() + localVue.directive('click-outside', () => {}) + const wrapper = shallowMount(EmojiInput, { + propsData: { + suggest: () => [], + enableEmojiPicker: true, + value + }, + slots: { + default: '' + }, + localVue + }) + return [wrapper, localVue] +} + +describe('EmojiInput', () => { + describe('insertion mechanism', () => { + it('inserts string at the end with trailing space', () => { + const initialString = 'Testing' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: initialString.length }) + wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + expect(wrapper.emitted().input[0][0]).to.eql('Testing (test) ') + }) + + it('inserts string at the end with trailing space (source has a trailing space)', () => { + const initialString = 'Testing ' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: initialString.length }) + wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + expect(wrapper.emitted().input[0][0]).to.eql('Testing (test) ') + }) + + it('inserts string at the begginning without leading space', () => { + const initialString = 'Testing' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: 0 }) + wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + expect(wrapper.emitted().input[0][0]).to.eql('(test) Testing') + }) + + it('inserts string between words without creating extra spaces', () => { + const initialString = 'Spurdo Sparde' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: 6 }) + wrapper.vm.insert({ insertion: ':ebin:', spamMode: false }) + expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') + }) + + it('inserts string between words without creating extra spaces (other caret)', () => { + const initialString = 'Spurdo Sparde' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: 7 }) + wrapper.vm.insert({ insertion: ':ebin:', spamMode: false }) + expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') + }) + + it('inserts string without any padding in spam mode', () => { + const initialString = 'Eat some spam!' + const [wrapper] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: initialString.length }) + wrapper.vm.insert({ insertion: ':spam:', spamMode: true }) + expect(wrapper.emitted().input[0][0]).to.eql('Eat some spam!:spam:') + }) + + it('correctly sets caret after insertion at beginning', (done) => { + const initialString = '1234' + const [wrapper, vue] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: 0 }) + wrapper.vm.insert({ insertion: '1234', spamMode: false }) + vue.nextTick(() => { + expect(wrapper.vm.caret).to.eql(5) + done() + }) + }) + + it('correctly sets caret after insertion at end', (done) => { + const initialString = '1234' + const [wrapper, vue] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: initialString.length }) + wrapper.vm.insert({ insertion: '1234', spamMode: false }) + vue.nextTick(() => { + expect(wrapper.vm.caret).to.eql(10) + done() + }) + }) + + it('correctly sets caret after insertion in spam mode', (done) => { + const initialString = '1234' + const [wrapper, vue] = generateInput(initialString) + const input = wrapper.find('input') + input.setValue(initialString) + wrapper.setData({ caret: initialString.length }) + wrapper.vm.insert({ insertion: '1234', spamMode: true }) + vue.nextTick(() => { + expect(wrapper.vm.caret).to.eql(8) + done() + }) + }) + }) +}) -- cgit v1.2.3-70-g09d2 From 7b4cb387345c0e278a6cfe5bbff5265c09281567 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 23 Sep 2019 20:29:01 +0300 Subject: split spam mode into two separate options (one in settings page) --- src/components/emoji_input/emoji_input.js | 15 +++++++++------ src/components/emoji_picker/emoji_picker.js | 4 ++-- src/components/emoji_picker/emoji_picker.scss | 4 ++-- src/components/emoji_picker/emoji_picker.vue | 12 ++++++------ src/components/settings/settings.js | 4 ++++ src/components/settings/settings.vue | 8 ++++++++ src/i18n/en.json | 3 ++- src/modules/config.js | 1 + test/unit/specs/components/emoji_input.spec.js | 18 +++++++++--------- 9 files changed, 43 insertions(+), 26 deletions(-) (limited to 'test/unit/specs/components') diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index 86ff9707..5f90d7f4 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -89,7 +89,7 @@ const EmojiInput = { blurTimeout: null, showPicker: false, temporarilyHideSuggestions: false, - spamMode: false, + keepOpen: false, disableClickOutside: false } }, @@ -97,6 +97,9 @@ const EmojiInput = { EmojiPicker }, computed: { + padEmoji () { + return this.$store.state.config.padEmoji + }, suggestions () { const firstchar = this.textAtCaret.charAt(0) if (this.textAtCaret === firstchar) { return [] } @@ -176,7 +179,7 @@ const EmojiInput = { this.$emit('input', newValue) this.caret = 0 }, - insert ({ insertion, spamMode }) { + insert ({ insertion, keepOpen }) { const before = this.value.substring(0, this.caret) || '' const after = this.value.substring(this.caret) || '' @@ -195,8 +198,8 @@ const EmojiInput = { * them, masto seem to be rendering :emoji::emoji: correctly now so why not */ const isSpaceRegex = /\s/ - const spaceBefore = !isSpaceRegex.exec(before.slice(-1)) && before.length && !spamMode > 0 ? ' ' : '' - const spaceAfter = !isSpaceRegex.exec(after[0]) && !spamMode ? ' ' : '' + const spaceBefore = !isSpaceRegex.exec(before.slice(-1)) && before.length && this.padEmoji > 0 ? ' ' : '' + const spaceAfter = !isSpaceRegex.exec(after[0]) && this.padEmoji ? ' ' : '' const newValue = [ before, @@ -205,7 +208,7 @@ const EmojiInput = { spaceAfter, after ].join('') - this.spamMode = spamMode + this.keepOpen = keepOpen this.$emit('input', newValue) const position = this.caret + (insertion + spaceAfter + spaceBefore).length @@ -283,7 +286,7 @@ const EmojiInput = { this.blurTimeout = null } - if (!this.spamMode) { + if (!this.keepOpen) { this.showPicker = false } this.focused = true diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js index cb93f0c1..824412dd 100644 --- a/src/components/emoji_picker/emoji_picker.js +++ b/src/components/emoji_picker/emoji_picker.js @@ -18,7 +18,7 @@ const EmojiPicker = { activeGroup: 'custom', showingStickers: false, groupsScrolledClass: 'scrolled-top', - spamMode: false + keepOpen: false } }, components: { @@ -27,7 +27,7 @@ const EmojiPicker = { methods: { onEmoji (emoji) { const value = emoji.imageUrl ? `:${emoji.displayText}:` : emoji.replacement - this.$emit('emoji', { insertion: value, spamMode: this.spamMode }) + this.$emit('emoji', { insertion: value, keepOpen: this.keepOpen }) }, highlight (key) { const ref = this.$refs['group-' + key] diff --git a/src/components/emoji_picker/emoji_picker.scss b/src/components/emoji_picker/emoji_picker.scss index 09438898..b0ed00e9 100644 --- a/src/components/emoji_picker/emoji_picker.scss +++ b/src/components/emoji_picker/emoji_picker.scss @@ -10,11 +10,11 @@ margin: 0 !important; z-index: 1; - .spam-mode { + .keep-open { padding: 7px; line-height: normal; } - .spam-mode-label { + .keep-open-label { padding: 0 7px; display: flex; } diff --git a/src/components/emoji_picker/emoji_picker.vue b/src/components/emoji_picker/emoji_picker.vue index b32d0862..6c43dd97 100644 --- a/src/components/emoji_picker/emoji_picker.vue +++ b/src/components/emoji_picker/emoji_picker.vue @@ -76,16 +76,16 @@
-
diff --git a/src/i18n/en.json b/src/i18n/en.json index 7676e7a8..20d4ed22 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -109,7 +109,7 @@ "emoji": { "stickers": "Stickers", "emoji": "Emoji", - "spam": "Keep picker open, don't separate emoji with spaces", + "keep_open": "Keep picker open", "search_emoji": "Search for an emoji", "add_emoji": "Insert emoji", "custom": "Custom emoji", @@ -232,6 +232,7 @@ "delete_account_error": "There was an issue deleting your account. If this persists please contact your instance administrator.", "delete_account_instructions": "Type your password in the input below to confirm account deletion.", "avatar_size_instruction": "The recommended minimum size for avatar images is 150x150 pixels.", + "pad_emoji": "Pad emoji with spaces when adding from picker", "export_theme": "Save preset", "filtering": "Filtering", "filtering_explanation": "All statuses containing these words will be muted, one per line", diff --git a/src/modules/config.js b/src/modules/config.js index 2bfad8f6..cf04d14f 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -7,6 +7,7 @@ const defaultState = { colors: {}, hideMutedPosts: undefined, // instance default collapseMessageWithSubject: undefined, // instance default + padEmoji: true, hideAttachments: false, hideAttachmentsInConv: false, maxThumbnails: 16, diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js index 5f24331a..13a59961 100644 --- a/test/unit/specs/components/emoji_input.spec.js +++ b/test/unit/specs/components/emoji_input.spec.js @@ -26,7 +26,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + wrapper.vm.insert({ insertion: '(test)', keepOpen: false }) expect(wrapper.emitted().input[0][0]).to.eql('Testing (test) ') }) @@ -36,7 +36,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + wrapper.vm.insert({ insertion: '(test)', keepOpen: false }) expect(wrapper.emitted().input[0][0]).to.eql('Testing (test) ') }) @@ -46,7 +46,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: 0 }) - wrapper.vm.insert({ insertion: '(test)', spamMode: false }) + wrapper.vm.insert({ insertion: '(test)', keepOpen: false }) expect(wrapper.emitted().input[0][0]).to.eql('(test) Testing') }) @@ -56,7 +56,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: 6 }) - wrapper.vm.insert({ insertion: ':ebin:', spamMode: false }) + wrapper.vm.insert({ insertion: ':ebin:', keepOpen: false }) expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') }) @@ -66,7 +66,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: 7 }) - wrapper.vm.insert({ insertion: ':ebin:', spamMode: false }) + wrapper.vm.insert({ insertion: ':ebin:', keepOpen: false }) expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') }) @@ -76,7 +76,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: ':spam:', spamMode: true }) + wrapper.vm.insert({ insertion: ':spam:', keepOpen: true }) expect(wrapper.emitted().input[0][0]).to.eql('Eat some spam!:spam:') }) @@ -86,7 +86,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: 0 }) - wrapper.vm.insert({ insertion: '1234', spamMode: false }) + wrapper.vm.insert({ insertion: '1234', keepOpen: false }) vue.nextTick(() => { expect(wrapper.vm.caret).to.eql(5) done() @@ -99,7 +99,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: '1234', spamMode: false }) + wrapper.vm.insert({ insertion: '1234', keepOpen: false }) vue.nextTick(() => { expect(wrapper.vm.caret).to.eql(10) done() @@ -112,7 +112,7 @@ describe('EmojiInput', () => { const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: '1234', spamMode: true }) + wrapper.vm.insert({ insertion: '1234', keepOpen: true }) vue.nextTick(() => { expect(wrapper.vm.caret).to.eql(8) done() -- cgit v1.2.3-70-g09d2 From 836cb817d18f5e3ee6dab446633b8e05733c2a3a Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 25 Sep 2019 20:54:07 +0300 Subject: fix tests --- test/unit/specs/components/emoji_input.spec.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'test/unit/specs/components') diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js index 13a59961..368d623d 100644 --- a/test/unit/specs/components/emoji_input.spec.js +++ b/test/unit/specs/components/emoji_input.spec.js @@ -1,7 +1,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils' import EmojiInput from 'src/components/emoji_input/emoji_input.vue' -const generateInput = (value) => { +const generateInput = (value, padEmoji = true) => { const localVue = createLocalVue() localVue.directive('click-outside', () => {}) const wrapper = shallowMount(EmojiInput, { @@ -10,6 +10,15 @@ const generateInput = (value) => { enableEmojiPicker: true, value }, + mocks: { + $store: { + state: { + config: { + padEmoji + } + } + } + }, slots: { default: '' }, @@ -70,13 +79,13 @@ describe('EmojiInput', () => { expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') }) - it('inserts string without any padding in spam mode', () => { + it('inserts string without any padding if padEmoji setting is set to false', () => { const initialString = 'Eat some spam!' - const [wrapper] = generateInput(initialString) + const [wrapper] = generateInput(initialString, false) const input = wrapper.find('input') input.setValue(initialString) - wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: ':spam:', keepOpen: true }) + wrapper.setData({ caret: initialString.length, keepOpen: false }) + wrapper.vm.insert({ insertion: ':spam:' }) expect(wrapper.emitted().input[0][0]).to.eql('Eat some spam!:spam:') }) @@ -106,13 +115,13 @@ describe('EmojiInput', () => { }) }) - it('correctly sets caret after insertion in spam mode', (done) => { + it('correctly sets caret after insertion if padEmoji setting is set to false', (done) => { const initialString = '1234' - const [wrapper, vue] = generateInput(initialString) + const [wrapper, vue] = generateInput(initialString, false) const input = wrapper.find('input') input.setValue(initialString) wrapper.setData({ caret: initialString.length }) - wrapper.vm.insert({ insertion: '1234', keepOpen: true }) + wrapper.vm.insert({ insertion: '1234', keepOpen: false }) vue.nextTick(() => { expect(wrapper.vm.caret).to.eql(8) done() -- cgit v1.2.3-70-g09d2 From 0be86304d24a5f11a64e9120c8ae1ce9121e64e8 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 6 Oct 2019 23:28:30 +0300 Subject: Fix tests, more replacing with mergedConfig --- src/App.js | 4 ++-- src/components/attachment/attachment.js | 8 ++++---- src/components/emoji_input/emoji_input.js | 2 +- src/components/gallery/gallery.js | 2 +- .../interface_language_switcher.vue | 2 +- src/components/mobile_nav/mobile_nav.js | 2 +- .../mobile_post_status_button.js | 2 +- src/components/notification/notification.js | 2 +- src/components/post_status_form/post_status_form.js | 2 +- src/components/settings/settings.js | 2 +- src/components/still-image/still-image.js | 2 +- src/components/style_switcher/style_switcher.js | 8 ++++---- src/components/timeline/timeline.js | 6 +++--- src/components/user_card/user_card.js | 12 ++++++------ src/components/video_attachment/video_attachment.js | 8 ++++---- .../notifications_fetcher.service.js | 5 ++--- .../timeline_fetcher/timeline_fetcher.service.js | 16 ++++++++++++---- test/unit/specs/components/emoji_input.spec.js | 4 ++-- test/unit/specs/components/user_profile.spec.js | 16 ++++++++-------- 19 files changed, 56 insertions(+), 49 deletions(-) (limited to 'test/unit/specs/components') diff --git a/src/App.js b/src/App.js index fe63b54c..04a40e30 100644 --- a/src/App.js +++ b/src/App.js @@ -45,7 +45,7 @@ export default { }), created () { // Load the locale from the storage - this.$i18n.locale = this.$store.state.config.interfaceLanguage + this.$i18n.locale = this.$store.getters.mergedConfig.interfaceLanguage window.addEventListener('resize', this.updateMobileState) }, destroyed () { @@ -93,7 +93,7 @@ export default { suggestionsEnabled () { return this.$store.state.instance.suggestionsEnabled }, showInstanceSpecificPanel () { return this.$store.state.instance.showInstanceSpecificPanel && - !this.$store.state.config.hideISP && + !this.$store.getters.mergedConfig.hideISP && this.$store.state.instance.instanceSpecificPanelContent }, showFeaturesPanel () { return this.$store.state.instance.showFeaturesPanel }, diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index e93921fe..21cd0351 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -15,8 +15,8 @@ const Attachment = { data () { return { nsfwImage: this.$store.state.instance.nsfwCensorImage || nsfwImage, - hideNsfwLocal: this.$store.state.config.hideNsfw, - preloadImage: this.$store.state.config.preloadImage, + hideNsfwLocal: this.$store.getters.mergedConfig.hideNsfw, + preloadImage: this.$store.getters.mergedConfig.preloadImage, loading: false, img: fileTypeService.fileType(this.attachment.mimetype) === 'image' && document.createElement('img'), modalOpen: false, @@ -57,7 +57,7 @@ const Attachment = { } }, openModal (event) { - const modalTypes = this.$store.state.config.playVideosInModal + const modalTypes = this.$store.getters.mergedConfig.playVideosInModal ? ['image', 'video'] : ['image'] if (fileTypeService.fileMatchesSomeType(modalTypes, this.attachment) || @@ -70,7 +70,7 @@ const Attachment = { } }, toggleHidden (event) { - if (this.$store.state.config.useOneClickNsfw && !this.showHidden) { + if (this.$store.getters.mergedConfig.useOneClickNsfw && !this.showHidden) { this.openModal(event) return } diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index a586b819..366951c0 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -99,7 +99,7 @@ const EmojiInput = { }, computed: { padEmoji () { - return this.$store.state.config.padEmoji + return this.$store.getters.mergedConfig.padEmoji }, suggestions () { const firstchar = this.textAtCaret.charAt(0) diff --git a/src/components/gallery/gallery.js b/src/components/gallery/gallery.js index 7f33a81b..96ac1b93 100644 --- a/src/components/gallery/gallery.js +++ b/src/components/gallery/gallery.js @@ -37,7 +37,7 @@ const Gallery = { return itemsPerRow => ({ 'height': `${(this.width / (itemsPerRow + 0.6))}px` }) }, useContainFit () { - return this.$store.state.config.useContainFit + return this.$store.getters.mergedConfig.useContainFit } }, methods: { diff --git a/src/components/interface_language_switcher/interface_language_switcher.vue b/src/components/interface_language_switcher/interface_language_switcher.vue index 83df9a0b..1ca22001 100644 --- a/src/components/interface_language_switcher/interface_language_switcher.vue +++ b/src/components/interface_language_switcher/interface_language_switcher.vue @@ -40,7 +40,7 @@ export default { }, language: { - get: function () { return this.$store.state.config.interfaceLanguage }, + get: function () { return this.$store.getters.mergedConfig.interfaceLanguage }, set: function (val) { this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val }) this.$i18n.locale = val diff --git a/src/components/mobile_nav/mobile_nav.js b/src/components/mobile_nav/mobile_nav.js index c2bb76ee..5a90c31f 100644 --- a/src/components/mobile_nav/mobile_nav.js +++ b/src/components/mobile_nav/mobile_nav.js @@ -63,7 +63,7 @@ const MobileNav = { this.$refs.notifications.markAsSeen() }, onScroll ({ target: { scrollTop, clientHeight, scrollHeight } }) { - if (this.$store.state.config.autoLoad && scrollTop + clientHeight >= scrollHeight) { + if (this.$store.getters.mergedConfig.autoLoad && scrollTop + clientHeight >= scrollHeight) { this.$refs.notifications.fetchOlderNotifications() } } diff --git a/src/components/mobile_post_status_button/mobile_post_status_button.js b/src/components/mobile_post_status_button/mobile_post_status_button.js index 3e77148a..0ad12bb1 100644 --- a/src/components/mobile_post_status_button/mobile_post_status_button.js +++ b/src/components/mobile_post_status_button/mobile_post_status_button.js @@ -30,7 +30,7 @@ const MobilePostStatusButton = { return this.autohideFloatingPostButton && (this.hidden || this.inputActive) }, autohideFloatingPostButton () { - return !!this.$store.state.config.autohideFloatingPostButton + return !!this.$store.getters.mergedConfig.autohideFloatingPostButton } }, watch: { diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 8e817f3b..7d46eb5a 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -39,7 +39,7 @@ const Notification = { return highlightClass(this.notification.from_profile) }, userStyle () { - const highlight = this.$store.state.config.highlight + const highlight = this.$store.getters.mergedConfig.highlight const user = this.notification.from_profile return highlightStyle(highlight[user.screen_name]) }, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 46afc79c..db501dc1 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -152,7 +152,7 @@ const PostStatusForm = { this.$store.state.instance.pollLimits.max_options >= 2 }, hideScopeNotice () { - return this.$store.state.config.hideScopeNotice + return this.$store.getters.mergedConfig.hideScopeNotice }, pollContentError () { return this.pollFormVisible && diff --git a/src/components/settings/settings.js b/src/components/settings/settings.js index a327ab28..98ceb164 100644 --- a/src/components/settings/settings.js +++ b/src/components/settings/settings.js @@ -99,7 +99,7 @@ const settings = { handler (value) { this.$store.dispatch('setOption', { name: 'notificationVisibility', - value: this.$store.state.config.notificationVisibility + value: this.$store.getters.mergedConfig.notificationVisibility }) }, deep: true diff --git a/src/components/still-image/still-image.js b/src/components/still-image/still-image.js index 02e98f19..a5559d5d 100644 --- a/src/components/still-image/still-image.js +++ b/src/components/still-image/still-image.js @@ -7,7 +7,7 @@ const StillImage = { ], data () { return { - stopGifs: this.$store.state.config.stopGifs + stopGifs: this.$store.getters.mergedConfig.stopGifs } }, computed: { diff --git a/src/components/style_switcher/style_switcher.js b/src/components/style_switcher/style_switcher.js index 8c3d4861..c19aaaec 100644 --- a/src/components/style_switcher/style_switcher.js +++ b/src/components/style_switcher/style_switcher.js @@ -27,7 +27,7 @@ export default { data () { return { availableStyles: [], - selected: this.$store.state.config.theme, + selected: this.$store.getters.mergedConfig.theme, previewShadows: {}, previewColors: {}, @@ -111,7 +111,7 @@ export default { }) }, mounted () { - this.normalizeLocalState(this.$store.state.config.customTheme) + this.normalizeLocalState(this.$store.getters.mergedConfig.customTheme) if (typeof this.shadowSelected === 'undefined') { this.shadowSelected = this.shadowsAvailable[0] } @@ -365,9 +365,9 @@ export default { return version >= 1 || version <= 2 }, clearAll () { - const state = this.$store.state.config.customTheme + const state = this.$store.getters.mergedConfig.customTheme const version = state.colors ? 2 : 'l1' - this.normalizeLocalState(this.$store.state.config.customTheme, version) + this.normalizeLocalState(this.$store.getters.mergedConfig.customTheme, version) }, // Clears all the extra stuff when loading V1 theme diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 0594576c..27a9a55e 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -141,7 +141,7 @@ const Timeline = { const bodyBRect = document.body.getBoundingClientRect() const height = Math.max(bodyBRect.height, -(bodyBRect.y)) if (this.timeline.loading === false && - this.$store.state.config.autoLoad && + this.$store.getters.mergedConfig.autoLoad && this.$el.offsetHeight > 0 && (window.innerHeight + window.pageYOffset) >= (height - 750)) { this.fetchOlderStatuses() @@ -153,7 +153,7 @@ const Timeline = { }, watch: { newStatusCount (count) { - if (!this.$store.state.config.streaming) { + if (!this.$store.getters.mergedConfig.streaming) { return } if (count > 0) { @@ -162,7 +162,7 @@ const Timeline = { const top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0) if (top < 15 && !this.paused && - !(this.unfocused && this.$store.state.config.pauseOnUnfocused) + !(this.unfocused && this.$store.getters.mergedConfig.pauseOnUnfocused) ) { this.showNewStatuses() } else { diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index 12f9f9e8..c84afe77 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -27,9 +27,9 @@ export default { }] }, style () { - const color = this.$store.state.config.customTheme.colors - ? this.$store.state.config.customTheme.colors.bg // v2 - : this.$store.state.config.colors.bg // v1 + const color = this.$store.getters.mergedConfig.customTheme.colors + ? this.$store.getters.mergedConfig.customTheme.colors.bg // v2 + : this.$store.getters.mergedConfig.colors.bg // v1 if (color) { const rgb = (typeof color === 'string') ? hex2rgb(color) : color @@ -61,11 +61,11 @@ export default { }, userHighlightType: { get () { - const data = this.$store.state.config.highlight[this.user.screen_name] + const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name] return (data && data.type) || 'disabled' }, set (type) { - const data = this.$store.state.config.highlight[this.user.screen_name] + const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name] if (type !== 'disabled') { this.$store.dispatch('setHighlight', { user: this.user.screen_name, color: (data && data.color) || '#FFFFFF', type }) } else { @@ -76,7 +76,7 @@ export default { }, userHighlightColor: { get () { - const data = this.$store.state.config.highlight[this.user.screen_name] + const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name] return data && data.color }, set (color) { diff --git a/src/components/video_attachment/video_attachment.js b/src/components/video_attachment/video_attachment.js index 76b19a02..f0ca7e89 100644 --- a/src/components/video_attachment/video_attachment.js +++ b/src/components/video_attachment/video_attachment.js @@ -3,7 +3,7 @@ const VideoAttachment = { props: ['attachment', 'controls'], data () { return { - loopVideo: this.$store.state.config.loopVideo + loopVideo: this.$store.getters.mergedConfig.loopVideo } }, methods: { @@ -12,16 +12,16 @@ const VideoAttachment = { if (typeof target.webkitAudioDecodedByteCount !== 'undefined') { // non-zero if video has audio track if (target.webkitAudioDecodedByteCount > 0) { - this.loopVideo = this.loopVideo && !this.$store.state.config.loopVideoSilentOnly + this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly } } else if (typeof target.mozHasAudio !== 'undefined') { // true if video has audio track if (target.mozHasAudio) { - this.loopVideo = this.loopVideo && !this.$store.state.config.loopVideoSilentOnly + this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly } } else if (typeof target.audioTracks !== 'undefined') { if (target.audioTracks.length > 0) { - this.loopVideo = this.loopVideo && !this.$store.state.config.loopVideoSilentOnly + this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly } } } diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index b6c4cf80..47008026 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -8,11 +8,10 @@ const update = ({ store, notifications, older }) => { const fetchAndUpdate = ({ store, credentials, older = false }) => { const args = { credentials } + const { getters } = store const rootState = store.rootState || store.state const timelineData = rootState.statuses.notifications - const hideMutedPosts = typeof rootState.config.hideMutedPosts === 'undefined' - ? rootState.instance.hideMutedPosts - : rootState.config.hideMutedPosts + const hideMutedPosts = getters.mergedConfig.hideMutedPosts args['withMuted'] = !hideMutedPosts diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index f72688f8..9eb30c2d 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -15,13 +15,21 @@ const update = ({ store, statuses, timeline, showImmediately, userId }) => { }) } -const fetchAndUpdate = ({ store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false, until }) => { +const fetchAndUpdate = ({ + store, + credentials, + timeline = 'friends', + older = false, + showImmediately = false, + userId = false, + tag = false, + until +}) => { const args = { timeline, credentials } const rootState = store.rootState || store.state + const { getters } = store const timelineData = rootState.statuses.timelines[camelCase(timeline)] - const hideMutedPosts = typeof rootState.config.hideMutedPosts === 'undefined' - ? rootState.instance.hideMutedPosts - : rootState.config.hideMutedPosts + const hideMutedPosts = getters.mergedConfig.hideMutedPosts if (older) { args['until'] = until || timelineData.minId diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js index 368d623d..b1b98802 100644 --- a/test/unit/specs/components/emoji_input.spec.js +++ b/test/unit/specs/components/emoji_input.spec.js @@ -12,8 +12,8 @@ const generateInput = (value, padEmoji = true) => { }, mocks: { $store: { - state: { - config: { + getters: { + mergedConfig: { padEmoji } } diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 6de9491a..1b6a47d7 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -18,7 +18,14 @@ const actions = { } const testGetters = { - findUser: state => getters.findUser(state.users) + findUser: state => getters.findUser(state.users), + mergedConfig: state => ({ + colors: '', + highlight: {}, + customTheme: { + colors: [] + } + }) } const localUser = { @@ -45,13 +52,6 @@ const externalProfileStore = new Vuex.Store({ interface: { browserSupport: '' }, - config: { - colors: '', - highlight: {}, - customTheme: { - colors: [] - } - }, instance: { hideUserStats: true }, -- cgit v1.2.3-70-g09d2