Skip to content

Commit 4af2cbc

Browse files
committed
Add tests of width based loaders
1 parent ea11fb9 commit 4af2cbc

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

packages/contentful/cypress/component/ContentfulVisual.cy.tsx

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import ContentfulVisual from "../../src";
1+
import ContentfulVisual, {
2+
widthBasedImageLoader,
3+
widthBasedVideoLoader,
4+
} from "../../src";
25
import {
36
imageAsset,
47
portraitImageAsset,
@@ -49,7 +52,7 @@ describe("contentful asset props", () => {
4952
});
5053

5154
describe("contentful visual entry props", () => {
52-
it("renders responsive images", () => {
55+
it("renders orientation based responsive images", () => {
5356
cy.mount(
5457
<ContentfulVisual
5558
src={{
@@ -79,7 +82,7 @@ describe("contentful visual entry props", () => {
7982
.should("contain", imageAsset.url);
8083
});
8184

82-
it("renders responsive videos", () => {
85+
it("renders orientation based responsive videos", () => {
8386
cy.mount(
8487
<ContentfulVisual
8588
expand
@@ -150,4 +153,54 @@ describe("contentful visual entry props", () => {
150153
.invoke("attr", "aria-label")
151154
.should("eq", "Background loop description");
152155
});
156+
157+
it("renders width based responsive images", () => {
158+
cy.mount(
159+
<ContentfulVisual
160+
expand
161+
src={{
162+
...visualEntry,
163+
video: null,
164+
portraitVideo: null,
165+
}}
166+
sourceMedia={["(min-width:400px)", "(max-width:399px)"]}
167+
imageLoader={widthBasedImageLoader}
168+
/>
169+
);
170+
171+
// Portrait asset
172+
cy.viewport(399, 500);
173+
cy.get("img")
174+
.its("[0].currentSrc")
175+
.should("contain", portraitImageAsset.url);
176+
177+
// Landscape asset
178+
cy.viewport(400, 500);
179+
cy.get("img").its("[0].currentSrc").should("contain", imageAsset.url);
180+
});
181+
182+
it("renders width based responsive videos", () => {
183+
cy.mount(
184+
<ContentfulVisual
185+
expand
186+
src={{
187+
...visualEntry,
188+
image: null,
189+
portraitImage: null,
190+
}}
191+
sourceMedia={["(min-width:400px)", "(max-width:399px)"]}
192+
videoLoader={widthBasedVideoLoader}
193+
/>
194+
);
195+
196+
// Portrait asset
197+
cy.viewport(399, 500);
198+
cy.get("video")
199+
.its("[0].currentSrc")
200+
.should("contain", portraitVideoAsset.url);
201+
202+
// Landscape asset
203+
cy.viewport(400, 500);
204+
cy.get("video").its("[0].currentSrc").should("contain", videoAsset.url);
205+
});
153206
});

0 commit comments

Comments
 (0)