diff options
Diffstat (limited to 'test/unit/specs')
| -rw-r--r-- | test/unit/specs/boot/routes.spec.js | 27 | ||||
| -rw-r--r-- | test/unit/specs/components/emoji_input.spec.js | 2 | ||||
| -rw-r--r-- | test/unit/specs/components/rich_content.spec.js | 28 | ||||
| -rw-r--r-- | test/unit/specs/components/user_profile.spec.js | 9 | ||||
| -rw-r--r-- | test/unit/specs/modules/lists.spec.js | 83 | ||||
| -rw-r--r-- | test/unit/specs/modules/serverSideStorage.spec.js | 326 | ||||
| -rw-r--r-- | test/unit/specs/modules/statuses.spec.js | 4 | ||||
| -rw-r--r-- | test/unit/specs/modules/users.spec.js | 44 | ||||
| -rw-r--r-- | test/unit/specs/services/chat_service/chat_service.spec.js | 24 | ||||
| -rw-r--r-- | test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 27 | ||||
| -rw-r--r-- | test/unit/specs/services/file_size_format/file_size_format.spec.js | 4 | ||||
| -rw-r--r-- | test/unit/specs/services/theme_data/sanity_checks.spec.js | 2 |
12 files changed, 525 insertions, 55 deletions
diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js index 439aefd4..ff246d2b 100644 --- a/test/unit/specs/boot/routes.spec.js +++ b/test/unit/specs/boot/routes.spec.js @@ -19,6 +19,7 @@ describe('routes', () => { const matchedComponents = router.currentRoute.value.matched + // eslint-disable-next-line no-prototype-builtins expect(matchedComponents[0].components.default.components.hasOwnProperty('Timeline')).to.eql(true) }) @@ -27,6 +28,7 @@ describe('routes', () => { const matchedComponents = router.currentRoute.value.matched + // eslint-disable-next-line no-prototype-builtins expect(matchedComponents[0].components.default.components.hasOwnProperty('UserCard')).to.eql(true) }) @@ -35,6 +37,31 @@ describe('routes', () => { const matchedComponents = router.currentRoute.value.matched + // eslint-disable-next-line no-prototype-builtins expect(matchedComponents[0].components.default.components.hasOwnProperty('UserCard')).to.eql(true) }) + + it('list view', async () => { + await router.push('/lists') + + const matchedComponents = router.currentRoute.value.matched + + expect(Object.prototype.hasOwnProperty.call(matchedComponents[0].components.default.components, 'ListsCard')).to.eql(true) + }) + + it('list timeline', async () => { + await router.push('/lists/1') + + const matchedComponents = router.currentRoute.value.matched + + expect(Object.prototype.hasOwnProperty.call(matchedComponents[0].components.default.components, 'Timeline')).to.eql(true) + }) + + it('list edit', async () => { + await router.push('/lists/1/edit') + + const matchedComponents = router.currentRoute.value.matched + + expect(Object.prototype.hasOwnProperty.call(matchedComponents[0].components.default.components, 'BasicUserCard')).to.eql(true) + }) }) diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js index 6188308e..752111ef 100644 --- a/test/unit/specs/components/emoji_input.spec.js +++ b/test/unit/specs/components/emoji_input.spec.js @@ -29,7 +29,7 @@ const generateInput = (value, padEmoji = true) => { modelValue: value }, slots: { - 'default': () => h('input', '') + default: () => h('input', '') } }) return wrapper diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index 958fb997..616df6a0 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -4,7 +4,15 @@ import RichContent from 'src/components/rich_content/rich_content.jsx' const attentions = [] const global = { mocks: { - '$store': null + $store: { + state: {}, + getters: { + mergedConfig: () => ({ + mentionLinkShowTooltip: true + }), + findUserByUrl: () => null + } + } }, stubs: { FAIcon: true @@ -131,8 +139,7 @@ describe('RichContent', () => { ].join(''), [ makeMention('John'), - makeMention('Josh'), - makeMention('Jeremy') + makeMention('Josh'), makeMention('Jeremy') ].join('') ].join('\n') @@ -349,7 +356,6 @@ describe('RichContent', () => { p( '<span class="MentionsLine">', '<span class="MentionLink mention-link">', - '<!-- eslint-disable vue/no-v-html -->', '<a href="lol" class="original" target="_blank">', '<span>', 'https://</span>', @@ -358,10 +364,7 @@ describe('RichContent', () => { '<span>', '</span>', '</a>', - '<!-- eslint-enable vue/no-v-html -->', - '<!--v-if-->', // v-if placeholder, mentionlink's "new" (i.e. rich) display '</span>', - '<!--v-if-->', // v-if placeholder, mentionsline's extra mentions and stuff '</span>' ), p( @@ -380,7 +383,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '').replace(/<!--.*?-->/g, '')).to.eql(compwrap(expected)) }) it('rich contents of nested mentions are handled properly', () => { @@ -412,7 +415,6 @@ describe('RichContent', () => { '<span class="poast-style">', '<span class="MentionsLine">', '<span class="MentionLink mention-link">', - '<!-- eslint-disable vue/no-v-html -->', '<a href="lol" class="original" target="_blank">', '<span>', 'https://</span>', @@ -421,11 +423,8 @@ describe('RichContent', () => { '<span>', '</span>', '</a>', - '<!-- eslint-enable vue/no-v-html -->', - '<!--v-if-->', // v-if placeholder, mentionlink's "new" (i.e. rich) display '</span>', '<span class="MentionLink mention-link">', - '<!-- eslint-disable vue/no-v-html -->', '<a href="lol" class="original" target="_blank">', '<span>', 'https://</span>', @@ -434,10 +433,7 @@ describe('RichContent', () => { '<span>', '</span>', '</a>', - '<!-- eslint-enable vue/no-v-html -->', - '<!--v-if-->', // v-if placeholder, mentionlink's "new" (i.e. rich) display '</span>', - '<!--v-if-->', // v-if placeholder, mentionsline's extra mentions and stuff '</span>', ' ', '</span>', @@ -455,7 +451,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '').replace(/<!--.*?-->/g, '')).to.eql(compwrap(expected)) }) it('rich contents of a link are handled properly', () => { diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 584758f7..dc0b938a 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -15,6 +15,7 @@ const actions = { const testGetters = { findUser: state => getters.findUser(state.users), + findUserByName: state => getters.findUserByName(state.users), relationship: state => getters.relationship(state.users), mergedConfig: state => ({ colors: '', @@ -95,6 +96,7 @@ const externalProfileStore = createStore({ credentials: '' }, usersObject: { 100: extUser }, + usersByNameObject: {}, users: [extUser], relationships: {} } @@ -163,7 +165,8 @@ const localProfileStore = createStore({ currentUser: { credentials: '' }, - usersObject: { 100: localUser, 'testuser': localUser }, + usersObject: { 100: localUser }, + usersByNameObject: { testuser: localUser }, users: [localUser], relationships: {} } @@ -175,7 +178,7 @@ describe.skip('UserProfile', () => { it('renders external profile', () => { const wrapper = mount(UserProfile, { global: { - plugins: [ externalProfileStore ], + plugins: [externalProfileStore], mocks: { $route: { params: { id: 100 }, @@ -192,7 +195,7 @@ describe.skip('UserProfile', () => { it('renders local profile', () => { const wrapper = mount(UserProfile, { global: { - plugins: [ localProfileStore ], + plugins: [localProfileStore], mocks: { $route: { params: { name: 'testUser' }, diff --git a/test/unit/specs/modules/lists.spec.js b/test/unit/specs/modules/lists.spec.js new file mode 100644 index 00000000..e43106ea --- /dev/null +++ b/test/unit/specs/modules/lists.spec.js @@ -0,0 +1,83 @@ +import { cloneDeep } from 'lodash' +import { defaultState, mutations, getters } from '../../../../src/modules/lists.js' + +describe('The lists module', () => { + describe('mutations', () => { + it('updates array of all lists', () => { + const state = cloneDeep(defaultState) + const list = { id: '1', title: 'testList' } + + mutations.setLists(state, [list]) + expect(state.allLists).to.have.length(1) + expect(state.allLists).to.eql([list]) + }) + + it('adds a new list with a title, updating the title for existing lists', () => { + const state = cloneDeep(defaultState) + const list = { id: '1', title: 'testList' } + const modList = { id: '1', title: 'anotherTestTitle' } + + mutations.setList(state, { listId: list.id, title: list.title }) + expect(state.allListsObject[list.id]).to.eql({ title: list.title, accountIds: [] }) + expect(state.allLists).to.have.length(1) + expect(state.allLists[0]).to.eql(list) + + mutations.setList(state, { listId: modList.id, title: modList.title }) + expect(state.allListsObject[modList.id]).to.eql({ title: modList.title, accountIds: [] }) + expect(state.allLists).to.have.length(1) + expect(state.allLists[0]).to.eql(modList) + }) + + it('adds a new list with an array of IDs, updating the IDs for existing lists', () => { + const state = cloneDeep(defaultState) + const list = { id: '1', accountIds: ['1', '2', '3'] } + const modList = { id: '1', accountIds: ['3', '4', '5'] } + + mutations.setListAccounts(state, { listId: list.id, accountIds: list.accountIds }) + expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds }) + + mutations.setListAccounts(state, { listId: modList.id, accountIds: modList.accountIds }) + expect(state.allListsObject[modList.id]).to.eql({ accountIds: modList.accountIds }) + }) + + it('deletes a list', () => { + const state = { + allLists: [{ id: '1', title: 'testList' }], + allListsObject: { + 1: { title: 'testList', accountIds: ['1', '2', '3'] } + } + } + const listId = '1' + + mutations.deleteList(state, { listId }) + expect(state.allLists).to.have.length(0) + expect(state.allListsObject).to.eql({}) + }) + }) + + describe('getters', () => { + it('returns list title', () => { + const state = { + allLists: [{ id: '1', title: 'testList' }], + allListsObject: { + 1: { title: 'testList', accountIds: ['1', '2', '3'] } + } + } + const id = '1' + + expect(getters.findListTitle(state)(id)).to.eql('testList') + }) + + it('returns list accounts', () => { + const state = { + allLists: [{ id: '1', title: 'testList' }], + allListsObject: { + 1: { title: 'testList', accountIds: ['1', '2', '3'] } + } + } + const id = '1' + + expect(getters.findListAccounts(state)(id)).to.eql(['1', '2', '3']) + }) + }) +}) diff --git a/test/unit/specs/modules/serverSideStorage.spec.js b/test/unit/specs/modules/serverSideStorage.spec.js new file mode 100644 index 00000000..be249eed --- /dev/null +++ b/test/unit/specs/modules/serverSideStorage.spec.js @@ -0,0 +1,326 @@ +import { cloneDeep } from 'lodash' + +import { + VERSION, + COMMAND_TRIM_FLAGS, + COMMAND_TRIM_FLAGS_AND_RESET, + _moveItemInArray, + _getRecentData, + _getAllFlags, + _mergeFlags, + _mergePrefs, + _resetFlags, + mutations, + defaultState, + newUserFlags +} from 'src/modules/serverSideStorage.js' + +describe('The serverSideStorage module', () => { + describe('mutations', () => { + describe('setServerSideStorage', () => { + const { setServerSideStorage } = mutations + const user = { + created_at: new Date('1999-02-09'), + storage: {} + } + + it('should initialize storage if none present', () => { + const state = cloneDeep(defaultState) + setServerSideStorage(state, user) + expect(state.cache._version).to.eql(VERSION) + expect(state.cache._timestamp).to.be.a('number') + expect(state.cache.flagStorage).to.eql(defaultState.flagStorage) + expect(state.cache.prefsStorage).to.eql(defaultState.prefsStorage) + }) + + it('should initialize storage with proper flags for new users if none present', () => { + const state = cloneDeep(defaultState) + setServerSideStorage(state, { ...user, created_at: new Date() }) + expect(state.cache._version).to.eql(VERSION) + expect(state.cache._timestamp).to.be.a('number') + expect(state.cache.flagStorage).to.eql(newUserFlags) + expect(state.cache.prefsStorage).to.eql(defaultState.prefsStorage) + }) + + it('should merge flags even if remote timestamp is older', () => { + const state = { + ...cloneDeep(defaultState), + cache: { + _timestamp: Date.now(), + _version: VERSION, + ...cloneDeep(defaultState) + } + } + setServerSideStorage( + state, + { + ...user, + storage: { + _timestamp: 123, + _version: VERSION, + flagStorage: { + ...defaultState.flagStorage, + updateCounter: 1 + }, + prefsStorage: { + ...defaultState.prefsStorage + } + } + } + ) + expect(state.cache.flagStorage).to.eql({ + ...defaultState.flagStorage, + updateCounter: 1 + }) + }) + + it('should reset local timestamp to remote if contents are the same', () => { + const state = { + ...cloneDeep(defaultState), + cache: null + } + setServerSideStorage( + state, + { + ...user, + storage: { + _timestamp: 123, + _version: VERSION, + flagStorage: { + ...defaultState.flagStorage, + updateCounter: 999 + } + } + } + ) + expect(state.cache._timestamp).to.eql(123) + expect(state.flagStorage.updateCounter).to.eql(999) + expect(state.cache.flagStorage.updateCounter).to.eql(999) + }) + + it('should remote version if local missing', () => { + const state = cloneDeep(defaultState) + setServerSideStorage(state, user) + expect(state.cache._version).to.eql(VERSION) + expect(state.cache._timestamp).to.be.a('number') + expect(state.cache.flagStorage).to.eql(defaultState.flagStorage) + }) + }) + describe('setPreference', () => { + const { setPreference, updateCache, addCollectionPreference, removeCollectionPreference } = mutations + + it('should set preference and update journal log accordingly', () => { + const state = cloneDeep(defaultState) + setPreference(state, { path: 'simple.testing', value: 1 }) + expect(state.prefsStorage.simple.testing).to.eql(1) + expect(state.prefsStorage._journal.length).to.eql(1) + expect(state.prefsStorage._journal[0]).to.eql({ + path: 'simple.testing', + operation: 'set', + args: [1], + // should have A timestamp, we don't really care what it is + timestamp: state.prefsStorage._journal[0].timestamp + }) + }) + + it('should keep journal to a minimum', () => { + const state = cloneDeep(defaultState) + setPreference(state, { path: 'simple.testing', value: 1 }) + setPreference(state, { path: 'simple.testing', value: 2 }) + addCollectionPreference(state, { path: 'collections.testing', value: 2 }) + removeCollectionPreference(state, { path: 'collections.testing', value: 2 }) + updateCache(state, { username: 'test' }) + expect(state.prefsStorage.simple.testing).to.eql(2) + expect(state.prefsStorage.collections.testing).to.eql([]) + expect(state.prefsStorage._journal.length).to.eql(2) + expect(state.prefsStorage._journal[0]).to.eql({ + path: 'simple.testing', + operation: 'set', + args: [2], + // should have A timestamp, we don't really care what it is + timestamp: state.prefsStorage._journal[0].timestamp + }) + expect(state.prefsStorage._journal[1]).to.eql({ + path: 'collections.testing', + operation: 'removeFromCollection', + args: [2], + // should have A timestamp, we don't really care what it is + timestamp: state.prefsStorage._journal[1].timestamp + }) + }) + }) + }) + + describe('helper functions', () => { + describe('_moveItemInArray', () => { + it('should move item according to movement value', () => { + expect(_moveItemInArray([1, 2, 3, 4], 4, -1)).to.eql([1, 2, 4, 3]) + expect(_moveItemInArray([1, 2, 3, 4], 1, 2)).to.eql([2, 3, 1, 4]) + }) + it('should clamp movement to within array', () => { + expect(_moveItemInArray([1, 2, 3, 4], 4, -10)).to.eql([4, 1, 2, 3]) + expect(_moveItemInArray([1, 2, 3, 4], 3, 99)).to.eql([1, 2, 4, 3]) + }) + }) + describe('_getRecentData', () => { + it('should handle nulls correctly', () => { + expect(_getRecentData(null, null)).to.eql({ recent: null, stale: null, needUpload: true }) + }) + + it('doesn\'t choke on invalid data', () => { + expect(_getRecentData({ a: 1 }, { b: 2 })).to.eql({ recent: null, stale: null, needUpload: true }) + }) + + it('should prefer the valid non-null correctly, needUpload works properly', () => { + const nonNull = { _version: VERSION, _timestamp: 1 } + expect(_getRecentData(nonNull, null)).to.eql({ recent: nonNull, stale: null, needUpload: true }) + expect(_getRecentData(null, nonNull)).to.eql({ recent: nonNull, stale: null, needUpload: false }) + }) + + it('should prefer the one with higher timestamp', () => { + const a = { _version: VERSION, _timestamp: 1 } + const b = { _version: VERSION, _timestamp: 2 } + + expect(_getRecentData(a, b)).to.eql({ recent: b, stale: a, needUpload: false }) + expect(_getRecentData(b, a)).to.eql({ recent: b, stale: a, needUpload: false }) + }) + + it('case where both are same', () => { + const a = { _version: VERSION, _timestamp: 3 } + const b = { _version: VERSION, _timestamp: 3 } + + expect(_getRecentData(a, b)).to.eql({ recent: b, stale: a, needUpload: false }) + expect(_getRecentData(b, a)).to.eql({ recent: b, stale: a, needUpload: false }) + }) + }) + + describe('_getAllFlags', () => { + it('should handle nulls properly', () => { + expect(_getAllFlags(null, null)).to.eql([]) + }) + it('should output list of keys if passed single object', () => { + expect(_getAllFlags({ flagStorage: { a: 1, b: 1, c: 1 } }, null)).to.eql(['a', 'b', 'c']) + }) + it('should union keys of both objects', () => { + expect(_getAllFlags({ flagStorage: { a: 1, b: 1, c: 1 } }, { flagStorage: { c: 1, d: 1 } })).to.eql(['a', 'b', 'c', 'd']) + }) + }) + + describe('_mergeFlags', () => { + it('should handle merge two flag sets correctly picking higher numbers', () => { + expect( + _mergeFlags( + { flagStorage: { a: 0, b: 3 } }, + { flagStorage: { b: 1, c: 4, d: 9 } }, + ['a', 'b', 'c', 'd']) + ).to.eql({ a: 0, b: 3, c: 4, d: 9 }) + }) + }) + + describe('_mergePrefs', () => { + it('should prefer recent and apply journal to it', () => { + expect( + _mergePrefs( + // RECENT + { + simple: { a: 1, b: 0, c: true }, + _journal: [ + { path: 'simple.b', operation: 'set', args: [0], timestamp: 2 }, + { path: 'simple.c', operation: 'set', args: [true], timestamp: 4 } + ] + }, + // STALE + { + simple: { a: 1, b: 1, c: false }, + _journal: [ + { path: 'simple.a', operation: 'set', args: [1], timestamp: 1 }, + { path: 'simple.b', operation: 'set', args: [1], timestamp: 3 } + ] + } + ) + ).to.eql({ + simple: { a: 1, b: 1, c: true }, + _journal: [ + { path: 'simple.a', operation: 'set', args: [1], timestamp: 1 }, + { path: 'simple.b', operation: 'set', args: [1], timestamp: 3 }, + { path: 'simple.c', operation: 'set', args: [true], timestamp: 4 } + ] + }) + }) + + it('should allow setting falsy values', () => { + expect( + _mergePrefs( + // RECENT + { + simple: { a: 1, b: 0, c: false }, + _journal: [ + { path: 'simple.b', operation: 'set', args: [0], timestamp: 2 }, + { path: 'simple.c', operation: 'set', args: [false], timestamp: 4 } + ] + }, + // STALE + { + simple: { a: 0, b: 0, c: true }, + _journal: [ + { path: 'simple.a', operation: 'set', args: [0], timestamp: 1 }, + { path: 'simple.b', operation: 'set', args: [0], timestamp: 3 } + ] + } + ) + ).to.eql({ + simple: { a: 0, b: 0, c: false }, + _journal: [ + { path: 'simple.a', operation: 'set', args: [0], timestamp: 1 }, + { path: 'simple.b', operation: 'set', args: [0], timestamp: 3 }, + { path: 'simple.c', operation: 'set', args: [false], timestamp: 4 } + ] + }) + }) + + it('should work with strings', () => { + expect( + _mergePrefs( + // RECENT + { + simple: { a: 'foo' }, + _journal: [ + { path: 'simple.a', operation: 'set', args: ['foo'], timestamp: 2 } + ] + }, + // STALE + { + simple: { a: 'bar' }, + _journal: [ + { path: 'simple.a', operation: 'set', args: ['bar'], timestamp: 4 } + ] + } + ) + ).to.eql({ + simple: { a: 'bar' }, + _journal: [ + { path: 'simple.a', operation: 'set', args: ['bar'], timestamp: 4 } + ] + }) + }) + }) + + describe('_resetFlags', () => { + it('should reset all known flags to 0 when reset flag is set to > 0 and < 9000', () => { + const totalFlags = { a: 0, b: 3, reset: 1 } + + expect(_resetFlags(totalFlags)).to.eql({ a: 0, b: 0, reset: 0 }) + }) + it('should trim all flags to known when reset is set to 1000', () => { + const totalFlags = { a: 0, b: 3, c: 33, reset: COMMAND_TRIM_FLAGS } + + expect(_resetFlags(totalFlags, { a: 0, b: 0, reset: 0 })).to.eql({ a: 0, b: 3, reset: 0 }) + }) + it('should trim all flags to known and reset when reset is set to 1001', () => { + const totalFlags = { a: 0, b: 3, c: 33, reset: COMMAND_TRIM_FLAGS_AND_RESET } + + expect(_resetFlags(totalFlags, { a: 0, b: 0, reset: 0 })).to.eql({ a: 0, b: 0, reset: 0 }) + }) + }) + }) +}) diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index b790b231..a8d0e5a3 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -245,7 +245,7 @@ describe('Statuses module', () => { it('increments count in existing reaction', () => { const state = defaultState() const status = makeMockStatus({ id: '1' }) - status.emoji_reactions = [ { name: 'π', count: 1, accounts: [] } ] + status.emoji_reactions = [{ name: 'π', count: 1, accounts: [] }] mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) mutations.addOwnReaction(state, { id: '1', emoji: 'π', currentUser: { id: 'me' } }) @@ -269,7 +269,7 @@ describe('Statuses module', () => { it('decreases count in existing reaction', () => { const state = defaultState() const status = makeMockStatus({ id: '1' }) - status.emoji_reactions = [ { name: 'π', count: 2, accounts: [{ id: 'me' }] } ] + status.emoji_reactions = [{ name: 'π', count: 2, accounts: [{ id: 'me' }] }] mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) mutations.removeOwnReaction(state, { id: '1', emoji: 'π', currentUser: { id: 'me' } }) diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index dfa5684d..3073f507 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -57,24 +57,27 @@ describe('The users module', () => { }) describe('findUser', () => { - it('returns user with matching screen_name', () => { + it('does not return user with matching screen_name', () => { const user = { screen_name: 'Guy', id: '1' } const state = { usersObject: { - 1: user, + 1: user + }, + usersByNameObject: { guy: user } } const name = 'Guy' - const expected = { screen_name: 'Guy', id: '1' } - expect(getters.findUser(state)(name)).to.eql(expected) + expect(getters.findUser(state)(name)).to.eql(undefined) }) it('returns user with matching id', () => { const user = { screen_name: 'Guy', id: '1' } const state = { usersObject: { - 1: user, + 1: user + }, + usersByNameObject: { guy: user } } @@ -83,4 +86,35 @@ describe('The users module', () => { expect(getters.findUser(state)(id)).to.eql(expected) }) }) + + describe('findUserByName', () => { + it('returns user with matching screen_name', () => { + const user = { screen_name: 'Guy', id: '1' } + const state = { + usersObject: { + 1: user + }, + usersByNameObject: { + guy: user + } + } + const name = 'Guy' + const expected = { screen_name: 'Guy', id: '1' } + expect(getters.findUserByName(state)(name)).to.eql(expected) + }) + + it('does not return user with matching id', () => { + const user = { screen_name: 'Guy', id: '1' } + const state = { + usersObject: { + 1: user + }, + usersByNameObject: { + guy: user + } + } + const id = '1' + expect(getters.findUserByName(state)(id)).to.eql(undefined) + }) + }) }) diff --git a/test/unit/specs/services/chat_service/chat_service.spec.js b/test/unit/specs/services/chat_service/chat_service.spec.js index fbbca436..a42269b4 100644 --- a/test/unit/specs/services/chat_service/chat_service.spec.js +++ b/test/unit/specs/services/chat_service/chat_service.spec.js @@ -24,23 +24,23 @@ describe('chatService', () => { describe('.add', () => { it("Doesn't add duplicates", () => { const chat = chatService.empty() - chatService.add(chat, { messages: [ message1 ] }) - chatService.add(chat, { messages: [ message1 ] }) + chatService.add(chat, { messages: [message1] }) + chatService.add(chat, { messages: [message1] }) expect(chat.messages.length).to.eql(1) - chatService.add(chat, { messages: [ message2 ] }) + chatService.add(chat, { messages: [message2] }) expect(chat.messages.length).to.eql(2) }) it('Updates minId and lastMessage and newMessageCount', () => { const chat = chatService.empty() - chatService.add(chat, { messages: [ message1 ] }) + chatService.add(chat, { messages: [message1] }) expect(chat.maxId).to.eql(message1.id) expect(chat.minId).to.eql(message1.id) expect(chat.newMessageCount).to.eql(1) - chatService.add(chat, { messages: [ message2 ] }) + chatService.add(chat, { messages: [message2] }) expect(chat.maxId).to.eql(message2.id) expect(chat.minId).to.eql(message1.id) expect(chat.newMessageCount).to.eql(2) @@ -50,7 +50,7 @@ describe('chatService', () => { expect(chat.lastSeenMessageId).to.eql(message2.id) // Add message with higher id - chatService.add(chat, { messages: [ message3 ] }) + chatService.add(chat, { messages: [message3] }) expect(chat.newMessageCount).to.eql(1) }) }) @@ -59,9 +59,9 @@ describe('chatService', () => { it('Updates minId and lastMessage', () => { const chat = chatService.empty() - chatService.add(chat, { messages: [ message1 ] }) - chatService.add(chat, { messages: [ message2 ] }) - chatService.add(chat, { messages: [ message3 ] }) + chatService.add(chat, { messages: [message1] }) + chatService.add(chat, { messages: [message2] }) + chatService.add(chat, { messages: [message3] }) expect(chat.maxId).to.eql(message3.id) expect(chat.minId).to.eql(message1.id) @@ -80,9 +80,9 @@ describe('chatService', () => { it('Inserts date separators', () => { const chat = chatService.empty() - chatService.add(chat, { messages: [ message1 ] }) - chatService.add(chat, { messages: [ message2 ] }) - chatService.add(chat, { messages: [ message3 ] }) + chatService.add(chat, { messages: [message1] }) + chatService.add(chat, { messages: [message2] }) + chatService.add(chat, { messages: [message3] }) const view = chatService.getView(chat) expect(view.map(i => i.type)).to.eql(['date', 'message', 'message', 'date', 'message']) 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 03fb32c9..3923596b 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -195,7 +195,7 @@ describe('API Entities normalizer', () => { expect(parsedPost).to.have.property('type', 'status') expect(parsedRepeat).to.have.property('type', 'retweet') expect(parsedRepeat).to.have.property('retweeted_status') - expect(parsedRepeat).to.have.deep.property('retweeted_status.id', 'deadbeef') + expect(parsedRepeat).to.have.nested.property('retweeted_status.id', 'deadbeef') }) it('sets nsfw for statuses with the #nsfw tag', () => { @@ -229,7 +229,7 @@ describe('API Entities normalizer', () => { expect(parsedPost).to.have.property('type', 'status') expect(parsedRepeat).to.have.property('type', 'retweet') expect(parsedRepeat).to.have.property('retweeted_status') - expect(parsedRepeat).to.have.deep.property('retweeted_status.id', 'deadbeef') + expect(parsedRepeat).to.have.nested.property('retweeted_status.id', 'deadbeef') }) }) }) @@ -269,7 +269,8 @@ describe('API Entities normalizer', () => { it('converts IDN to unicode and marks it as internatonal', () => { const user = makeMockUserMasto({ acct: 'lain@xn--lin-6cd.com' }) - expect(parseUser(user)).to.have.property('screen_name_ui').that.equal('lain@πlΠ°in.com') + expect(parseUser(user)).to.have.property('screen_name_ui').that.equal('lain@lΠ°in.com') + expect(parseUser(user)).to.have.property('screen_name_ui_contains_non_ascii').that.equal(true) }) }) @@ -284,9 +285,9 @@ describe('API Entities normalizer', () => { }) expect(parseNotification(notif)).to.have.property('id', 123) expect(parseNotification(notif)).to.have.property('seen', false) - expect(parseNotification(notif)).to.have.deep.property('status.id', '444') - expect(parseNotification(notif)).to.have.deep.property('action.id', '444') - expect(parseNotification(notif)).to.have.deep.property('from_profile.id', 'spurdo') + expect(parseNotification(notif)).to.have.nested.property('status.id', '444') + expect(parseNotification(notif)).to.have.nested.property('action.id', '444') + expect(parseNotification(notif)).to.have.nested.property('from_profile.id', 'spurdo') }) it('correctly normalizes favorite notifications', () => { @@ -303,9 +304,9 @@ describe('API Entities normalizer', () => { expect(parseNotification(notif)).to.have.property('id', 123) expect(parseNotification(notif)).to.have.property('type', 'like') expect(parseNotification(notif)).to.have.property('seen', true) - expect(parseNotification(notif)).to.have.deep.property('status.id', '4412') - expect(parseNotification(notif)).to.have.deep.property('action.id', '444') - expect(parseNotification(notif)).to.have.deep.property('from_profile.id', 'spurdo') + expect(parseNotification(notif)).to.have.nested.property('status.id', '4412') + expect(parseNotification(notif)).to.have.nested.property('action.id', '444') + expect(parseNotification(notif)).to.have.nested.property('from_profile.id', 'spurdo') }) }) @@ -314,8 +315,8 @@ describe('API Entities normalizer', () => { const linkHeader = '<https://example.com/api/v1/notifications?max_id=861676>; rel="next", <https://example.com/api/v1/notifications?min_id=861741>; rel="prev"' const result = parseLinkHeaderPagination(linkHeader) expect(result).to.eql({ - 'maxId': 861676, - 'minId': 861741 + maxId: 861676, + minId: 861741 }) }) @@ -323,8 +324,8 @@ describe('API Entities normalizer', () => { const linkHeader = '<http://example.com/api/v1/timelines/home?max_id=9waQx5IIS48qVue2Ai>; rel="next", <http://example.com/api/v1/timelines/home?min_id=9wi61nIPnfn674xgie>; rel="prev"' const result = parseLinkHeaderPagination(linkHeader, { flakeId: true }) expect(result).to.eql({ - 'maxId': '9waQx5IIS48qVue2Ai', - 'minId': '9wi61nIPnfn674xgie' + maxId: '9waQx5IIS48qVue2Ai', + minId: '9wi61nIPnfn674xgie' }) }) }) diff --git a/test/unit/specs/services/file_size_format/file_size_format.spec.js b/test/unit/specs/services/file_size_format/file_size_format.spec.js index e02ac379..6804b6eb 100644 --- a/test/unit/specs/services/file_size_format/file_size_format.spec.js +++ b/test/unit/specs/services/file_size_format/file_size_format.spec.js @@ -25,8 +25,8 @@ describe('fileSizeFormat', () => { } ] - var res = [] - for (var value in values) { + const res = [] + for (const value in values) { res.push(fileSizeFormatService.fileSizeFormat(values[value])) } expect(res).to.eql(expected) diff --git a/test/unit/specs/services/theme_data/sanity_checks.spec.js b/test/unit/specs/services/theme_data/sanity_checks.spec.js index f0072e7d..f94c6a08 100644 --- a/test/unit/specs/services/theme_data/sanity_checks.spec.js +++ b/test/unit/specs/services/theme_data/sanity_checks.spec.js @@ -6,7 +6,7 @@ const checkColors = (output) => { expect(v, key).to.be.an('object') expect(v, key).to.include.all.keys('r', 'g', 'b') 'rgba'.split('').forEach(k => { - if ((k === 'a' && v.hasOwnProperty('a')) || k !== 'a') { + if ((k === 'a' && Object.prototype.hasOwnProperty.call(v, 'a')) || k !== 'a') { expect(v[k], key + '.' + k).to.be.a('number') expect(v[k], key + '.' + k).to.be.least(0) expect(v[k], key + '.' + k).to.be.most(k === 'a' ? 1 : 255) |
