Skip to content

Commit 09d99c0

Browse files
committed
Fix unit tests after v6 refactor
1 parent cdee673 commit 09d99c0

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

src/pushInScene.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class PushInScene extends PushInBase {
9797
[layerDepth] = layerDepth;
9898
}
9999

100-
this.layerDepth = layerDepth ?? PUSH_IN_DEFAULT_LAYER_DEPTH;
100+
this.layerDepth = <number>layerDepth ?? PUSH_IN_DEFAULT_LAYER_DEPTH;
101101
}
102102

103103
/**

test/__mocks__/layers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const layerOptions = {
22
inpoints: [100, 200],
33
outpoints: [150, 250],
44
speed: 50,
5+
isFirst: false,
6+
isLast: false,
57
}
68

79
export const layerParams = {

test/pushInLayer/getInpoints.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,16 @@ describe('getInpoints', () => {
6161
);
6262
});
6363

64-
it('Should return scene top value as the default for first layer', () => {
64+
it('Should return 0 as the default for first layer in sequential mode', () => {
6565
const elem = <HTMLElement>document.querySelector('#layer-0');
6666
const result = mockPushInLayer['getInpoints'](elem, 0);
67+
expect(result).toEqual([0]);
68+
});
69+
70+
it('Should return scene top value as the default for first layer in continuous mode', () => {
71+
const elem = <HTMLElement>document.querySelector('#layer-0');
72+
mockPushInLayer['scene']['getMode'] = () => 'continuous';
73+
const result = mockPushInLayer['getInpoints'](elem, 0);
6774
expect(result).toEqual([10]);
6875
});
6976

test/pushInLayer/setLayerStyle.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,26 @@ describe('setLayerStyle', () => {
7575
);
7676
});
7777

78-
it('should set opacity to 1 if its the first layer and the scroll position is before its inpoint', () => {
78+
it('should set opacity to 1 if its the first layer, scroll position is before inpoint, and transitionStart is -1', () => {
7979
mockPushInLayer['scene']['pushin']['scrollY'] = 10;
80+
mockPushInLayer['params']['transitionStart'] = -1;
8081
mockPushInLayer['setLayerStyle']();
8182
const result = element.style.opacity;
8283

8384
expect(result).toEqual('1');
8485
});
8586

8687
it('should set opacity to 1 if its the first layer and it is active', () => {
87-
mockPushInLayer['scene']['pushin']['scrollY'] = 205;
88+
mockPushInLayer['scene']['pushin']['scrollY'] = 251;
8889
mockPushInLayer['setLayerStyle']();
8990
const result = element.style.opacity;
9091

9192
expect(result).toEqual('1');
9293
});
9394

94-
it('should set opacity to 1 if its the last layer and the scroll position is after its outpoint', () => {
95+
it('should set opacity to 1 if its the last layer, scroll position is after outpoint, and transitionEnd is -1', () => {
9596
mockPushInLayer['scene']['pushin']['scrollY'] = 600;
97+
mockPushInLayer['params']['transitionEnd'] = -1;
9698
mockPushInLayer['index'] = 2;
9799
mockPushInLayer['setLayerStyle']();
98100

test/pushInScene/getLayers.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ describe('getLayers', () => {
4040

4141
it('Should create pushInLayer with correct arguments', () => {
4242
mockPushInScene['getLayers']();
43-
expect(PushInLayer).toHaveBeenCalledWith(layers[1], 1, mockPushInScene, {});
43+
const mockOptions = {
44+
isFirst: false,
45+
isLast: false,
46+
};
47+
expect(PushInLayer).toHaveBeenCalledWith(layers[1], 1, mockPushInScene, mockOptions);
4448
});
4549

4650
it('Should set layer settings from the JavaScript API', () => {
@@ -49,13 +53,19 @@ describe('getLayers', () => {
4953

5054
mockPushInScene['settings'] = sceneOptions;
5155
mockPushInScene['settings'].layers = [
52-
Object.assign({}, layerOptions),
56+
{ ...layerOptions, isFirst: true },
5357
testLayerOptions,
54-
Object.assign({}, layerOptions),
55-
Object.assign({}, layerOptions),
58+
{ ...layerOptions },
59+
{ ...layerOptions, isLast: true },
5660
];
5761

5862
mockPushInScene['getLayers']();
59-
expect(PushInLayer).toHaveBeenNthCalledWith(2, layers[1], 1, mockPushInScene, testLayerOptions);
63+
64+
const expectedElement = layers[1];
65+
const expectedIndex = 1;
66+
const expectedParent = mockPushInScene;
67+
const expectedOptions = testLayerOptions;
68+
69+
expect(PushInLayer).toHaveBeenNthCalledWith(2, expectedElement, expectedIndex, expectedParent, expectedOptions);
6070
});
6171
});

0 commit comments

Comments
 (0)