-
Notifications
You must be signed in to change notification settings - Fork 2k
/
getEmbeddedExplorerHTML.test.ts
103 lines (100 loc) 路 3.81 KB
/
getEmbeddedExplorerHTML.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
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
103
import { getEmbeddedExplorerHTML } from '../../../plugin/landingPage/default/getEmbeddedHTML';
import type { ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions } from '../../../plugin/landingPage/default/types';
import { describe, it, expect } from '@jest/globals';
const cdnVersion = '_latest';
expect.addSnapshotSerializer(require('jest-serializer-html'));
const apolloServerVersion = '@apollo/server@4.0.0';
describe('Embedded Explorer Landing Page Config HTML', () => {
it('with document, variables, headers and displayOptions provided', () => {
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions =
{
includeCookies: true,
document: 'query Test { id }',
variables: {
option: {
a: 'val',
b: 1,
c: true,
},
},
headers: { authorization: 'true' },
embed: {
displayOptions: {
showHeadersAndEnvVars: true,
docsPanelState: 'open',
theme: 'light',
},
persistExplorerState: true,
},
graphRef: 'graph@current',
};
expect(getEmbeddedExplorerHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
<h1>
Welcome to Apollo Server
</h1>
<p>
Apollo Explorer cannot be loaded; it appears that you might be offline.
</p>
</div>
<style>
iframe {
background-color: white;
}
</style>
<div style="width: 100vw; height: 100vh; position: absolute; top: 0;"
id="embeddableExplorer"
>
</div>
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?runtime=%40apollo%2Fserver%404.0.0">
</script>
<script>
var endpointUrl = window.location.href;
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"document":"query Test { id }","headers":{"authorization":"true"},"variables":{"option":{"a":"val","b":1,"c":true}},"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true,"includeCookies":true,"runtime":"@apollo/server@4.0.0"};
new window.EmbeddedExplorer({
...embeddedExplorerConfig,
endpointUrl,
});
</script>
`);
});
it('for embedded explorer with document, variables, headers and displayOptions excluded', () => {
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions =
{
includeCookies: false,
embed: true as true,
graphRef: 'graph@current',
};
expect(getEmbeddedExplorerHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
<h1>
Welcome to Apollo Server
</h1>
<p>
Apollo Explorer cannot be loaded; it appears that you might be offline.
</p>
</div>
<style>
iframe {
background-color: white;
}
</style>
<div style="width: 100vw; height: 100vh; position: absolute; top: 0;"
id="embeddableExplorer"
>
</div>
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?runtime=%40apollo%2Fserver%404.0.0">
</script>
<script>
var endpointUrl = window.location.href;
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"displayOptions":{}},"persistExplorerState":false,"includeCookies":false,"runtime":"@apollo/server@4.0.0"};
new window.EmbeddedExplorer({
...embeddedExplorerConfig,
endpointUrl,
});
</script>
`);
});
});