Skip to content

Commit

Permalink
need to fix test. animate when slide/drag is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
ybot1122 committed Nov 4, 2024
1 parent 5b2c228 commit e1e7f5d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/ReactFullpageSlideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export default function ReactFullpageSlideshow({
} else {
goToSlide(activeIndexRef.current - 1);
}
} else {
isAnimatingRef.current = true;
setIsAnimating(true);

setTimeout(() => {
isAnimatingRef.current = false;
setIsAnimating(false);
}, slideAnimationMs);
}
yOffsetRef.current = 0;
setYOffset(0);
Expand Down
14 changes: 12 additions & 2 deletions test/BasicTest.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import userEvent from "@testing-library/user-event";
import "@testing-library/jest-dom";
import { act, render, screen } from "@testing-library/react";
import { act, render, Screen, screen } from "@testing-library/react";
import React from "react";
import { App, assertSlidePosition } from "./utils";
import { App } from "./utils";

jest.useFakeTimers({ advanceTimers: true });

Expand Down Expand Up @@ -79,3 +79,13 @@ describe("BasicTest", () => {
});
});
});

const assertSlidePosition = (activeIndex: number, screen: Screen) => {
const slides = [0, 1, 2, 3, 4];
slides.map((ind) => {
const top = `calc(${(ind - activeIndex) * 100}vh + ${0}px)`;
expect(
screen.getByText(`slide ${ind + 1}`).parentNode.parentNode,
).toHaveStyle(`top: ${top}`);
});
};
14 changes: 12 additions & 2 deletions test/SwipeTest.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import { App, assertSlidePosition } from "./utils";
import { fireEvent, render, Screen, screen } from "@testing-library/react";
import { App } from "./utils";

jest.useRealTimers();

Expand All @@ -20,3 +20,13 @@ test("SwipeTest", async () => {

assertSlidePosition(1, screen);
});

const assertSlidePosition = (activeIndex: number, screen: Screen) => {
const slides = [0, 1, 2, 3, 4];
slides.map((ind) => {
const top = `calc(${(ind - activeIndex) * 100}vh + ${0}px)`;
expect(
screen.getByText(`slide ${ind + 1}`).parentNode.parentNode,
).toHaveStyle(`top: ${top}`);
});
};
11 changes: 0 additions & 11 deletions test/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { ReactFullpageSlideshow } from "../src";
import { rfsApi } from "../src/types";
import { Screen } from "@testing-library/dom";

export const App = () => {
return (
Expand All @@ -19,16 +18,6 @@ export const App = () => {
);
};

export const assertSlidePosition = (activeIndex: number, screen: Screen) => {
const slides = [0, 1, 2, 3, 4];
slides.map((ind) => {
const top = `calc(${(ind - activeIndex) * 100}vh + ${0}px)`;
expect(
screen.getByText(`slide ${ind + 1}`).parentNode.parentNode,
).toHaveStyle(`top: ${top}`);
});
};

const Slide = ({
goToSlide,
goToNextSlide,
Expand Down

0 comments on commit e1e7f5d

Please sign in to comment.