• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

naver / egjs-flicking / 11944947852

21 Nov 2024 01:37AM UTC coverage: 40.509% (-42.4%) from 82.888%
11944947852

Pull #901

github

web-flow
Merge c469ddcae into c106ab483
Pull Request #901: feat: add CrossFlicking Preset

2294 of 7653 branches covered (29.98%)

Branch coverage included in aggregate %.

319 of 380 new or added lines in 11 files covered. (83.95%)

5581 existing lines in 49 files now uncovered.

5570 of 11760 relevant lines covered (47.36%)

12.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.59
/test/unit/control/Control.spec.ts
1
import { OnRelease } from "@egjs/axes";
1✔
2

1✔
3
import FlickingError from "~/core/FlickingError";
1✔
4
import Control from "~/control/Control";
1!
5
import AxesController from "~/control/AxesController";
×
6
import { DIRECTION, EVENTS } from "~/const/external";
×
7
import * as ERROR from "~/const/error";
1✔
8

9
import { createFlicking, createPanel, simulate, tick } from "../helper/test-util";
1✔
10
import El from "../helper/El";
1!
11
import Panel from "~/core/panel/Panel";
×
12
import { ValueOf } from "~/type/internal";
1✔
13

1✔
14
class ControlImpl extends Control {
1!
15
  public moveToPosition(position: number, duration: number, axesEvent?: OnRelease): Promise<void> {
16
    return Promise.resolve();
17
  }
1!
18

×
19
  public moveToPanel(panel: Panel, {
×
20
    duration,
21
    direction = DIRECTION.NONE,
×
22
    axesEvent
×
23
  }: {
24
    duration: number;
1!
25
    direction?: ValueOf<typeof DIRECTION>;
×
26
    axesEvent?: OnRelease;
27
  }) {
×
28
    const promise = super.moveToPanel(panel, { duration, direction, axesEvent });
29

1✔
30
    tick(10000);
1!
31

×
32
    return promise;
×
33
  }
×
34

×
35
  public async moveToPanelWithInterruption(panel: Panel, duration: number, axesEvent?: OnRelease): Promise<void> {
36
    const promise = super.moveToPanel(panel, { duration, axesEvent });
1✔
UNCOV
37

×
UNCOV
38
    tick(duration / 2);
×
UNCOV
39
    await simulate((panel as any)._flicking.element);
×
40

×
UNCOV
41
    return promise;
×
UNCOV
42
  }
×
43
}
44

45
describe("Control", () => {
1✔
UNCOV
46
  describe("properties", () => {
×
UNCOV
47
    it("should have controller as AxesController", () => {
×
UNCOV
48
      expect(new ControlImpl().controller).to.be.an.instanceOf(AxesController);
×
49
    });
UNCOV
50

×
UNCOV
51
    it("should have activeIndex as -1", () => {
×
UNCOV
52
      expect(new ControlImpl().activeIndex).to.equal(-1);
×
UNCOV
53
    });
×
UNCOV
54

×
UNCOV
55
    it("should have activePanel as null", () => {
×
UNCOV
56
      expect(new ControlImpl().activePanel).to.equal(null);
×
57
    });
×
58

×
59
    it("is not animating by default", () => {
UNCOV
60
      expect(new ControlImpl().animating).to.be.false;
×
61
    });
×
62

×
63
    it("is not holding by default", () => {
×
64
      expect(new ControlImpl().holding).to.be.false;
×
65
    });
×
66
  });
UNCOV
67

×
UNCOV
68
  describe("Methods", () => {
×
UNCOV
69
    describe("init", () => {
×
70
      it("should also call init of the controller", async () => {
71
        const control = new ControlImpl();
72
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
1✔
73
        const initSpy = sinon.spy(control.controller, "init");
4!
74

75
        control.init(flicking);
1✔
76

1✔
77
        expect(initSpy.calledOnceWith(flicking)).to.be.true;
1✔
78
      });
1✔
79
    });
1✔
80

1✔
81
    describe("enable", () => {
1✔
82
      it("should call enable of the controller", () => {
1✔
83
        const control = new ControlImpl();
1✔
84
        control.disable();
1✔
85

UNCOV
86
        const enableSpy = sinon.spy(control.controller, "enable");
×
87
        control.enable();
88

1✔
89
        expect(enableSpy.calledOnce).to.be.true;
×
90
      });
91
    });
1✔
UNCOV
92

×
UNCOV
93
    describe("disable", () => {
×
UNCOV
94
      it("should call disable of the controller", () => {
×
UNCOV
95
        const control = new ControlImpl();
×
96
        const disableSpy = sinon.spy();
97

1✔
UNCOV
98
        control.controller.disable = disableSpy;
×
99
        control.disable();
UNCOV
100

×
UNCOV
101
        expect(disableSpy.calledOnce).to.be.true;
×
102
      });
UNCOV
103
    });
×
UNCOV
104

×
UNCOV
105
    describe("release", () => {
×
106
      it("should call release of the controller", () => {
UNCOV
107
        const control = new ControlImpl();
×
UNCOV
108
        const releaseSpy = sinon.spy();
×
109

110
        control.controller.release = releaseSpy;
111
        control.release();
112

113
        expect(releaseSpy.calledOnce).to.be.true;
1✔
114
      });
115
    });
1✔
116

1✔
117
    describe("updateInput", () => {
1✔
UNCOV
118
      it("should call update of the controller", async () => {
×
119
        const control = new ControlImpl();
120
        const updateSpy = sinon.spy(control.controller, "update");
1✔
UNCOV
121

×
122
        control.init(await createFlicking(El.DEFAULT_HORIZONTAL));
123
        control.updateInput();
1✔
UNCOV
124

×
125
        expect(updateSpy.calledOnce).to.be.true;
126
      });
1✔
UNCOV
127

×
128
      it("should be throw FlickingError with code NOT_ATTACHED_TO_FLICKING if control is not initialized", () => {
129
        const control = new ControlImpl();
1✔
UNCOV
130

×
131
        expect(() => control.updateInput())
132
          .to.throw(FlickingError)
133
          .with.property("code", ERROR.CODE.NOT_ATTACHED_TO_FLICKING);
1✔
134
      });
1✔
135
    });
1✔
136

UNCOV
137
    describe("moveToPanel", () => {
×
UNCOV
138
      it("should be rejected returning FlickingError with code NOT_ATTACHED_TO_FLICKING if control is not initialized", async () => {
×
139
        const control = new ControlImpl();
UNCOV
140

×
UNCOV
141
        const err = await control.moveToPanel(await createPanel(El.panel()), { duration: 500 }).catch(e => e);
×
142

UNCOV
143
        expect(err)
×
UNCOV
144
          .to.be.instanceOf(FlickingError)
×
UNCOV
145
          .with.property("code", ERROR.CODE.NOT_ATTACHED_TO_FLICKING);
×
UNCOV
146
      });
×
UNCOV
147

×
148
      it("should change activePanel to given panel after resolved", async () => {
149
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
150
        const control = flicking.control;
151
        const panel = flicking.getPanel(2);
152
        const activePanelBefore = control.activePanel;
1✔
153

1✔
UNCOV
154
        void control.moveToPanel(panel, { duration: 500 });
×
UNCOV
155
        tick(1500);
×
UNCOV
156
        const activePanelAfter = control.activePanel;
×
UNCOV
157

×
UNCOV
158
        expect(activePanelBefore).to.equal(flicking.getPanel(0));
×
159
        expect(activePanelAfter).to.equal(panel);
160
      });
161

1✔
162
      it("should change activePanel to given panel after resolved when duration is 0", async () => {
1✔
UNCOV
163
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
×
UNCOV
164
        const control = flicking.control;
×
UNCOV
165
        const panel = flicking.getPanel(2);
×
UNCOV
166
        const activePanelBefore = control.activePanel;
×
UNCOV
167

×
168
        void control.moveToPanel(panel, { duration: 0 });
169
        const activePanelAfter = control.activePanel;
170

1✔
171
        expect(activePanelBefore).to.equal(flicking.getPanel(0));
1✔
UNCOV
172
        expect(activePanelAfter).to.equal(panel);
×
UNCOV
173
      });
×
UNCOV
174

×
UNCOV
175
      it("should change activePanel to given panel after resolved when duration is 0 and moving to the same position", async () => {
×
UNCOV
176
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
×
177
        const control = flicking.control;
178

179
        control.setActive(flicking.panels[2], flicking.panels[0], false);
1✔
180
        const activePanelBefore = control.activePanel;
1✔
181
        void control.moveToPanel(flicking.panels[0], { duration: 0 });
UNCOV
182
        const activePanelAfter = control.activePanel;
×
UNCOV
183

×
184
        expect(activePanelBefore).to.equal(flicking.getPanel(2));
UNCOV
185
        expect(activePanelAfter).to.equal(flicking.getPanel(0));
×
UNCOV
186
      });
×
UNCOV
187

×
UNCOV
188
      it(`should trigger ${EVENTS.WILL_CHANGE} if active panel was null`, async () => {
×
189
        const control = new ControlImpl();
UNCOV
190
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
×
UNCOV
191
        const changeSpy = sinon.spy();
×
UNCOV
192
        const restoreSpy = sinon.spy();
×
UNCOV
193
        flicking.on(EVENTS.WILL_CHANGE, changeSpy);
×
194
        flicking.on(EVENTS.WILL_RESTORE, restoreSpy);
195

196
        control.init(flicking);
197
        control.updateInput();
1✔
UNCOV
198

×
UNCOV
199
        await control.moveToPanel(flicking.getPanel(2), { duration: 500 });
×
200

201
        expect(changeSpy.calledOnce).to.be.true;
202
        expect(restoreSpy.called).to.be.false;
203
      });
204

1✔
205
      it(`should trigger ${EVENTS.WILL_CHANGE} if given panel is not same to active panel`, async () => {
1✔
206
        const control = new ControlImpl();
UNCOV
207
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
×
UNCOV
208

×
209
        control.init(flicking);
UNCOV
210
        control.updateInput();
×
UNCOV
211
        await control.moveToPanel(flicking.getPanel(1), { duration: 0 });
×
UNCOV
212

×
UNCOV
213
        const changeSpy = sinon.spy();
×
214
        const restoreSpy = sinon.spy();
UNCOV
215
        flicking.on(EVENTS.WILL_CHANGE, changeSpy);
×
UNCOV
216
        flicking.on(EVENTS.WILL_RESTORE, restoreSpy);
×
217

218
        await control.moveToPanel(flicking.getPanel(2), { duration: 500 });
UNCOV
219

×
220
        expect(changeSpy.calledOnce).to.be.true;
221
        expect(restoreSpy.called).to.be.false;
222
      });
223

1✔
224
      it(`should trigger ${EVENTS.WILL_RESTORE} if give panel is same to active panel`, async () => {
UNCOV
225
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, { defaultIndex: 1 });
×
UNCOV
226
        const control = flicking.control;
×
UNCOV
227
        const changeSpy = sinon.spy();
×
228
        const restoreSpy = sinon.spy();
UNCOV
229

×
UNCOV
230
        flicking.on(EVENTS.WILL_CHANGE, changeSpy);
×
UNCOV
231
        flicking.on(EVENTS.WILL_RESTORE, restoreSpy);
×
UNCOV
232
        await control.moveToPanel(flicking.getPanel(1), { duration: 500 });
×
UNCOV
233

×
UNCOV
234
        expect(changeSpy.calledOnce).to.be.false;
×
UNCOV
235
        expect(restoreSpy.calledOnce).to.be.true;
×
UNCOV
236
      });
×
UNCOV
237

×
UNCOV
238
      it(`should be rejected with FlickingError with STOP_CALLED_BY_USER as code when stop() is called from ${EVENTS.WILL_CHANGE} event`, async () => {
×
239
        const control = new ControlImpl();
240
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
241
        flicking.on(EVENTS.WILL_CHANGE, e => e.stop());
242

1✔
243
        control.init(flicking);
UNCOV
244
        control.updateInput();
×
UNCOV
245

×
UNCOV
246
        const err = await control.moveToPanel(flicking.getPanel(1), { duration: 500 }).catch(e => e);
×
247

UNCOV
248
        expect(err)
×
UNCOV
249
          .to.be.instanceOf(FlickingError)
×
UNCOV
250
          .with.property("code", ERROR.CODE.STOP_CALLED_BY_USER);
×
UNCOV
251
      });
×
UNCOV
252

×
UNCOV
253
      it(`should be rejected with FlickingError with STOP_CALLED_BY_USER as code when stop() is called from ${EVENTS.WILL_RESTORE} event`, async () => {
×
UNCOV
254
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, { defaultIndex: 1 });
×
UNCOV
255
        const control = flicking.control;
×
UNCOV
256

×
257
        flicking.on(EVENTS.WILL_RESTORE, e => e.stop());
258

259
        const err = await control.moveToPanel(flicking.getPanel(1), { duration: 500 }).catch(e => e);
260

1✔
261
        expect(err)
UNCOV
262
          .to.be.instanceOf(FlickingError)
×
UNCOV
263
          .with.property("code", ERROR.CODE.STOP_CALLED_BY_USER);
×
UNCOV
264
      });
×
265

UNCOV
266
      it("should be rejected when user interrupted while animating", async () => {
×
UNCOV
267
        const control = new ControlImpl();
×
UNCOV
268
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);
×
UNCOV
269

×
UNCOV
270
        control.init(flicking);
×
UNCOV
271
        control.updateInput();
×
UNCOV
272

×
UNCOV
273
        const err = await control.moveToPanelWithInterruption(flicking.getPanel(2), 1000).catch(e => e);
×
UNCOV
274

×
275
        expect(err)
276
          .to.be.instanceOf(FlickingError)
277
          .with.property("code", ERROR.CODE.ANIMATION_INTERRUPTED);
278
      });
1✔
279
    });
UNCOV
280
  });
×
UNCOV
281
});
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc