Browse Source
Merge pull request #11786 from nextcloud/chore/noid/migrate-utils-to-typescript
Merge pull request #11786 from nextcloud/chore/noid/migrate-utils-to-typescript
chore(typescript): migrate utils to TSpull/11794/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 226 additions and 49 deletions
-
2src/components/CallView/shared/EmptyCallView.vue
-
2src/components/ConversationSettings/LinkShareSettings.vue
-
2src/components/LeftSidebar/ConversationsList/Conversation.vue
-
2src/components/MessagesList/MessagesGroup/Message/Message.vue
-
2src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue
-
2src/components/NewConversationDialog/NewConversationDialog.vue
-
2src/components/RightSidebar/Participants/Participant.vue
-
2src/components/RightSidebar/SipSettings.vue
-
2src/components/TopBar/TopBarMenu.vue
-
2src/stores/sharedItems.js
-
2src/types/index.ts
-
19src/utils/__tests__/formattedTime.spec.js
-
41src/utils/__tests__/getItemTypeFromMessage.spec.js
-
63src/utils/__tests__/handleUrl.spec.js
-
61src/utils/__tests__/readableNumber.spec.js
-
5src/utils/getItemTypeFromMessage.ts
-
34src/utils/handleUrl.ts
-
30src/utils/readableNumber.ts
@ -0,0 +1,19 @@ |
|||
import { formattedTime } from '../formattedTime.ts' |
|||
|
|||
const TIME = (61 * 60 + 5) * 1000 // 1 hour, 1 minute, 5 seconds in ms
|
|||
|
|||
describe('formattedTime', () => { |
|||
it('should return the formatted time with optional spacing and padded minutes / seconds', () => { |
|||
const result = formattedTime(TIME) |
|||
expect(result).toBe('1 : 01 : 05') |
|||
const resultCondensed = formattedTime(TIME, true) |
|||
expect(resultCondensed).toBe('1:01:05') |
|||
}) |
|||
|
|||
it('should return fallback string when time value is falsy', () => { |
|||
const result = formattedTime(0) |
|||
expect(result).toBe('-- : --') |
|||
const resultCondensed = formattedTime(0, true) |
|||
expect(resultCondensed).toBe('--:--') |
|||
}) |
|||
}) |
|||
@ -0,0 +1,41 @@ |
|||
import { SHARED_ITEM } from '../../constants.js' |
|||
import { getItemTypeFromMessage } from '../getItemTypeFromMessage.ts' |
|||
|
|||
describe('getItemTypeFromMessage', () => { |
|||
it('should return the correct item type for a messages', () => { |
|||
const messages = { |
|||
1: { messageType: 'comment', messageParameters: { object: { type: 'geo-location' } } }, |
|||
2: { messageType: 'comment', messageParameters: { object: { type: 'deck-card' } } }, |
|||
3: { messageType: 'comment', messageParameters: { object: { type: 'talk-poll' } } }, |
|||
4: { messageType: 'comment', messageParameters: { object: { type: 'some-type' } } }, |
|||
5: { messageType: 'record-audio', messageParameters: { file: { mimetype: 'audio/mp3' } } }, |
|||
6: { messageType: 'record-video', messageParameters: { file: { mimetype: 'video/mp4' } } }, |
|||
7: { messageType: 'voice-message', messageParameters: { file: { mimetype: 'audio/mp3' } } }, |
|||
8: { messageType: 'comment', messageParameters: { file: { mimetype: 'audio/mp3' } } }, |
|||
9: { messageType: 'comment', messageParameters: { file: { mimetype: 'image/jpg' } } }, |
|||
10: { messageType: 'comment', messageParameters: { file: { mimetype: 'video/mp4' } } }, |
|||
11: { messageType: 'comment', messageParameters: { file: { mimetype: 'text/markdown' } } }, |
|||
12: { messageType: 'comment', message: 'simple message' }, |
|||
} |
|||
|
|||
const outputTypes = { |
|||
1: SHARED_ITEM.TYPES.LOCATION, |
|||
2: SHARED_ITEM.TYPES.DECK_CARD, |
|||
3: SHARED_ITEM.TYPES.POLL, |
|||
4: SHARED_ITEM.TYPES.OTHER, |
|||
5: SHARED_ITEM.TYPES.RECORDING, |
|||
6: SHARED_ITEM.TYPES.RECORDING, |
|||
7: SHARED_ITEM.TYPES.VOICE, |
|||
8: SHARED_ITEM.TYPES.AUDIO, |
|||
9: SHARED_ITEM.TYPES.MEDIA, |
|||
10: SHARED_ITEM.TYPES.MEDIA, |
|||
11: SHARED_ITEM.TYPES.FILE, |
|||
12: SHARED_ITEM.TYPES.OTHER, |
|||
} |
|||
|
|||
for (const i in messages) { |
|||
const type = i + ': ' + getItemTypeFromMessage(messages[i]) |
|||
expect(type).toBe(i + ': ' + outputTypes[i]) |
|||
} |
|||
}) |
|||
}) |
|||
@ -0,0 +1,63 @@ |
|||
import { showError, showSuccess } from '@nextcloud/dialogs' |
|||
|
|||
import { |
|||
generateAbsoluteUrl, |
|||
generateFullConversationLink, |
|||
copyConversationLinkToClipboard, |
|||
} from '../handleUrl.ts' |
|||
|
|||
jest.mock('@nextcloud/dialogs', () => ({ |
|||
showSuccess: jest.fn(), |
|||
showError: jest.fn(), |
|||
})) |
|||
|
|||
describe('handleUrl', () => { |
|||
describe('generateAbsoluteUrl', () => { |
|||
it('should generate url with IS_DESKTOP=false correctly', () => { |
|||
const output = generateAbsoluteUrl('/path') |
|||
expect(output).toBe('http://localhost/nc-webroot/path') |
|||
}) |
|||
|
|||
it('should generate url with IS_DESKTOP=true correctly', () => { |
|||
const originalIsDesktop = global.IS_DESKTOP |
|||
global.IS_DESKTOP = true |
|||
|
|||
const output = generateAbsoluteUrl('/path') |
|||
expect(output).toBe('/nc-webroot/path') |
|||
|
|||
global.IS_DESKTOP = originalIsDesktop |
|||
}) |
|||
}) |
|||
|
|||
describe('generateFullConversationLink', () => { |
|||
it('should generate links with given token', () => { |
|||
const link = generateFullConversationLink('TOKEN') |
|||
expect(link).toBe('http://localhost/nc-webroot/call/TOKEN') |
|||
}) |
|||
|
|||
it('should generate links with given token and message id', () => { |
|||
const link = generateFullConversationLink('TOKEN', '123') |
|||
expect(link).toBe('http://localhost/nc-webroot/call/TOKEN#message_123') |
|||
}) |
|||
}) |
|||
|
|||
describe('copyConversationLinkToClipboard', () => { |
|||
it('should copy the conversation link and show success message', async () => { |
|||
Object.assign(navigator, { clipboard: { writeText: jest.fn().mockResolvedValueOnce() } }) |
|||
|
|||
await copyConversationLinkToClipboard('TOKEN', '123') |
|||
|
|||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('http://localhost/nc-webroot/call/TOKEN#message_123') |
|||
expect(showSuccess).toHaveBeenCalled() |
|||
}) |
|||
|
|||
it('should show error message when copying fails', async () => { |
|||
Object.assign(navigator, { clipboard: { writeText: jest.fn().mockRejectedValueOnce() } }) |
|||
|
|||
await copyConversationLinkToClipboard('TOKEN', '123') |
|||
|
|||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('http://localhost/nc-webroot/call/TOKEN#message_123') |
|||
expect(showError).toHaveBeenCalled() |
|||
}) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,61 @@ |
|||
import { readableNumber, stringChop } from '../readableNumber.ts' |
|||
|
|||
describe('readableNumber', () => { |
|||
describe('stringChop', () => { |
|||
it('should return the correct array of numbers', () => { |
|||
const numbers = { |
|||
1: { number: '123456789', size: 3 }, |
|||
2: { number: '12345678', size: 3 }, |
|||
3: { number: '1234567', size: 3 }, |
|||
4: { number: '123456', size: 2 }, |
|||
5: { number: '123456', size: 1 }, |
|||
6: { number: '123456', size: 0 }, |
|||
7: { number: '123456', size: 6 }, |
|||
8: { number: '123456', size: 7 }, |
|||
9: { number: '', size: 3 }, |
|||
} |
|||
|
|||
const outputTypes = { |
|||
1: ['123', '456', '789'], |
|||
2: ['123', '456', '78'], |
|||
3: ['123', '456', '7'], |
|||
4: ['12', '34', '56'], |
|||
5: ['1', '2', '3', '4', '5', '6'], |
|||
6: ['123456'], |
|||
7: ['123456'], |
|||
8: ['123456'], |
|||
9: [''], |
|||
} |
|||
|
|||
for (const i in numbers) { |
|||
const output = i + ': ' + stringChop(numbers[i].number, numbers[i].size) |
|||
expect(output).toBe(i + ': ' + outputTypes[i]) |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
describe('readableNumber', () => { |
|||
it('should return the correct readable number', () => { |
|||
const numbers = { |
|||
1: 123456789, |
|||
2: '123456789', |
|||
3: '12345678', |
|||
4: '1234567', |
|||
5: '', |
|||
} |
|||
|
|||
const outputTypes = { |
|||
1: '123 456 789', |
|||
2: '123 456 789', |
|||
3: '123 456 78', |
|||
4: '123 4567', |
|||
5: '', |
|||
} |
|||
|
|||
for (const i in numbers) { |
|||
const output = i + ': ' + readableNumber(numbers[i]) |
|||
expect(output).toBe(i + ': ' + outputTypes[i]) |
|||
} |
|||
}) |
|||
}) |
|||
}) |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue