-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
navigation.js
114 lines (95 loc) · 4.25 KB
/
navigation.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
102
103
104
105
106
107
108
109
110
111
112
113
114
import { page, data } from "../../../shared-data/head-function-export.js"
// No need to test SSR navigation (anchor tags) because it's effectively covered in the html insertion tests
describe(`Head function export behavior during CSR navigation (Gatsby Link)`, () => {
it(`should remove tags not on next page`, () => {
cy.visit(page.basic).waitForRouteChange()
cy.getTestElement(`extra-meta`)
.invoke(`attr`, `content`)
.should(`equal`, data.static.extraMeta)
cy.getTestElement(`gatsby-link`).click().waitForRouteChange()
cy.get(`[data-testid="extra-meta"]`).should(`not.exist`)
})
it(`should add tags not on next page`, () => {
cy.visit(page.basic).waitForRouteChange()
cy.get(`[data-testid="extra-meta-2"]`).should(`not.exist`)
cy.getTestElement(`gatsby-link`).click().waitForRouteChange()
cy.getTestElement(`extra-meta-2`)
.invoke(`attr`, `content`)
.should(`equal`, data.queried.extraMeta2)
})
it(`should not contain tags from old tags when we navigate to page without Head export`, () => {
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(`navigate-to-page-without-head-export`)
.click()
.waitForRouteChange()
cy.getTestElement(`base`).should(`not.exist`)
cy.getTestElement(`title`).should(`not.exist`)
cy.getTestElement(`meta`).should(`not.exist`)
cy.getTestElement(`noscript`).should(`not.exist`)
cy.getTestElement(`style`).should(`not.exist`)
cy.getTestElement(`link`).should(`not.exist`)
})
/**
* Technically nodes are always removed from the DOM and new ones added (in other words nodes are not reused with different data),
* but since this is an implementation detail we'll still test the behavior we expect as if we didn't know that.
*/
it(`should change meta tag values`, () => {
// Initial load
cy.visit(page.basic).waitForRouteChange()
// Validate data from initial load
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)
// Navigate to a different page via Gatsby Link
cy.getTestElement(`gatsby-link`).click()
// Validate data on navigated-to page
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)
// Navigate back to original page via Gatsby Link
cy.getTestElement(`gatsby-link`).click().waitForRouteChange()
// Validate data is same as initial load
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)
})
})