-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsuspense-placeholder.spec.js
65 lines (64 loc) · 2.59 KB
/
suspense-placeholder.spec.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
const VISIT_URL = "/suspense/placeholder";
describe("/suspense/placeholder", () => {
// create series of tests for the following delayMs (which is customizable via url)
[1500, 4500, 7500].forEach(delayMs => {
describe(`check suspending delayMs=${delayMs}`, () => {
before(() => {
cy.visit(`${VISIT_URL}/delayMs/${delayMs}`);
cy.url().should(
"match",
new RegExp(`/suspense/placeholder/delayMs/${delayMs}$`)
);
});
// for each duration, create a series of tests
[150, 300, 1000, 2000, 3000, 5000, 6000, 10000].forEach(duration => {
// weird, for 6000ms, a Placeholder with a delayMs > 6000 will always show spinner ...
// so skipping the test for this specific case
(duration === 6000 && delayMs > 6000 ? it.skip : it)(
`[duration=${duration}ms] ${
duration > delayMs
? "should show spinner then content"
: "should NOT show spinner - content will show in time"
}`,
() => {
cy.getByTestId(`link-to-duration-${duration}`).click();
cy.url().should(
"match",
new RegExp(
`/suspense/placeholder/delayMs/${delayMs}/duration/${duration}$`
)
);
if (duration > delayMs) {
// duration > delayMs -> should show spinner then content
cy.get(
`[data-testid=link-to-duration-${duration}] .render-paused`
).should("be.visible");
cy.get("[data-testid=delay-spinner]").should("exist");
cy.get("[data-testid=delay-spinner]").should("not.exist");
cy.get(
`[data-testid=link-to-duration-${duration}] .render-paused`
).should("not.be.visible");
cy.getByTestId("delay-result").should(
"contain",
`Resource loaded in ${duration}ms`
);
} else {
// duration < delayMs -> should NOT show spinner - content will show in time
cy.get(
`[data-testid=link-to-duration-${duration}] .render-paused`
).should("be.visible");
cy.get(
`[data-testid=link-to-duration-${duration}] .render-paused`
).should("not.be.visible");
cy.get("[data-testid=delay-spinner]").should("not.exist");
cy.getByTestId("delay-result").should(
"contain",
`Resource loaded in ${duration}ms`
);
}
}
);
});
});
});
});