aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/specs')
-rw-r--r--test/unit/specs/boot/routes.spec.js24
-rw-r--r--test/unit/specs/components/user_profile.spec.js5
-rw-r--r--test/unit/specs/modules/lists.spec.js83
-rw-r--r--test/unit/specs/modules/serverSideStorage.spec.js178
-rw-r--r--test/unit/specs/modules/users.spec.js44
-rw-r--r--test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js16
6 files changed, 336 insertions, 14 deletions
diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js
index 5cffefbb..ff246d2b 100644
--- a/test/unit/specs/boot/routes.spec.js
+++ b/test/unit/specs/boot/routes.spec.js
@@ -40,4 +40,28 @@ describe('routes', () => {
// 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/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js
index 0fbab722..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: {}
}
diff --git a/test/unit/specs/modules/lists.spec.js b/test/unit/specs/modules/lists.spec.js
new file mode 100644
index 00000000..ac9af1b6
--- /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, list)
+ expect(state.allListsObject[list.id]).to.eql({ title: list.title })
+ expect(state.allLists).to.have.length(1)
+ expect(state.allLists[0]).to.eql(list)
+
+ mutations.setList(state, modList)
+ expect(state.allListsObject[modList.id]).to.eql({ title: modList.title })
+ 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, list)
+ expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds })
+
+ mutations.setListAccounts(state, modList)
+ 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 id = '1'
+
+ mutations.deleteList(state, { id })
+ 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..e06c6ada
--- /dev/null
+++ b/test/unit/specs/modules/serverSideStorage.spec.js
@@ -0,0 +1,178 @@
+import { cloneDeep } from 'lodash'
+
+import {
+ VERSION,
+ COMMAND_TRIM_FLAGS,
+ COMMAND_TRIM_FLAGS_AND_RESET,
+ _getRecentData,
+ _getAllFlags,
+ _mergeFlags,
+ _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)
+ })
+
+ 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)
+ })
+
+ 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
+ }
+ }
+ }
+ )
+ 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('helper functions', () => {
+ 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('_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/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/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js
index 525e57a5..98bb05a8 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')
})
})
})
@@ -284,9 +284,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 +303,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')
})
})