-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathApplicationExtension.test.tsx
More file actions
66 lines (55 loc) · 2.28 KB
/
ApplicationExtension.test.tsx
File metadata and controls
66 lines (55 loc) · 2.28 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
/*
* Copyright (c) 2024, Salesforce, 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 {RouteProps} from 'react-router-dom'
import {ApplicationExtension} from './ApplicationExtension'
import {ApplicationExtensionConfig} from '../../types'
import React from 'react'
class TestConfig implements ApplicationExtensionConfig {
[key: string]: any
enabled = true
}
class TestExtension extends ApplicationExtension<TestConfig> {
static readonly id = 'test-extension'
}
describe('ApplicationExtension', () => {
let extension: ApplicationExtension<TestConfig>
let mockComponent: React.ComponentType<any>
beforeEach(() => {
const config = new TestConfig()
extension = new TestExtension(config)
mockComponent = jest.fn(() => <div>Test Component</div>)
})
describe('extendApp', () => {
test('should return the provided component without modification', () => {
const result = extension.extendApp(mockComponent)
expect(result).toBe(mockComponent)
})
})
describe('extendRoutes', () => {
test('should return the routes array without modification', () => {
const routes: RouteProps[] = [
{path: '/home', component: mockComponent},
{path: '/about', component: mockComponent}
]
const result = extension.extendRoutes(routes)
expect(result).toEqual(routes)
})
test('should allow for modification of routes', () => {
const routes: RouteProps[] = [{path: '/home', component: mockComponent}]
const additionalRoute: RouteProps = {path: '/new', component: mockComponent}
const extendRoutesSpy = jest
.spyOn(extension, 'extendRoutes')
.mockImplementation((baseRoutes) => {
return Promise.resolve([...baseRoutes, additionalRoute])
})
const modifiedRoutes = extension.extendRoutes(routes)
expect(modifiedRoutes).toContainEqual(additionalRoute)
expect(modifiedRoutes).toHaveLength(routes.length + 1)
extendRoutesSpy.mockRestore()
})
})
})