-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
html-insertion.js
101 lines (95 loc) · 4.04 KB
/
html-insertion.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
95
96
97
98
99
100
101
import { page, data } from "../../../shared-data/head-function-export.js"
describe(`Head function export html insertion`, () => {
it(`should work with static data`, () => {
cy.visit(page.basic).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.static.base)
cy.getTestElement(`title`).should(`have.text`, data.static.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.static.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.static.noscript)
cy.getTestElement(`style`).should(`contain`, data.static.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.static.link)
cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD)
})
it(`should work with data from a page query`, () => {
cy.visit(page.pageQuery).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.queried.base)
cy.getTestElement(`title`).should(`have.text`, data.queried.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.queried.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.queried.noscript)
cy.getTestElement(`style`).should(`contain`, data.queried.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.queried.link)
})
it(`should work when a head function with static data is re-exported from the page`, () => {
cy.visit(page.reExport).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.static.base)
cy.getTestElement(`title`).should(`have.text`, data.static.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.static.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.static.noscript)
cy.getTestElement(`style`).should(`contain`, data.static.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.static.link)
cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD)
})
it(`should work when an imported Head component with queried data is used`, () => {
cy.visit(page.staticQuery).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.queried.base)
cy.getTestElement(`title`).should(`have.text`, data.queried.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.queried.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.queried.noscript)
cy.getTestElement(`style`).should(`contain`, data.queried.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.queried.link)
})
it(`should work in a DSG page (exporting function named config)`, () => {
cy.visit(page.dsg).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.dsg.base)
cy.getTestElement(`title`).should(`have.text`, data.dsg.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.dsg.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.dsg.noscript)
cy.getTestElement(`style`).should(`contain`, data.dsg.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.dsg.link)
})
it(`should work in an SSR page (exporting function named getServerData)`, () => {
cy.visit(page.ssr).waitForRouteChange()
cy.getTestElement(`base`)
.invoke(`attr`, `href`)
.should(`equal`, data.ssr.base)
cy.getTestElement(`title`).should(`have.text`, data.ssr.title)
cy.getTestElement(`meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.ssr.meta)
cy.getTestElement(`noscript`).should(`have.text`, data.ssr.noscript)
cy.getTestElement(`style`).should(`contain`, data.ssr.style)
cy.getTestElement(`link`)
.invoke(`attr`, `href`)
.should(`equal`, data.ssr.link)
})
})