-
Notifications
You must be signed in to change notification settings - Fork 2k
/
getEmbeddedSandboxHTML.test.ts
96 lines (93 loc) 路 3.11 KB
/
getEmbeddedSandboxHTML.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
import { getEmbeddedSandboxHTML } from '../../../plugin/landingPage/default/getEmbeddedHTML';
import type { LandingPageConfig } 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('Landing Page Config HTML', () => {
it('for embedded sandbox with document, variables and headers provided', () => {
const config: LandingPageConfig = {
includeCookies: true,
document: 'query Test { id }',
variables: {
option: {
a: 'val',
b: 1,
c: true,
},
},
headers: { authorization: 'true' },
embed: true,
};
expect(getEmbeddedSandboxHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
<h1>
Welcome to Apollo Server
</h1>
<p>
Apollo Sandbox 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="embeddableSandbox"
>
</div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?runtime=%40apollo%2Fserver%404.0.0">
</script>
<script>
var initialEndpoint = window.location.href;
new window.EmbeddedSandbox({
target: '#embeddableSandbox',
initialEndpoint,
initialState: {"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"includeCookies":true},
hideCookieToggle: false,
runtime: '@apollo/server@4.0.0'
});
</script>
`);
});
it('for embedded sandbox with document, variables and headers excluded', () => {
const config: LandingPageConfig = {
includeCookies: false,
embed: true,
};
expect(getEmbeddedSandboxHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
<h1>
Welcome to Apollo Server
</h1>
<p>
Apollo Sandbox 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="embeddableSandbox"
>
</div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?runtime=%40apollo%2Fserver%404.0.0">
</script>
<script>
var initialEndpoint = window.location.href;
new window.EmbeddedSandbox({
target: '#embeddableSandbox',
initialEndpoint,
initialState: {"includeCookies":false},
hideCookieToggle: false,
runtime: '@apollo/server@4.0.0'
});
</script>
`);
});
});