Skip to content

Commit

Permalink
fix: add plugins after flicking is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
malangfox committed Jun 28, 2024
1 parent 66bcb7e commit 8b8f9e1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions test/unit/Arrow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe("Arrow", () => {
it("should interrupt ongoing animation when interruptable is true", async () => {
// Given
const plugin = new Arrow({ interruptable: true });
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);

// When
const nextArrow = flicking.element.querySelector(".flicking-arrow-next");
Expand All @@ -82,8 +82,8 @@ describe("Arrow", () => {
it("should not interrupt ongoing animation when interruptable is true", async () => {
// Given
const plugin = new Arrow({ interruptable: false });
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);

// When
const nextArrow = flicking.element.querySelector(".flicking-arrow-next");
Expand Down
16 changes: 8 additions & 8 deletions test/unit/AutoPlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe("AutoPlay", () => {
const playSpy = sinon.spy(plugin, "play");

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);

// Then
expect(playSpy.calledOnce).to.be.true;
Expand All @@ -39,8 +39,8 @@ describe("AutoPlay", () => {
nextStub.resolves(void 0);

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);

// Then
expect(nextStub.called).to.be.false;
Expand All @@ -55,8 +55,8 @@ describe("AutoPlay", () => {
const nextSpy = sinon.spy(flicking, "next");

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);

// Then
expect(nextSpy.called).to.be.false;
Expand Down Expand Up @@ -94,8 +94,8 @@ describe("AutoPlay", () => {
plugin.stop = stopSpy;

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);
const wrapper = flicking.element;

// Then
Expand All @@ -113,8 +113,8 @@ describe("AutoPlay", () => {
nextStub.resolves(void 0);

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);
const wrapper = flicking.element;

// Then
Expand All @@ -140,8 +140,8 @@ describe("AutoPlay", () => {
nextStub.resolves(void 0);

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);
const wrapper = flicking.element;

// Then
Expand Down Expand Up @@ -205,8 +205,8 @@ describe("AutoPlay", () => {
const flicking = new Flicking(createFlickingFixture());

// When
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);
const wrapper = flicking.element;

// Then
Expand Down Expand Up @@ -245,8 +245,8 @@ describe("AutoPlay", () => {
easing: x => x,
duration: 1000
});
flicking.addPlugins(plugin);
await waitEvent(flicking, "ready");
flicking.addPlugins(plugin);
const flickingWrapper = flicking.element;

await wait(500);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/Fade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ describe("Fade", () => {

it("should set opacity to 1 for current panel", async () => {
// Given & When
flicking.addPlugins(new Fade());
await waitEvent(flicking, "ready");
flicking.addPlugins(new Fade());

// Then
expect(flicking.currentPanel.element.style.opacity).to.equal("1");
});

it("should apply opacity to child elements if a selector is given", async () => {
// Given & When
flicking.addPlugins(new Fade("p"));
await waitEvent(flicking, "ready");
flicking.addPlugins(new Fade("p"));

// Then
const currentPanelEl = flicking.currentPanel.element;
Expand All @@ -59,8 +59,8 @@ describe("Fade", () => {

it("should be updated whenever flicking moves", async () => {
// Given
flicking.addPlugins(new Fade());
await waitEvent(flicking, "ready");
flicking.addPlugins(new Fade());

// When
void flicking.moveTo(1, 0);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/Perspective.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ describe("Perspective", () => {

it("should set transform to default for current panel", async () => {
// Given & When
flicking.addPlugins(new Perspective());
await waitEvent(flicking, "ready");
flicking.addPlugins(new Perspective());

// Then
expect(flicking.currentPanel.element.style.transform).to.equal("perspective(1000px) rotateX(0deg) rotateY(0deg) scale(1)");
});

it("should set transform to default that except perspective for current panel when allocated other arguments", async () => {
// Given & When
flicking.addPlugins(new Perspective({perspective: 500, rotate: 0.5, scale: 0.5}));
await waitEvent(flicking, "ready");
flicking.addPlugins(new Perspective({perspective: 500, rotate: 0.5, scale: 0.5}));

// Then
expect(flicking.currentPanel.element.style.transform).to.equal("perspective(500px) rotateX(0deg) rotateY(0deg) scale(1)");
});

it("should apply transform to child elements if a selector is given", async () => {
// Given & When
flicking.addPlugins(new Perspective({selector: "p"}));
await waitEvent(flicking, "ready");
flicking.addPlugins(new Perspective({selector: "p"}));

// Then
const currentPanelEl = flicking.currentPanel.element;
Expand All @@ -66,8 +66,8 @@ describe("Perspective", () => {

it("should be updated whenever flicking moves", async () => {
// Given
flicking.addPlugins(new Perspective());
await waitEvent(flicking, "ready");
flicking.addPlugins(new Perspective());

// When
void flicking.moveTo(1, 0);
Expand Down
10 changes: 5 additions & 5 deletions test/unit/Sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("Sync", () => {

it("main flicking should move with other flickings", async () => {
// Given
await waitEvent(flicking0, "ready");
flicking0.addPlugins(new Sync({
type: "camera",
synchronizedFlickingOptions: [
Expand All @@ -59,7 +60,6 @@ describe("Sync", () => {
}
]
}));
await waitEvent(flicking0, "ready");

// When
void flicking0.control.moveToPosition(500, 0);
Expand All @@ -71,6 +71,7 @@ describe("Sync", () => {

it("other flickings should move main flicking", async () => {
// Given
await waitEvent(flicking1, "ready");
flicking0.addPlugins(new Sync({
type: "camera",
synchronizedFlickingOptions: [
Expand All @@ -82,7 +83,6 @@ describe("Sync", () => {
}
]
}));
await waitEvent(flicking1, "ready");

// When
void flicking1.control.moveToPosition(1100, 0);
Expand All @@ -94,6 +94,7 @@ describe("Sync", () => {

it("active panel should have active class", async () => {
// Given
await waitEvent(flicking0, "ready");
flicking0.addPlugins(new Sync({
type: "index",
synchronizedFlickingOptions: [
Expand All @@ -107,7 +108,6 @@ describe("Sync", () => {
}
]
}));
await waitEvent(flicking0, "ready");

// When
void flicking0.moveTo(1, 0);
Expand All @@ -121,6 +121,7 @@ describe("Sync", () => {

it("slidable flicking should move other flickings", async () => {
// Given
await waitEvent(flicking0, "ready");
flicking0.addPlugins(new Sync({
type: "index",
synchronizedFlickingOptions: [
Expand All @@ -133,7 +134,6 @@ describe("Sync", () => {
}
]
}));
await waitEvent(flicking0, "ready");

// When
void flicking0.moveTo(2, 0);
Expand All @@ -146,6 +146,7 @@ describe("Sync", () => {

it("clickable flicking should move other flickings", async () => {
// Given
await waitEvent(flicking0, "ready");
flicking0.addPlugins(new Sync({
type: "index",
synchronizedFlickingOptions: [
Expand All @@ -158,7 +159,6 @@ describe("Sync", () => {
}
]
}));
await waitEvent(flicking0, "ready");

// When
await simulate(flicking0.panels[2].element, { deltaX: 0, deltaY: 0 });
Expand Down

0 comments on commit 8b8f9e1

Please sign in to comment.