• 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

14.72
/test/unit/camera/mode/CircularCameraMode.spec.ts
1
import CircularCameraMode from "~/camera/mode/CircularCameraMode";
1✔
2

1✔
UNCOV
3
import { createFlicking, createPanel } from "../../helper/test-util";
×
UNCOV
4
import El from "../../helper/El";
×
UNCOV
5

×
6
describe("CircularCamera", () => {
×
UNCOV
7
  describe("Methods", () => {
×
UNCOV
8
    describe("findAnchorIncludePosition", () => {
×
9
      it("should return panel at toggled position if circular is enabled", async () => {
10
        const { camera, panels } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
11

1✔
UNCOV
12
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
UNCOV
13
        expect(camera.mode.findAnchorIncludePosition(panels[2].range.max + 1).panel).to.equal(panels[0]);
×
UNCOV
14
        expect(camera.mode.findAnchorIncludePosition(panels[0].range.min - 1).panel).to.equal(panels[2]);
×
15
      });
UNCOV
16

×
UNCOV
17
      it("should return panel at toggled position if the given position is same to the camera range max", async () => {
×
UNCOV
18
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
×
UNCOV
19

×
UNCOV
20
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
UNCOV
21
        expect(camera.mode.findAnchorIncludePosition(camera.range.max).index).to.equal(0);
×
UNCOV
22
      });
×
23

×
24
      it("should return panel at toggled position if the given position is same to the camera range min", async () => {
×
25
        const { camera, panelCount } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
UNCOV
26

×
27
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
28
        expect(camera.mode.findAnchorIncludePosition(camera.range.min).index).to.equal(panelCount - 1);
×
29
      });
×
30
    });
×
31

×
32
    describe("clampToReachablePosition", () => {
UNCOV
33
      it("should return position itself even it's over range when circular can be enabled", async () => {
×
UNCOV
34
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
×
UNCOV
35

×
36
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
37
        expect(camera.controlParams.circular).to.be.true;
38
        expect(camera.clampToReachablePosition(camera.range.max + 1))
1✔
39
          .to.equal(camera.range.max + 1);
2!
40
        expect(camera.clampToReachablePosition(camera.range.min - 1))
41
          .to.equal(camera.range.min - 1);
1✔
42
      });
1✔
43
    });
1✔
44

1✔
45
    describe("canReach", () => {
1✔
46
      it("should always return true for any panel when circular is enabled", async () => {
1✔
47
        const flicking = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
1✔
48
        const camera = flicking.camera;
1✔
49
        const panel = flicking.getPanel(0);
UNCOV
50

×
UNCOV
51
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
UNCOV
52

×
53
        sinon.stub(panel, "position")
UNCOV
54
          .get(() => camera.range.max + 1);
×
UNCOV
55

×
UNCOV
56
        expect(camera.canReach(panel)).to.be.true;
×
UNCOV
57

×
UNCOV
58
        sinon.stub(panel, "position")
×
59
          .get(() => camera.range.min - 1);
60

61
        expect(camera.canReach(panel)).to.be.true;
62
      });
1✔
63
    });
UNCOV
64

×
UNCOV
65
    describe("canSee", () => {
×
UNCOV
66
      it("should return true when panel is visible on looped position is included if circular is enabled", async () => {
×
67
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
UNCOV
68
        const panel = await createPanel(El.panel());
×
UNCOV
69
        const camRange = camera.range;
×
UNCOV
70

×
UNCOV
71
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
72

73
        camera.lookAt(camRange.min);
74
        sinon.stub(panel, "range")
75
          .get(() => ({ min: camera.visibleRange.min + camera.rangeDiff + 1, max: camera.visibleRange.min + camera.rangeDiff + 1 }));
1✔
76

UNCOV
77
        expect(camera.canSee(panel)).to.be.true;
×
UNCOV
78

×
UNCOV
79
        sinon.stub(panel, "range")
×
80
          .get(() => ({ min: camera.visibleRange.max + camera.rangeDiff - 1, max: camera.visibleRange.max + camera.rangeDiff - 1 }));
UNCOV
81

×
UNCOV
82
        expect(camera.canSee(panel)).to.be.true;
×
UNCOV
83

×
UNCOV
84
        camera.lookAt(camRange.max);
×
85
        sinon.stub(panel, "range")
86
          .get(() => ({ min: camera.visibleRange.min - camera.rangeDiff + 1, max: camera.visibleRange.min - camera.rangeDiff + 1 }));
87

88
        expect(camera.canSee(panel)).to.be.true;
89

1✔
90
        sinon.stub(panel, "range")
1✔
91
          .get(() => ({ min: camera.visibleRange.max - camera.rangeDiff - 1, max: camera.visibleRange.max - camera.rangeDiff - 1 }));
UNCOV
92

×
UNCOV
93
        expect(camera.canSee(panel)).to.be.true;
×
UNCOV
94
      });
×
95

UNCOV
96
      it("should return false when visible on looped position is not included if circular is enabled", async () => {
×
UNCOV
97
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
×
UNCOV
98

×
UNCOV
99
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
100

UNCOV
101
        const panel = await createPanel(El.panel());
×
102
        sinon.stub(panel, "range")
UNCOV
103
          .get(() => ({ min: camera.visibleRange.min + camera.rangeDiff - 1, max: camera.visibleRange.min + camera.rangeDiff - 1 }));
×
104

105
        expect(camera.canSee(panel)).to.be.false;
106

107
        sinon.stub(panel, "range")
108
          .get(() => ({ min: camera.visibleRange.max + camera.rangeDiff + 1, max: camera.visibleRange.max + camera.rangeDiff + 1 }));
1✔
109

1✔
110
        expect(camera.canSee(panel)).to.be.false;
UNCOV
111

×
UNCOV
112
        sinon.stub(panel, "range")
×
UNCOV
113
          .get(() => ({ min: camera.visibleRange.min - camera.rangeDiff - 1, max: camera.visibleRange.min - camera.rangeDiff - 1 }));
×
114

UNCOV
115
        expect(camera.canSee(panel)).to.be.false;
×
UNCOV
116

×
UNCOV
117
        sinon.stub(panel, "range")
×
UNCOV
118
          .get(() => ({ min: camera.visibleRange.max - camera.rangeDiff + 1, max: camera.visibleRange.max - camera.rangeDiff + 1 }));
×
UNCOV
119

×
120
        expect(camera.canSee(panel)).to.be.false;
×
UNCOV
121
      });
×
UNCOV
122
    });
×
123

×
UNCOV
124
    describe("getRange", () => {
×
UNCOV
125
      it("should set range from first panel's left to last panel's right when circular is enabled", async () => {
×
126
        const { camera, panels } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
127

128
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
129
        expect(camera.mode.checkAvailability()).to.be.true;
130
        expect(camera.range).to.deep.equal({
1✔
131
          min: panels[0].range.min,
1✔
132
          max: panels[2].range.max
UNCOV
133
        });
×
UNCOV
134
      });
×
UNCOV
135
    });
×
136

UNCOV
137
    describe("findNearestAnchor", () => {
×
UNCOV
138
      it("should return the first anchor when position is 0", async () => {
×
139
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
UNCOV
140
        const anchors = camera.anchorPoints;
×
UNCOV
141

×
UNCOV
142
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
UNCOV
143
        expect(camera.mode.checkAvailability()).to.be.true;
×
UNCOV
144
        expect(camera.mode.findNearestAnchor(0)).to.equal(anchors[0]);
×
UNCOV
145
      });
×
UNCOV
146

×
UNCOV
147
      it("should return the last anchor when position is below 0", async () => {
×
UNCOV
148
        const { camera } = await createFlicking(El.DEFAULT_HORIZONTAL, { circular: true });
×
UNCOV
149
        const anchors = camera.anchorPoints;
×
UNCOV
150

×
UNCOV
151
        expect(camera.mode).to.be.an.instanceOf(CircularCameraMode);
×
UNCOV
152
        expect(camera.mode.checkAvailability()).to.be.true;
×
UNCOV
153
        expect(camera.mode.findNearestAnchor(-500)).to.equal(anchors[2]);
×
UNCOV
154
      });
×
UNCOV
155
    });
×
UNCOV
156
  });
×
UNCOV
157
});
×
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