|
1 | 1 | describe(
|
2 |
| - `remote-file`, |
| 2 | + `remote-file`, |
3 | 3 | {
|
4 | 4 | retries: {
|
5 | 5 | runMode: 4,
|
6 | 6 | },
|
7 | 7 | },
|
8 | 8 | () => {
|
9 |
| - beforeEach(() => { |
10 |
| - cy.visit(`/remote-file/`).waitForRouteChange() |
| 9 | + beforeEach(() => { |
| 10 | + cy.visit(`/remote-file/`).waitForRouteChange() |
11 | 11 |
|
12 |
| - // trigger intersection observer |
13 |
| - cy.scrollTo("top") |
14 |
| - cy.wait(100) |
15 |
| - cy.scrollTo("bottom", { |
16 |
| - duration: 500, |
17 |
| - }) |
18 |
| - cy.wait(500) |
19 |
| - }) |
20 |
| - |
21 |
| - async function testImages(images, expectations) { |
22 |
| - for (let i = 0; i < images.length; i++) { |
23 |
| - const expectation = expectations[i] |
24 |
| - |
25 |
| - const res = await fetch(images[i].currentSrc, { |
26 |
| - method: "HEAD", |
| 12 | + // trigger intersection observer |
| 13 | + cy.scrollTo("top") |
| 14 | + cy.wait(100) |
| 15 | + cy.scrollTo("bottom", { |
| 16 | + duration: 500, |
27 | 17 | })
|
28 |
| - expect(res.ok).to.be.true |
29 |
| - if (expectation.width) { |
30 |
| - expect(Math.ceil(images[i].getBoundingClientRect().width)).to.be.equal( |
31 |
| - expectation.width |
32 |
| - ) |
33 |
| - } |
34 |
| - if (expectation.height) { |
35 |
| - expect(Math.ceil(images[i].getBoundingClientRect().height)).to.be.equal( |
36 |
| - expectation.height |
37 |
| - ) |
38 |
| - } |
39 |
| - } |
40 |
| - } |
| 18 | + cy.wait(500) |
| 19 | + }) |
41 | 20 |
|
42 |
| - it(`should render correct dimensions`, () => { |
43 |
| - cy.get('[data-testid="public"]').then(async $urls => { |
44 |
| - const urls = Array.from($urls.map((_, $url) => $url.getAttribute("href"))) |
| 21 | + async function testImages(images, expectations) { |
| 22 | + for (let i = 0; i < images.length; i++) { |
| 23 | + const expectation = expectations[i] |
45 | 24 |
|
46 |
| - for (const url of urls) { |
47 |
| - const res = await fetch(url, { |
| 25 | + const res = await fetch(images[i].currentSrc, { |
48 | 26 | method: "HEAD",
|
49 | 27 | })
|
50 | 28 | expect(res.ok).to.be.true
|
| 29 | + if (expectation.width) { |
| 30 | + expect( |
| 31 | + Math.ceil(images[i].getBoundingClientRect().width) |
| 32 | + ).to.be.equal(expectation.width) |
| 33 | + } |
| 34 | + if (expectation.height) { |
| 35 | + expect( |
| 36 | + Math.ceil(images[i].getBoundingClientRect().height) |
| 37 | + ).to.be.equal(expectation.height) |
| 38 | + } |
51 | 39 | }
|
52 |
| - }) |
53 |
| - |
54 |
| - cy.get(".resize").then(async $imgs => { |
55 |
| - await testImages(Array.from($imgs), [ |
56 |
| - { |
57 |
| - width: 100, |
58 |
| - height: 133, |
59 |
| - }, |
60 |
| - { |
61 |
| - width: 100, |
62 |
| - height: 160, |
63 |
| - }, |
64 |
| - { |
65 |
| - width: 100, |
66 |
| - height: 67, |
67 |
| - }, |
68 |
| - ]) |
69 |
| - }) |
| 40 | + } |
70 | 41 |
|
71 |
| - cy.get(".fixed").then(async $imgs => { |
72 |
| - await testImages(Array.from($imgs), [ |
73 |
| - { |
74 |
| - width: 100, |
75 |
| - height: 133, |
76 |
| - }, |
77 |
| - { |
78 |
| - width: 100, |
79 |
| - height: 160, |
80 |
| - }, |
81 |
| - { |
82 |
| - width: 100, |
83 |
| - height: 67, |
84 |
| - }, |
85 |
| - ]) |
86 |
| - }) |
| 42 | + it(`should render correct dimensions`, () => { |
| 43 | + cy.get('[data-testid="public"]').then(async $urls => { |
| 44 | + const urls = Array.from( |
| 45 | + $urls.map((_, $url) => $url.getAttribute("href")) |
| 46 | + ) |
87 | 47 |
|
88 |
| - cy.get(".constrained").then(async $imgs => { |
89 |
| - await testImages(Array.from($imgs), [ |
90 |
| - { |
91 |
| - width: 300, |
92 |
| - height: 400, |
93 |
| - }, |
94 |
| - { |
95 |
| - width: 300, |
96 |
| - height: 481, |
97 |
| - }, |
98 |
| - { |
99 |
| - width: 300, |
100 |
| - height: 200, |
101 |
| - }, |
102 |
| - ]) |
103 |
| - }) |
| 48 | + for (const url of urls) { |
| 49 | + const res = await fetch(url, { |
| 50 | + method: "HEAD", |
| 51 | + }) |
| 52 | + expect(res.ok).to.be.true |
| 53 | + } |
| 54 | + }) |
104 | 55 |
|
105 |
| - cy.get(".full").then(async $imgs => { |
106 |
| - await testImages(Array.from($imgs), [ |
107 |
| - { |
108 |
| - height: 1229, |
109 |
| - }, |
110 |
| - { |
111 |
| - height: 1478, |
112 |
| - }, |
113 |
| - { |
114 |
| - height: 614, |
115 |
| - }, |
116 |
| - ]) |
117 |
| - }) |
118 |
| - }) |
| 56 | + cy.get(".resize").then(async $imgs => { |
| 57 | + await testImages(Array.from($imgs), [ |
| 58 | + { |
| 59 | + width: 100, |
| 60 | + height: 133, |
| 61 | + }, |
| 62 | + { |
| 63 | + width: 100, |
| 64 | + height: 160, |
| 65 | + }, |
| 66 | + { |
| 67 | + width: 100, |
| 68 | + height: 67, |
| 69 | + }, |
| 70 | + ]) |
| 71 | + }) |
119 | 72 |
|
120 |
| - it(`should render a placeholder`, () => { |
121 |
| - cy.get(".fixed [data-placeholder-image]") |
122 |
| - .first() |
123 |
| - .should("have.css", "background-color", "rgb(232, 184, 8)") |
124 |
| - cy.get(".constrained [data-placeholder-image]") |
125 |
| - .first() |
126 |
| - .should($el => { |
127 |
| - expect($el.prop("tagName")).to.be.equal("IMG") |
128 |
| - expect($el.prop("src")).to.contain("data:image/jpg;base64") |
| 73 | + cy.get(".fixed").then(async $imgs => { |
| 74 | + await testImages(Array.from($imgs), [ |
| 75 | + { |
| 76 | + width: 100, |
| 77 | + height: 133, |
| 78 | + }, |
| 79 | + { |
| 80 | + width: 100, |
| 81 | + height: 160, |
| 82 | + }, |
| 83 | + { |
| 84 | + width: 100, |
| 85 | + height: 67, |
| 86 | + }, |
| 87 | + ]) |
129 | 88 | })
|
130 |
| - cy.get(".constrained_traced [data-placeholder-image]") |
131 |
| - .first() |
132 |
| - .should($el => { |
133 |
| - expect($el.prop("tagName")).to.be.equal("IMG") |
134 |
| - expect($el.prop("src")).to.contain("data:image/svg+xml,%3csvg") |
| 89 | + |
| 90 | + cy.get(".constrained").then(async $imgs => { |
| 91 | + await testImages(Array.from($imgs), [ |
| 92 | + { |
| 93 | + width: 300, |
| 94 | + height: 400, |
| 95 | + }, |
| 96 | + { |
| 97 | + width: 300, |
| 98 | + height: 481, |
| 99 | + }, |
| 100 | + { |
| 101 | + width: 300, |
| 102 | + height: 200, |
| 103 | + }, |
| 104 | + ]) |
135 | 105 | })
|
136 |
| - cy.get(".full [data-placeholder-image]") |
137 |
| - .first() |
138 |
| - .should($el => { |
139 |
| - expect($el.prop("tagName")).to.be.equal("DIV") |
140 |
| - expect($el).to.be.empty |
| 106 | + |
| 107 | + cy.get(".full").then(async $imgs => { |
| 108 | + await testImages(Array.from($imgs), [ |
| 109 | + { |
| 110 | + height: 1229, |
| 111 | + }, |
| 112 | + { |
| 113 | + height: 1478, |
| 114 | + }, |
| 115 | + { |
| 116 | + height: 614, |
| 117 | + }, |
| 118 | + ]) |
141 | 119 | })
|
142 |
| - }) |
143 |
| -}) |
| 120 | + }) |
| 121 | + |
| 122 | + it(`should render a placeholder`, () => { |
| 123 | + cy.get(".fixed [data-placeholder-image]") |
| 124 | + .first() |
| 125 | + .should("have.css", "background-color", "rgb(232, 184, 8)") |
| 126 | + cy.get(".constrained [data-placeholder-image]") |
| 127 | + .first() |
| 128 | + .should($el => { |
| 129 | + expect($el.prop("tagName")).to.be.equal("IMG") |
| 130 | + expect($el.prop("src")).to.contain("data:image/jpg;base64") |
| 131 | + }) |
| 132 | + cy.get(".constrained_traced [data-placeholder-image]") |
| 133 | + .first() |
| 134 | + .should($el => { |
| 135 | + // traced falls back to DOMINANT_COLOR |
| 136 | + expect($el.prop("tagName")).to.be.equal("DIV") |
| 137 | + expect($el).to.be.empty |
| 138 | + }) |
| 139 | + cy.get(".full [data-placeholder-image]") |
| 140 | + .first() |
| 141 | + .should($el => { |
| 142 | + expect($el.prop("tagName")).to.be.equal("DIV") |
| 143 | + expect($el).to.be.empty |
| 144 | + }) |
| 145 | + }) |
| 146 | + } |
| 147 | +) |
0 commit comments