-
Notifications
You must be signed in to change notification settings - Fork 3
/
WebApp.test.js
94 lines (84 loc) · 3.08 KB
/
WebApp.test.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
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import * as React from 'react';
import {
act, render, screen, waitFor,
} from '@testing-library/react';
import '@testing-library/jest-dom';
import { RecoilRoot } from 'recoil';
import { defaultTheme, Provider } from '@adobe/react-spectrum';
import { ApplicationProvider } from '../web-src/src/components/ApplicationProvider.js';
import { App } from '../web-src/src/components/App.js';
import { CONSENT_KEY } from '../web-src/src/components/ConsentDialog.js';
import { PROMPT_TEMPLATE_STORAGE_KEY } from '../web-src/src/state/PromptTemplatesState.js';
const CONFIG_URL = 'https://localhost:9080/index.html?ref=ref&repo=repo&owner=owner';
const mockConsentKey = CONSENT_KEY;
const mockPromptTemplateStorageKey = PROMPT_TEMPLATE_STORAGE_KEY;
jest.mock('@adobe/exc-app/settings', () => ({
get: jest.fn().mockImplementation(({ groupId, level, defaultValue }) => {
if (groupId === mockPromptTemplateStorageKey) {
return Promise.resolve({
settings: {
promptTemplates: [],
},
});
}
return Promise.resolve({
settings: {
[mockConsentKey]: true,
},
});
}),
SettingsLevel: jest.fn(),
}));
jest.mock('../web-src/src/helpers/NetworkHelper.js', () => ({
wretchRetry: jest.fn().mockImplementation(() => ({
get: jest.fn().mockImplementation(() => ({
json: jest.fn().mockRejectedValue(new Error('error')),
})),
})),
}));
jest.mock('../web-src/src/components/ShellProvider.js', () => ({
useShellContext: jest.fn().mockReturnValue({
user: {
imsOrg: 'org',
imsToken: 'token',
},
done: jest.fn(),
}),
}));
jest.mock('../web-src/src/services/FirefallService.js', () => ({
// eslint-disable-next-line func-names
FirefallService: jest.fn().mockImplementation(function () {
this.complete = jest.fn().mockReturnValue('text');
this.fallback = jest.fn().mockReturnValue({});
}),
}));
describe('WebApp', () => {
beforeEach(() => {
delete window.location;
window.location = new URL(CONFIG_URL);
});
it('renders correctly', async () => {
await act(async () => render(
<RecoilRoot>
<ApplicationProvider>
<Provider colorScheme="light" theme={defaultTheme} width="100%" height="100%">
<App />
</Provider>
</ApplicationProvider>
</RecoilRoot>,
));
expect(screen.getByTestId('prompt-templates-view')).toBeInTheDocument();
await waitFor(() => expect(screen.getAllByTestId('prompt-template-card').length).toBeGreaterThan(1));
});
});