From 576ad9750be4a76df7f7cc4d7062aa4546d7f61f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 22 Apr 2020 00:07:01 +0300 Subject: make tests not fail --- test/unit/specs/components/user_profile.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 1b6a47d7..0a3f2d27 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -96,7 +96,8 @@ const externalProfileStore = new Vuex.Store({ credentials: '' }, usersObject: { 100: extUser }, - users: [extUser] + users: [extUser], + relationships: {} } } }) @@ -164,7 +165,8 @@ const localProfileStore = new Vuex.Store({ credentials: '' }, usersObject: { 100: localUser, 'testuser': localUser }, - users: [localUser] + users: [localUser], + relationships: {} } } }) -- cgit v1.2.3-70-g09d2 From cda298c8223851d50edcd2761391d4ddb8932ed1 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 23 Apr 2020 11:17:52 +0300 Subject: remove unused mutation and test for it --- src/modules/users.js | 4 ---- .../entity_normalizer/entity_normalizer.service.js | 9 --------- test/unit/specs/modules/users.spec.js | 14 -------------- 3 files changed, 27 deletions(-) (limited to 'test') diff --git a/src/modules/users.js b/src/modules/users.js index 591d4634..6b19fc97 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -83,10 +83,6 @@ const unmuteDomain = (store, domain) => { } export const mutations = { - setMuted (state, { user: { id }, muted }) { - const user = state.usersObject[id] - set(user, 'muted', muted) - }, tagUser (state, { user: { id }, tag }) { const user = state.usersObject[id] const tags = user.tags || [] diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 66a7a8b7..7237fdfc 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -73,15 +73,6 @@ export const parseUser = (data) => { output.background_image = data.pleroma.background_image output.token = data.pleroma.chat_token - if (relationship && !relationship) { - output.follows_you = relationship.followed_by - output.requested = relationship.requested - output.following = relationship.following - output.statusnet_blocking = relationship.blocking - output.muted = relationship.muting - output.showing_reblogs = relationship.showing_reblogs - output.subscribed = relationship.subscribing - } if (relationship) { output.relationship = relationship } diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index eeb7afef..670acfc8 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -18,20 +18,6 @@ describe('The users module', () => { expect(state.users).to.eql([user]) expect(state.users[0].name).to.eql('Dude') }) - - it('sets a mute bit on users', () => { - const state = cloneDeep(defaultState) - const user = { id: '1', name: 'Guy' } - - mutations.addNewUsers(state, [user]) - mutations.setMuted(state, { user, muted: true }) - - expect(user.muted).to.eql(true) - - mutations.setMuted(state, { user, muted: false }) - - expect(user.muted).to.eql(false) - }) }) describe('findUser', () => { -- cgit v1.2.3-70-g09d2 From af9492977aaa10903d54add3187b5cf9d9a00d6c Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 24 Apr 2020 18:53:17 +0300 Subject: add back mute prediction, add getter for relationships --- src/components/block_card/block_card.js | 2 +- src/components/follow_card/follow_card.js | 2 +- src/components/mute_card/mute_card.js | 2 +- src/components/notification/notification.js | 2 +- src/components/status/status.js | 2 +- src/components/user_card/user_card.js | 2 +- src/components/user_settings/user_settings.js | 4 ++-- src/modules/users.js | 12 ++++++++++++ test/unit/specs/components/user_profile.spec.js | 1 + 9 files changed, 21 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/src/components/block_card/block_card.js b/src/components/block_card/block_card.js index 659c75d8..0bf4e37b 100644 --- a/src/components/block_card/block_card.js +++ b/src/components/block_card/block_card.js @@ -12,7 +12,7 @@ const BlockCard = { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] || {} + return this.$store.getters.relationship(this.userId) }, blocked () { return this.relationship.blocking diff --git a/src/components/follow_card/follow_card.js b/src/components/follow_card/follow_card.js index 620ae7fd..6dcb6d47 100644 --- a/src/components/follow_card/follow_card.js +++ b/src/components/follow_card/follow_card.js @@ -20,7 +20,7 @@ const FollowCard = { return this.$store.state.users.currentUser }, relationship () { - return this.$store.state.users.relationships[this.user.id] + return this.$store.getters.relationship(this.user.id) } } } diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js index be528d37..cbec0e9b 100644 --- a/src/components/mute_card/mute_card.js +++ b/src/components/mute_card/mute_card.js @@ -12,7 +12,7 @@ const MuteCard = { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] + return this.$store.getters.relationship(this.userId) }, muted () { return this.relationship.muting diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 09554f54..ff1c2817 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -56,7 +56,7 @@ const Notification = { return this.generateUserProfileLink(this.targetUser) }, needMute () { - return (this.$store.state.users.relationships[this.user.id] || {}).muting + return this.$store.getters.relationship(this.user.id).muting } } } diff --git a/src/components/status/status.js b/src/components/status/status.js index a73e3ae2..a36de028 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -119,7 +119,7 @@ const Status = { return hits }, muted () { - const relationship = this.$store.state.users.relationships[this.status.user.id] || {} + const relationship = this.$store.getters.relationship(this.userId) return !this.unmuted && ( (!(this.inProfile && this.status.user.id === this.profileUserId) && relationship.muting) || (!this.inConversation && this.status.thread_muted) || diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index fb3cfebc..8e6b9d7f 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -25,7 +25,7 @@ export default { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] || {} + return this.$store.getters.relationship(this.userId) }, classes () { return [{ diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index adfab8fa..5338c974 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -351,13 +351,13 @@ const UserSettings = { }, filterUnblockedUsers (userIds) { return reject(userIds, (userId) => { - const relationship = this.$store.state.users.relationships[userId] || {} + const relationship = this.$store.getters.relationship(this.userId) return relationship.blocking || userId === this.$store.state.users.currentUser.id }) }, filterUnMutedUsers (userIds) { return reject(userIds, (userId) => { - const relationship = this.$store.state.users.relationships[userId] || {} + const relationship = this.$store.getters.relationship(this.userId) return relationship.muting || userId === this.$store.state.users.currentUser.id }) }, diff --git a/src/modules/users.js b/src/modules/users.js index 6b19fc97..fb04ebd3 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -48,6 +48,11 @@ const unblockUser = (store, id) => { } const muteUser = (store, id) => { + const predictedRelationship = store.state.relationships[id] || { id } + predictedRelationship.muting = true + store.commit('updateUserRelationship', [predictedRelationship]) + store.commit('addMuteId', id) + return store.rootState.api.backendInteractor.muteUser({ id }) .then((relationship) => { store.commit('updateUserRelationship', [relationship]) @@ -56,6 +61,10 @@ const muteUser = (store, id) => { } const unmuteUser = (store, id) => { + const predictedRelationship = store.state.relationships[id] || { id } + predictedRelationship.muting = false + store.commit('updateUserRelationship', [predictedRelationship]) + return store.rootState.api.backendInteractor.unmuteUser({ id }) .then((relationship) => store.commit('updateUserRelationship', [relationship])) } @@ -227,6 +236,9 @@ export const getters = { return state.usersObject[query.toLowerCase()] } return result + }, + relationship: state => id => { + return state.relationships[id] || { id, loading: true } } } diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 0a3f2d27..dcf066f9 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -19,6 +19,7 @@ const actions = { const testGetters = { findUser: state => getters.findUser(state.users), + relationship: state => getters.relationship(state.users), mergedConfig: state => ({ colors: '', highlight: {}, -- cgit v1.2.3-70-g09d2 From c2dfe1f6cc364175d5aa17d587f82bdb6b8b189c Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 4 Jun 2020 15:25:00 +0200 Subject: EntityNormalizerSpec: Test new behavior. --- test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js index cfb380ba..178e75c6 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -338,9 +338,9 @@ describe('API Entities normalizer', () => { describe('MastoAPI emoji adder', () => { const emojis = makeMockEmojiMasto() - const imageHtml = 'image' + const imageHtml = ':image:' .replace(/"/g, '\'') - const thinkHtml = 'thinking' + const thinkHtml = ':thinking:' .replace(/"/g, '\'') it('correctly replaces shortcodes in supplied string', () => { -- cgit v1.2.3-70-g09d2 From 05167f202fbb55d1cee1a1c36b630c18ab297419 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 4 Jun 2020 15:31:52 +0200 Subject: EntityNormalizerSpec: More fixes. --- test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js index 178e75c6..166fce2b 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -366,8 +366,8 @@ describe('API Entities normalizer', () => { shortcode: '[a-z] {|}*' }]) const result = addEmojis('This post has :c++: emoji and :[a-z] {|}*: emoji', emojis) - expect(result).to.include('title=\'c++\'') - expect(result).to.include('title=\'[a-z] {|}*\'') + expect(result).to.include('title=\':c++:\'') + expect(result).to.include('title=\':[a-z] {|}*:\'') }) }) }) -- cgit v1.2.3-70-g09d2 From 8d7d4980b9a9c68e3c36dc00dfc85e39842b03f7 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 11 Jun 2020 18:39:19 +0200 Subject: StatusParser: Remove unused removeAttachmentLinks. Brings down the vendor by over 200kb --- package.json | 3 +-- src/services/status_parser/status_parser.js | 15 --------------- .../specs/services/status_parser/status_parses.spec.js | 17 ----------------- 3 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 test/unit/specs/services/status_parser/status_parses.spec.js (limited to 'test') diff --git a/package.json b/package.json index 4d68cc6e..42efc7e9 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,10 @@ "cropperjs": "^1.4.3", "diff": "^3.0.1", "escape-html": "^1.0.3", - "karma-mocha-reporter": "^2.2.1", "localforage": "^1.5.0", "object-path": "^0.11.3", "phoenix": "^1.3.0", "portal-vue": "^2.1.4", - "sanitize-html": "^1.13.0", "v-click-outside": "^2.1.1", "vue": "^2.6.11", "vue-chat-scroll": "^1.2.1", @@ -39,6 +37,7 @@ "whatwg-fetch": "^2.0.3" }, "devDependencies": { + "karma-mocha-reporter": "^2.2.1", "@babel/core": "^7.7.5", "@babel/plugin-transform-runtime": "^7.7.6", "@babel/preset-env": "^7.7.6", diff --git a/src/services/status_parser/status_parser.js b/src/services/status_parser/status_parser.js index 3d517e3c..ed0f6d57 100644 --- a/src/services/status_parser/status_parser.js +++ b/src/services/status_parser/status_parser.js @@ -1,17 +1,4 @@ import { filter } from 'lodash' -import sanitize from 'sanitize-html' - -export const removeAttachmentLinks = (html) => { - return sanitize(html, { - allowedTags: false, - allowedAttributes: false, - exclusiveFilter: ({ tag, attribs }) => tag === 'a' && typeof attribs.class === 'string' && attribs.class.match(/attachment/) - }) -} - -export const parse = (html) => { - return removeAttachmentLinks(html) -} export const muteWordHits = (status, muteWords) => { const statusText = status.text.toLowerCase() @@ -22,5 +9,3 @@ export const muteWordHits = (status, muteWords) => { return hits } - -export default parse diff --git a/test/unit/specs/services/status_parser/status_parses.spec.js b/test/unit/specs/services/status_parser/status_parses.spec.js deleted file mode 100644 index 7afd5042..00000000 --- a/test/unit/specs/services/status_parser/status_parses.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -import { removeAttachmentLinks } from '../../../../../src/services/status_parser/status_parser.js' - -const example = '' - -describe('statusParser.removeAttachmentLinks', () => { - const exampleWithoutAttachmentLinks = '' - - it('removes attachment links', () => { - const parsed = removeAttachmentLinks(example) - expect(parsed).to.eql(exampleWithoutAttachmentLinks) - }) - - it('works when the class is empty', () => { - const parsed = removeAttachmentLinks('') - expect(parsed).to.eql('') - }) -}) -- cgit v1.2.3-70-g09d2