-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathutils.client.test.js
More file actions
92 lines (80 loc) · 2.62 KB
/
utils.client.test.js
File metadata and controls
92 lines (80 loc) · 2.62 KB
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
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as utils from './utils'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {getEnvBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-config', () => ({
getConfig: jest.fn()
}))
jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths', () => ({
getEnvBasePath: jest.fn()
}))
describe('getProxyConfigs (client-side)', () => {
const configs = [{foo: 'bar'}]
beforeEach(() => {
global.Progressive = {ssrOptions: {proxyConfigs: configs}}
})
afterEach(() => {
delete global.Progressive
})
test('should return proxy configs set on window.Progressive', () => {
expect(utils.getProxyConfigs()).toEqual(configs)
})
})
describe('getAssetUrl (client-side)', () => {
beforeEach(() => {
global.Progressive = {buildOrigin: 'test.com'}
})
afterEach(() => {
delete global.Progressive
})
test('should return build origin when path is undefined', () => {
expect(utils.getAssetUrl()).toBe('test.com')
})
test('should return origin + path', () => {
expect(utils.getAssetUrl('/path')).toBe('test.com/path')
})
})
describe('getRouterBasePath (client-side)', () => {
beforeEach(() => {
jest.clearAllMocks()
})
test('should return base path when showBasePath is true', () => {
const mockBasePath = '/test-base'
getEnvBasePath.mockReturnValue(mockBasePath)
getConfig.mockReturnValue({
app: {
url: {
showBasePath: true
}
}
})
expect(utils.getRouterBasePath()).toBe(mockBasePath)
})
test('should return empty string when showBasePath is undefined', () => {
getConfig.mockReturnValue({
app: {
url: {}
}
})
expect(utils.getRouterBasePath()).toBe('')
})
test('should return empty string when showBasePath is false', () => {
getConfig.mockReturnValue({
app: {
url: {
showBasePath: false
}
}
})
expect(utils.getRouterBasePath()).toBe('')
})
test('should return empty string when app config is missing', () => {
getConfig.mockReturnValue({})
expect(utils.getRouterBasePath()).toBe('')
})
})