forked from bigcommerce/widget-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgetRenderer.test.ts
58 lines (51 loc) · 1.99 KB
/
widgetRenderer.test.ts
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
import fs from 'fs';
import WidgetFileType, { FileLoaderResponse } from '../../types';
import { generateRenderPayloadFromFileLoaderResults } from './widgetRenderer';
const configurationData = fs.readFileSync('src/services/__fixtures__/config.json', 'utf8').toString();
const translationsData = fs.readFileSync('src/services/__fixtures__/schema_translations.json', 'utf8').toString();
const htmlData = fs.readFileSync('src/services/__fixtures__/widget.html', 'utf8').toString();
const query = fs.readFileSync('src/services/__fixtures__/query.graphql', 'utf8').toString();
const queryParams = fs.readFileSync('src/services/__fixtures__/queryParams.json', 'utf8').toString();
const fileLoaderResponseData: FileLoaderResponse[] = [
{
type: WidgetFileType.TEMPLATE,
data: htmlData,
},
{
type: WidgetFileType.CONFIGURATION,
data: configurationData,
},
{
type: WidgetFileType.QUERY,
data: query,
},
{
type: WidgetFileType.QUERY_PARAMS,
data: queryParams,
},
{
type: WidgetFileType.TRANSLATION,
data: translationsData,
},
];
describe('Widget Renderer', () => {
it('renders correctly when all data is present', () => {
expect(true).toEqual(true);
const {
widget_configuration,
widget_template,
placement_uuid,
widget_uuid,
storefront_api_query,
storefront_api_query_params,
schema_translations,
} = generateRenderPayloadFromFileLoaderResults(fileLoaderResponseData);
expect(widget_configuration).toEqual(JSON.parse(configurationData));
expect(widget_template).toEqual(htmlData);
expect(storefront_api_query).toEqual(query);
expect(storefront_api_query_params).toEqual(JSON.parse(queryParams));
expect(placement_uuid).not.toBeNull();
expect(widget_uuid).not.toBeNull();
expect(schema_translations).toEqual(JSON.parse(translationsData));
});
});