-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #826 from frontity/amp-aware-image
Make the `Image` component AMP-aware
- Loading branch information
Showing
9 changed files
with
147 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@frontity/components": minor | ||
--- | ||
|
||
Make the Image component from `@frontity/components` AMP-aware and remove the Intersection Observer fallback which used to lazily load images in the absence of native lazy loading. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,23 @@ | ||
import expect from "expect"; | ||
|
||
describe("Image lazy-loading (with Intersection Observer)", () => { | ||
describe("Image lazy-loading (with native lazy-load)", () => { | ||
beforeEach(() => { | ||
cy.viewport(360, 640); | ||
cy.visit("http://localhost:3001?frontity_name=image", { | ||
onBeforeLoad(win) { | ||
// Remove the "loading" prop from the HTMLImageElement prototype | ||
Object.defineProperty(win.HTMLImageElement.prototype, "loading", { | ||
configurable: true, | ||
writable: true, | ||
}); | ||
// win.HTMLImageElement.prototype.loading = undefined; | ||
delete win.HTMLImageElement.prototype.loading; | ||
}, | ||
}); | ||
}); | ||
|
||
it("native lazy load should not exist", () => { | ||
return cy | ||
.window() | ||
.its("HTMLImageElement") | ||
.then((htmlImageElement) => { | ||
expect("loading" in htmlImageElement.prototype).toBe(false); | ||
}); | ||
}); | ||
|
||
it("should work scrolling from top to bottom", () => { | ||
cy.scrollTo("topLeft"); | ||
cy.get("img:not(.top.left)").should("not.be.visible"); | ||
cy.get("img.bottom.left") | ||
.scrollIntoView({ duration: 300 }) | ||
.should("be.visible"); | ||
cy.get("img.right").should("not.be.visible"); | ||
}); | ||
|
||
it("should work scrolling from bottom to top", () => { | ||
cy.scrollTo("bottomLeft"); | ||
cy.get("img:not(.bottom.left)").should("not.be.visible"); | ||
cy.get("img.top.left") | ||
.scrollIntoView({ duration: 300 }) | ||
.should("be.visible"); | ||
cy.get("img.right").should("not.be.visible"); | ||
cy.visit("http://localhost:3001?frontity_name=image"); | ||
}); | ||
|
||
it("should work scrolling from left to right", () => { | ||
it("should render an image with loading=lazy", () => { | ||
cy.scrollTo("topLeft"); | ||
cy.get("img:not(.bottom.left)").should("not.be.visible"); | ||
cy.get("img.top.right") | ||
.scrollIntoView({ duration: 300 }) | ||
.should("be.visible"); | ||
cy.get("img.bottom").should("not.be.visible"); | ||
cy.get("img[height]").should("have.attr", "loading", "lazy"); | ||
}); | ||
}); | ||
|
||
describe("Image lazy-loading (with native lazy-load)", () => { | ||
describe("amp-image", () => { | ||
beforeEach(() => { | ||
cy.viewport(360, 640); | ||
cy.visit("http://localhost:3001?frontity_name=image"); | ||
cy.visit("http://localhost:3001/amp-image/?frontity_name=amp-image"); | ||
}); | ||
|
||
it("should render an image without loading if it doesn't have height", () => { | ||
it("should render an amp-image", () => { | ||
cy.scrollTo("topLeft"); | ||
cy.get("img:not([height])").should("not.have.attr", "loading"); | ||
cy.get("img:not([height])").should("not.be.visible"); | ||
cy.get("img:not([height])") | ||
.scrollIntoView({ duration: 300 }) | ||
.should("be.visible"); | ||
}); | ||
|
||
it("should render an image with loading=lazy if it has a height", () => { | ||
cy.scrollTo("topLeft"); | ||
cy.get("img[height]").should("have.attr", "loading", "lazy"); | ||
cy.get("amp-img[height]").should("have.attr", "layout", "fill"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 0 additions & 172 deletions
172
packages/components/__tests__/__snapshots__/image.jsdom.tests.tsx.snap
This file was deleted.
Oops, something went wrong.
115 changes: 0 additions & 115 deletions
115
packages/components/__tests__/__snapshots__/image.node.tests.tsx.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.