-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.spec.js
102 lines (91 loc) · 2.83 KB
/
utils.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {
getCreatedByApp,
hasBeenUpdatedByApp,
getFlagshipDownloadLink
} from './utils'
import { isAndroid, isIOS } from 'cozy-device-helper'
import flag from 'cozy-flags'
jest.mock('cozy-device-helper', () => ({
isAndroid: jest.fn(),
isIOS: jest.fn()
}))
jest.mock('cozy-flags')
test('getCreatedByApp', () => {
expect(getCreatedByApp({ cozyMetadata: { createdByApp: 'banks' } })).toBe(
'banks'
)
expect(getCreatedByApp({})).toBe(undefined)
})
test('hasBeenUpdatedByApp', () => {
expect(
hasBeenUpdatedByApp(
{ cozyMetadata: { updatedByApps: [{ slug: 'banks' }] } },
'banks'
)
).toBe(true)
expect(
hasBeenUpdatedByApp(
{ cozyMetadata: { updatedByApps: [{ slug: 'banks' }] } },
'drive'
)
).toBe(false)
expect(hasBeenUpdatedByApp({}, 'drive')).toBe(false)
})
describe('getFlagshipDownloadLink', () => {
afterEach(() => {
jest.resetAllMocks()
})
it('should return the Android download link with the correct ID and language', () => {
// @ts-ignore
isAndroid.mockReturnValueOnce(true)
flag.mockReturnValueOnce('com.example.app')
const lang = 'fr'
expect(getFlagshipDownloadLink(lang)).toBe(
'https://play.google.com/store/apps/details?id=com.example.app&hl=fr'
)
})
it('should return the default Android download link if no ID is provided', () => {
// @ts-ignore
isAndroid.mockReturnValueOnce(true)
flag.mockReturnValueOnce(null)
const lang = 'en'
expect(getFlagshipDownloadLink(lang)).toBe(
'https://play.google.com/store/apps/details?id=io.cozy.flagship.mobile&hl=en'
)
})
it('should return the iOS download link with the correct ID and language', () => {
// @ts-ignore
isIOS.mockReturnValueOnce(true)
flag.mockReturnValueOnce('id123456')
const lang = 'es'
expect(getFlagshipDownloadLink(lang)).toBe(
'https://apps.apple.com/es/app/id123456'
)
})
it('should return the default iOS download link if no ID is provided', () => {
// @ts-ignore
isIOS.mockReturnValueOnce(true)
flag.mockReturnValueOnce(null)
const lang = 'en'
expect(getFlagshipDownloadLink(lang)).toBe(
'https://apps.apple.com/en/app/id1600636174'
)
})
it('should return the download link from the flag for other platforms', () => {
// @ts-ignore
isAndroid.mockReturnValueOnce(false)
// @ts-ignore
isIOS.mockReturnValueOnce(false)
flag.mockReturnValueOnce('https://other.site/download')
const lang = 'fr'
expect(getFlagshipDownloadLink(lang)).toBe('https://other.site/download')
})
it('should return the default download link for other platforms', () => {
// @ts-ignore
isAndroid.mockReturnValueOnce(false)
// @ts-ignore
isIOS.mockReturnValueOnce(false)
const lang = 'fr'
expect(getFlagshipDownloadLink(lang)).toBe('https://cozy.io/fr/download')
})
})