diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-04-30 10:50:16 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2021-04-30 10:50:16 +0200 |
commit | 3b5bd61f14837635db0a2688a482d2498595024a (patch) | |
tree | 3b963e858e6f91c8853f005e3e173ea08bb11047 /src/store | |
parent | a41b98045d668dc57a73a66e34c9639fe7694b61 (diff) |
Add JS tests for guest name store
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/guestNameStore.spec.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/store/guestNameStore.spec.js b/src/store/guestNameStore.spec.js new file mode 100644 index 000000000..524a8b760 --- /dev/null +++ b/src/store/guestNameStore.spec.js @@ -0,0 +1,96 @@ +import Vuex from 'vuex' +import { cloneDeep } from 'lodash' +import { createLocalVue } from '@vue/test-utils' + +import guestNameStore from './guestNameStore' + +describe('guestNameStore', () => { + let localVue = null + let store = null + + beforeEach(() => { + localVue = createLocalVue() + localVue.use(Vuex) + + store = new Vuex.Store(cloneDeep(guestNameStore)) + }) + + afterEach(() => { + jest.clearAllMocks() + }) + + test('sets guest name if empty', () => { + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-one', + }) + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id2', + actorDisplayName: 'actor-display-name-two', + }) + + expect(store.getters.getGuestName('token-1', 'actor-id1')).toBe('actor-display-name-one') + expect(store.getters.getGuestName('token-1', 'actor-id2')).toBe('actor-display-name-two') + expect(store.getters.getGuestName('token-2', 'actor-id1')).toBe('Guest') + expect(store.getters.getGuestName('token-1', 'actor-id3')).toBe('Guest') + }) + + test('does not override guest name if not empty', () => { + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-one', + }) + + // attempt overwriting + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-another', + }) + + expect(store.getters.getGuestName('token-1', 'actor-id1')).toBe('actor-display-name-one') + }) + + test('force override guest name', () => { + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-one', + }) + + // attempt overwriting + store.dispatch('forceGuestName', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-another', + }) + + expect(store.getters.getGuestName('token-1', 'actor-id1')).toBe('actor-display-name-another') + }) + + test('clear guest name', () => { + store.dispatch('setGuestNameIfEmpty', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: 'actor-display-name-one', + }) + + store.dispatch('forceGuestName', { + token: 'token-1', + actorId: 'actor-id1', + actorDisplayName: '', + }) + + expect(store.getters.getGuestName('token-1', 'actor-id1')).toBe('Guest') + }) + + test('translates default guest name', () => { + expect(store.getters.getGuestName('token-1', 'actor-id0')).toBe('Guest') + + expect(global.t).toHaveBeenCalledWith('spreed', 'Guest') + }) + +}) |