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