Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(JEST): use nextcloud/l10n library in tests, omit some console logs #11633

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
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')
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
})

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
Loading