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

naver / egjs-flicking / 10557177632

26 Aug 2024 09:22AM UTC coverage: 38.327% (-44.5%) from 82.855%
10557177632

Pull #886

github

daybrush
fix: recalculate camera offset
Pull Request #886: fix: recalculate camera offset

2039 of 7372 branches covered (27.66%)

Branch coverage included in aggregate %.

11 of 29 new or added lines in 2 files covered. (37.93%)

5575 existing lines in 46 files now uncovered.

5099 of 11252 relevant lines covered (45.32%)

10.91 hits per line

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

19.77
/test/unit/control/FreeControl.spec.ts
1
import FlickingError from "~/core/FlickingError";
1✔
2
import FreeControl from "~/control/FreeControl";
1!
3
import * as ERROR from "~/const/error";
×
4
import { EVENTS, MOVE_TYPE } from "~/const/external";
×
5

6
import El from "../helper/El";
×
7
import { createFlicking, simulate, tick } from "../helper/test-util";
×
8

9
describe("FreeControl", () => {
1!
10
  describe("Methods", () => {
×
11
    describe("moveToPosition", () => {
12
      it("should be rejected returning FlickingError with code NOT_ATTACHED_TO_FLICKING if control is not initialized", async () => {
×
13
        const control = new FreeControl();
14

1✔
15
        expect(() => control.moveToPosition(0, 0))
1!
16
          .to.throw(FlickingError)
×
17
          .with.property("code", ERROR.CODE.NOT_ATTACHED_TO_FLICKING);
×
18
      });
×
19

×
20
      it("should be rejected returning FlickingError with code POSITION_NOT_REACHABLE when there are no panels exist", async () => {
21
        const flicking = await createFlicking(El.viewport().add(El.camera()), { moveType: MOVE_TYPE.FREE_SCROLL });
1✔
UNCOV
22
        const control = flicking.control;
×
UNCOV
23

×
UNCOV
24
        expect(control).to.be.an.instanceOf(FreeControl);
×
UNCOV
25

×
UNCOV
26
        try {
×
UNCOV
27
          await control.moveToPosition(500, 0);
×
28
          expect(true).to.be.false;
29
        } catch (err) {
30
          expect(err)
1✔
UNCOV
31
            .to.be.instanceOf(FlickingError)
×
UNCOV
32
            .with.property("code", ERROR.CODE.POSITION_NOT_REACHABLE);
×
UNCOV
33
        }
×
34
      });
UNCOV
35

×
UNCOV
36
      it(`should not trigger either ${EVENTS.WILL_CHANGE} or ${EVENTS.WILL_RESTORE} if active panel is not changed`, async () => {
×
UNCOV
37
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, {
×
UNCOV
38
          moveType: MOVE_TYPE.FREE_SCROLL,
×
UNCOV
39
          threshold: 100
×
UNCOV
40
        });
×
UNCOV
41
        const control = flicking.control;
×
42
        const prevActivePanel = control.activePanel;
×
43

×
44
        const changeSpy = sinon.spy();
UNCOV
45
        const restoreSpy = sinon.spy();
×
UNCOV
46

×
UNCOV
47
        flicking.on({
×
UNCOV
48
          [EVENTS.WILL_CHANGE]: changeSpy,
×
UNCOV
49
          [EVENTS.WILL_RESTORE]: restoreSpy
×
UNCOV
50
        });
×
51

UNCOV
52
        const promise = control.moveToPosition(control.activePanel.position + 1, 500);
×
UNCOV
53
        tick(1000);
×
UNCOV
54
        await promise;
×
55

56
        expect(control).to.be.an.instanceOf(FreeControl);
57
        expect(control.activePanel).to.equal(prevActivePanel);
1✔
58
        expect(changeSpy.called).to.be.false;
3!
59
        expect(restoreSpy.called).to.be.false;
60
      });
1✔
61

1✔
62
      it("should set target panel by clamping position to camera range even if it's further outside of camera range", async () => {
1✔
63
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, {
1✔
64
          moveType: MOVE_TYPE.FREE_SCROLL
1✔
65
        });
1✔
66
        const control = flicking.control;
1✔
67

1✔
68
        const promise = control.moveToPosition(999999999999999, 500);
1✔
69
        tick(1000);
1✔
70
        await promise;
1✔
71

UNCOV
72
        expect(control.activePanel).to.equal(flicking.getPanel(2));
×
UNCOV
73
      });
×
UNCOV
74

×
75
      it("anyway moves to the given position even if it's further outside of camera range if stopAtEdge is false", async () => {
76
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, {
UNCOV
77
          moveType: [MOVE_TYPE.FREE_SCROLL, { stopAtEdge: false }]
×
78
        });
79
        const control = flicking.control;
80
        const animateSpy = sinon.spy(control.controller, "animateTo");
1✔
81

UNCOV
82
        void control.moveToPosition(999999999999999, 500);
×
UNCOV
83

×
UNCOV
84
        expect(animateSpy.calledWith(999999999999999, 500)).to.be.true;
×
85
      });
UNCOV
86

×
UNCOV
87
      it("should not be rejected when user interrupted while animating with user input", async () => {
×
UNCOV
88
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, {
×
UNCOV
89
          moveType: MOVE_TYPE.FREE_SCROLL
×
90
        });
UNCOV
91

×
UNCOV
92
        const control = flicking.control;
×
93
        const changedSpy = sinon.spy();
UNCOV
94
        const moveToSpy = sinon.spy(control, "moveToPosition");
×
95
        flicking.on("changed", changedSpy);
×
96

×
97
        await simulate(flicking.element, { deltaX: -300, duration: 100 }, 150);
UNCOV
98
        await simulate(flicking.element, { deltaX: -300, duration: 100 });
×
UNCOV
99

×
100
        const err = await (moveToSpy.firstCall.returnValue.catch(error => error));
101

UNCOV
102
        expect(err).to.be.undefined;
×
UNCOV
103
        expect(changedSpy.calledOnce).to.be.true;
×
104
      });
105
    });
106
  });
107
});
1✔
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