|
| 1 | +describe("AnimateView entry point", () => { |
| 2 | + it("keeps ordinary Motion working and reports unsupported React versions", () => { |
| 3 | + cy.visit("?test=animate-view") |
| 4 | + cy.get("#ordinary").should("have.css", "opacity", "0.5") |
| 5 | + cy.get("#ordinary").then(($ordinary) => { |
| 6 | + if ($ordinary.text().includes("React 19")) { |
| 7 | + cy.get("#supported").should("have.text", "true") |
| 8 | + } |
| 9 | + }) |
| 10 | + cy.get("#supported").then(($supported) => { |
| 11 | + if ($supported.text() === "true") return |
| 12 | + cy.on("uncaught:exception", (error) => { |
| 13 | + if (error.message.includes("AnimateView requires React 19.3")) |
| 14 | + return false |
| 15 | + }) |
| 16 | + cy.get("#toggle").click() |
| 17 | + cy.get("#error").should( |
| 18 | + "contain", |
| 19 | + "AnimateView requires React 19.3" |
| 20 | + ) |
| 21 | + }) |
| 22 | + }) |
| 23 | + |
| 24 | + for (const mode of ["default", "custom", "share", "update"]) { |
| 25 | + it(`animates ${mode} views with Motion timing`, () => { |
| 26 | + cy.visit(`?test=animate-view&mode=${mode}`) |
| 27 | + cy.get("#supported").then(($supported) => { |
| 28 | + // React 18 exercises import safety and the version error above. |
| 29 | + if ($supported.text() !== "true") return |
| 30 | + cy.document().then((doc) => { |
| 31 | + expect(typeof (doc as any).startViewTransition).to.equal( |
| 32 | + "function" |
| 33 | + ) |
| 34 | + }) |
| 35 | + cy.get("#toggle").click() |
| 36 | + const type = |
| 37 | + mode === "share" || mode === "update" ? mode : "enter" |
| 38 | + cy.get("#events") |
| 39 | + .should("have.attr", `data-${type}`) |
| 40 | + .then((data) => { |
| 41 | + const event = JSON.parse(data as unknown as string) |
| 42 | + expect(event.duration).to.be.closeTo(0.4, 0.01) |
| 43 | + expect(event.count).to.be.greaterThan(0) |
| 44 | + if (mode === "custom") expect(event.count).to.equal(1) |
| 45 | + }) |
| 46 | + cy.get("#events").should( |
| 47 | + "have.attr", |
| 48 | + `data-${type}-complete`, |
| 49 | + "true" |
| 50 | + ) |
| 51 | + if (type === "enter") { |
| 52 | + cy.get("#toggle").click() |
| 53 | + cy.get("#events").should( |
| 54 | + "have.attr", |
| 55 | + "data-exit-complete", |
| 56 | + "true" |
| 57 | + ) |
| 58 | + cy.get("#view").should("not.exist") |
| 59 | + } |
| 60 | + }) |
| 61 | + }) |
| 62 | + } |
| 63 | +}) |
0 commit comments