Skip to content

Commit

Permalink
Merge pull request #11633 from nextcloud/fix/noid/nextcloud-l10n-in-jest
Browse files Browse the repository at this point in the history
fix(JEST): use nextcloud/l10n library in tests, omit some console logs
  • Loading branch information
Antreesy authored Feb 22, 2024
2 parents 2e7bbaf + d6bd3a9 commit 9e50035
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ describe('Reactions.vue', () => {
test('fetches reactions details when they are not available', async () => {
// Arrange
reactionsStore.resetReactions(token, messageId)
console.debug = jest.fn()
jest.spyOn(reactionsStore, 'fetchReactions')

const wrapper = shallowMount(Reactions, {
Expand Down
11 changes: 2 additions & 9 deletions src/stores/__tests__/guestName.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ describe('guestNameStore', () => {
expect(store.getGuestName('token-1', 'actor-id1')).toBe('Guest')
})

test('translates default guest name', () => {

expect(store.getGuestName('token-1', 'actor-id0')).toBe('Guest')
expect(global.t).toHaveBeenCalledWith('spreed', 'Guest')
})

test('gets suffix with guest display name', () => {
// Arrange
const actor1 = {
Expand All @@ -123,8 +117,7 @@ describe('guestNameStore', () => {
store.addGuestName(actor1, { noUpdate: false })

// Assert
expect(store.getGuestNameWithGuestSuffix('token-1', 'actor-id1')).toBe('{guest} (guest)')
expect(global.t).toHaveBeenCalledWith('spreed', '{guest} (guest)', { guest: 'actor-display-name-one' })
expect(store.getGuestNameWithGuestSuffix('token-1', 'actor-id1')).toBe('actor-display-name-one (guest)')
})

test('does not get suffix for translatable default guest name', () => {
Expand All @@ -139,7 +132,6 @@ describe('guestNameStore', () => {

// Assert
expect(store.getGuestNameWithGuestSuffix('token-1', 'actor-id1')).toBe('Guest')
expect(global.t).toHaveBeenCalledWith('spreed', 'Guest')
})

test('stores the display name when guest submits it', async () => {
Expand Down Expand Up @@ -196,6 +188,7 @@ describe('guestNameStore', () => {
actorId: 'actor-id1',
actorDisplayName: 'old actor 1',
}
console.error = jest.fn()

vuexStore.dispatch('setCurrentUser', { uid: 'actor-id1' })
store.addGuestName(actor1, { noUpdate: false })
Expand Down
9 changes: 8 additions & 1 deletion src/stores/__tests__/reactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ describe('reactionsStore', () => {
// Arrange
const response = generateOCSResponse({ payload: reactions })
getReactionsDetails.mockResolvedValue(response)
console.debug = jest.fn()

// Act
reactionsStore.fetchReactions()

// Assert
expect(reactionsStore.getReactions(token, messageId)).toEqual(reactions)
})
it('updates reactions from the store', () => {
it('does not update reactions in the store twice', () => {
// Arrange
const newReactions = {
'🎄': [
Expand All @@ -95,6 +96,11 @@ describe('reactionsStore', () => {
messageId,
reactionsDetails: newReactions
})
reactionsStore.updateReactions({
token,
messageId,
reactionsDetails: newReactions
})

// Assert
expect(reactionsStore.getReactions(token, messageId)).toEqual(newReactions)
Expand Down Expand Up @@ -183,6 +189,7 @@ describe('reactionsStore', () => {
getReactionsDetails.mockResolvedValue(response)
jest.spyOn(reactionsStore, 'removeReaction')
jest.spyOn(reactionsStore, 'fetchReactions')
console.debug = jest.fn()

// Act
await reactionsStore.processReaction(token, message)
Expand Down
2 changes: 1 addition & 1 deletion src/stores/guestName.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const useGuestNameStore = defineStore('guestName', {
actorId,
actorDisplayName: previousName,
}, { noUpdate: false })
console.debug(error)
console.error(error)
}
},
},
Expand Down
7 changes: 4 additions & 3 deletions src/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import 'regenerator-runtime/runtime'
import Vue from 'vue'

import { translate, translatePlural } from '@nextcloud/l10n'

jest.mock('extendable-media-recorder', () => ({
MediaRecorder: jest.fn(),
register: jest.fn(),
Expand Down Expand Up @@ -125,9 +127,8 @@ global.BroadcastChannel = jest.fn(() => ({
window.URL.createObjectURL = jest.fn()
window.URL.revokeObjectURL = jest.fn()

// TODO: use nextcloud-l10n lib once https://github.com/nextcloud/nextcloud-l10n/issues/271 is solved
global.t = jest.fn().mockImplementation((app, text) => text)
global.n = jest.fn().mockImplementation((app, text) => text)
global.t = translate
global.n = translatePlural

Vue.prototype.t = global.t
Vue.prototype.n = global.n
Expand Down

0 comments on commit 9e50035

Please sign in to comment.