|
1 | | -import ContentfulVisual from "../../src"; |
| 1 | +import ContentfulVisual, { |
| 2 | + widthBasedImageLoader, |
| 3 | + widthBasedVideoLoader, |
| 4 | +} from "../../src"; |
2 | 5 | import { |
3 | 6 | imageAsset, |
4 | 7 | portraitImageAsset, |
@@ -49,7 +52,7 @@ describe("contentful asset props", () => { |
49 | 52 | }); |
50 | 53 |
|
51 | 54 | describe("contentful visual entry props", () => { |
52 | | - it("renders responsive images", () => { |
| 55 | + it("renders orientation based responsive images", () => { |
53 | 56 | cy.mount( |
54 | 57 | <ContentfulVisual |
55 | 58 | src={{ |
@@ -79,7 +82,7 @@ describe("contentful visual entry props", () => { |
79 | 82 | .should("contain", imageAsset.url); |
80 | 83 | }); |
81 | 84 |
|
82 | | - it("renders responsive videos", () => { |
| 85 | + it("renders orientation based responsive videos", () => { |
83 | 86 | cy.mount( |
84 | 87 | <ContentfulVisual |
85 | 88 | expand |
@@ -150,4 +153,54 @@ describe("contentful visual entry props", () => { |
150 | 153 | .invoke("attr", "aria-label") |
151 | 154 | .should("eq", "Background loop description"); |
152 | 155 | }); |
| 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 | + }); |
153 | 206 | }); |
0 commit comments