Skip to content

Commit

Permalink
tslint update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed Jun 9, 2018
1 parent 81a98a4 commit afbe6e5
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 105 deletions.
15 changes: 8 additions & 7 deletions tests/adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { makeTest } from './scaffolding/runner';
import { makeTest, TestBedConfig } from './scaffolding/runner';
import { Misc } from './miscellaneous/misc';

const customDefault = { startIndex: null, scrollCount: 0, preLoad: false };

Expand Down Expand Up @@ -51,28 +52,28 @@ const interruptConfigList = configList.map((config, i) => ({
}
}));

const checkExpectation = (config, misc) => {
const checkExpectation = (config: TestBedConfig, misc: Misc) => {
const startIndex = config.custom.startIndex === null ?
config.datasourceSettings.startIndex : config.custom.startIndex;
const bufferSize = config.datasourceSettings.bufferSize;
const firstIndex = startIndex - bufferSize;
const nextIndex = firstIndex + bufferSize + 1;
const firstItem = misc.scroller.buffer.getFirstVisibleItem();

expect(firstItem.$index).toEqual(firstIndex);
expect(firstItem ? firstItem.$index : null).toEqual(firstIndex);
expect(misc.getElementText(firstIndex)).toEqual(`${firstIndex} : item #${firstIndex}`);
expect(misc.getElementText(nextIndex)).toEqual(`${nextIndex} : item #${nextIndex}`);
};

const doReload = (config, misc) => {
const doReload = (config: TestBedConfig, misc: Misc) => {
if (config.custom.startIndex !== null) {
misc.datasource.adapter.reload(config.custom.startIndex);
} else {
misc.datasource.adapter.reload();
}
};

const shouldReload = (config) => (misc) => (done) => {
const shouldReload = (config: TestBedConfig) => (misc: Misc) => (done: Function) => {
const startWFCount = config.custom.preLoad ? 0 : 1;
spyOn(misc.workflow, 'finalize').and.callFake(() => {
if (misc.workflow.cyclesDone < startWFCount + config.custom.scrollCount) {
Expand All @@ -94,7 +95,7 @@ const shouldReload = (config) => (misc) => (done) => {
}
};

const shouldReloadBeforeLoad = (config) => (misc) => (done) => {
const shouldReloadBeforeLoad = (config: TestBedConfig) => (misc: Misc) => (done: Function) => {
spyOn(misc.workflow, 'finalize').and.callFake(() => {
expect(misc.scroller.cycleSubscriptions.length).toEqual(0);
if (misc.workflow.cyclesDone === 1) {
Expand All @@ -109,7 +110,7 @@ const shouldReloadBeforeLoad = (config) => (misc) => (done) => {
});
};

const shouldReloadInterruption = (config) => (misc) => (done) => {
const shouldReloadInterruption = (config: TestBedConfig) => (misc: Misc) => (done: Function) => {
spyOn(misc.workflow, 'finalize').and.callFake(() => {
expect(misc.scroller.cycleSubscriptions.length).toEqual(0);
if (misc.workflow.cyclesDone === 1) {
Expand Down
5 changes: 3 additions & 2 deletions tests/bug.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeTest } from './scaffolding/runner';
import { Misc } from './miscellaneous/misc';

const checkViewport = (misc, viewportHeight) => {
const checkViewport = (misc: Misc, viewportHeight: number) => {
const position = misc.getScrollPosition();
const size = misc.getScrollableSize();
const bwdPadding = misc.padding.backward.getSize();
Expand All @@ -25,7 +26,7 @@ describe('Bug Spec', () => {
makeTest({
title: 'should continue fetch',
config,
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
const fwdCount = 4;
let wfCount = null;
let jump = false;
Expand Down
37 changes: 19 additions & 18 deletions tests/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { configureTestBed } from './scaffolding/testBed';
import { defaultDatasourceClass } from './scaffolding/datasources';
import { defaultTemplate } from './scaffolding/templates';
import { Misc } from './miscellaneous/misc';
import { makeTest } from './scaffolding/runner';
import { makeTest, TestBedConfig } from './scaffolding/runner';

describe('Common Spec', () => {
let misc: Misc;

describe('Initialization', () => {

let misc: Misc;
let reconfigure = true;

beforeEach(async(() => {
Expand Down Expand Up @@ -53,11 +53,11 @@ describe('Common Spec', () => {
const _settings3 = { infinite: true };
const _settings4 = { startIndex: 99, bufferSize: 11, infinite: true };

const checkSettings = (_settings) => (misc) => (done) => {
const checkSettings = (_settings: any) => (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings).toEqual(jasmine.any(Object));
const mergedSettings = { ...defaultSettings, ..._settings };
Object.keys(defaultSettings).forEach(key => {
expect(misc.scroller.settings[key]).toEqual(mergedSettings[key]);
expect((<any>misc.scroller.settings)[key]).toEqual((<any>mergedSettings)[key]);
});
done();
};
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { startIndex: false } },
title: 'should fallback startIndex to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.startIndex).toEqual(defaultSettings.startIndex);
done();
}
Expand All @@ -104,7 +104,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { bufferSize: { weird: true } } },
title: 'should fallback bufferSize to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.bufferSize).toEqual(defaultSettings.bufferSize);
done();
}
Expand All @@ -113,7 +113,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { bufferSize: 5.5 } },
title: 'should fallback bufferSize to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.bufferSize).toEqual(defaultSettings.bufferSize);
done();
}
Expand All @@ -122,7 +122,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { bufferSize: -1 } },
title: 'should fallback bufferSize to the minimum',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.bufferSize).toEqual(minSettings.bufferSize);
done();
}
Expand All @@ -131,7 +131,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { padding: 'something' } },
title: 'should fallback padding to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.padding).toEqual(defaultSettings.padding);
done();
}
Expand All @@ -140,7 +140,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { padding: -0.1 } },
title: 'should fallback padding to the minimum',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.padding).toEqual(minSettings.padding);
done();
}
Expand All @@ -149,7 +149,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { infinite: 'something' } },
title: 'should fallback infinite to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.infinite).toEqual(defaultSettings.infinite);
done();
}
Expand All @@ -158,7 +158,7 @@ describe('Common Spec', () => {
makeTest({
config: { datasourceSettings: { horizontal: null } },
title: 'should fallback horizontal to the default',
it: (misc) => (done) => {
it: (misc: Misc) => (done: Function) => {
expect(misc.scroller.settings.horizontal).toEqual(defaultSettings.horizontal);
done();
}
Expand All @@ -176,7 +176,7 @@ describe('Bad datasource', () => {
toThrow: true
},
title: 'should throw exception (datasource is not a constructor)',
it: (error) => (done) => {
it: (error: any) => (done: Function) => {
expect(error).toBe('datasource is not a constructor');
done();
}
Expand All @@ -194,7 +194,7 @@ describe('Bad datasource', () => {
toThrow: true
},
title: 'should throw exception (no get)',
it: (error) => (done) => {
it: (error: any) => (done: Function) => {
expect(error).toBe('Datasource get method is not implemented');
done();
}
Expand All @@ -214,7 +214,7 @@ describe('Bad datasource', () => {
toThrow: true
},
title: 'should throw exception (get is not a function)',
it: (error) => (done) => {
it: (error: any) => (done: Function) => {
expect(error).toBe('Datasource get is not a function');
done();
}
Expand All @@ -229,13 +229,14 @@ describe('Bad datasource', () => {
this.settings = {};
}

get(offset) {
};
get(offset: number) {
return ++offset;
}
},
toThrow: true
},
title: 'should throw exception (get has less than 2 arguments)',
it: (error) => (done) => {
it: (error: any) => (done: Function) => {
expect(error).toBe('Datasource get method invalid signature');
done();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/datasource-get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { makeTest } from './scaffolding/runner';
import { Misc } from './miscellaneous/misc';

describe('Datasource Get', () => {

const shouldWork = (misc) => (done) =>
const shouldWork = (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() => {
expect(misc.scroller.state.fetch.count).toBeGreaterThan(0);
done();
Expand Down
33 changes: 17 additions & 16 deletions tests/eof.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Direction } from '../src/component/interfaces';
import { makeTest } from './scaffolding/runner';
import { Misc } from './miscellaneous/misc';

const min = 1, max = 100, scrollCount = 10;

Expand All @@ -18,7 +19,7 @@ describe('EOF/BOF Spec', () => {
}
};

const expectLimit = (misc, direction: Direction, noscroll = false) => {
const expectLimit = (misc: Misc, direction: Direction, noscroll = false) => {
const _forward = direction === Direction.forward;
const elements = misc.getElements();
expect(elements.length).toBeGreaterThan(config[_forward ? 'eof' : 'bof'].datasourceSettings.bufferSize);
Expand All @@ -40,44 +41,44 @@ describe('EOF/BOF Spec', () => {
const _eof = isEOF ? 'bof' : 'eof';
const direction = isEOF ? Direction.forward : Direction.backward;
const directionOpposite = isEOF ? Direction.backward : Direction.forward;
const doScroll = (misc) => isEOF ? misc.scrollMin() : misc.scrollMax();
const doScrollOpposite = (misc) => isEOF ? misc.scrollMax() : misc.scrollMin();
const doScroll = (misc: Misc) => isEOF ? misc.scrollMin() : misc.scrollMax();
const doScrollOpposite = (misc: Misc) => isEOF ? misc.scrollMax() : misc.scrollMin();

makeTest({
config: config[eof],
config: (<any>config)[eof],
title: `should get ${eof} on init`,
it: (misc) => (done) =>
it: (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() => {
expectLimit(misc, direction, true);
done();
})
});

makeTest({
config: config[eof],
config: (<any>config)[eof],
title: `should reset ${eof} after scroll`,
it: (misc) => (done) =>
it: (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() => {
const buffer = (<any>misc.scroller.buffer);
if (misc.workflow.cyclesDone === 1) {
expect(misc.scroller.buffer[eof]).toEqual(true);
expect(buffer[eof]).toEqual(true);
doScroll(misc);
} else {
expect(misc.scroller.buffer[eof]).toEqual(false);
expect(misc.scroller.buffer[_eof]).toEqual(false);
expect(buffer[eof]).toEqual(false);
expect(buffer[_eof]).toEqual(false);
done();
}
})
});

makeTest({
config: config[eof],
config: (<any>config)[eof],
title: `should stop when ${eof} is reached again`,
it: (misc) => (done) =>
it: (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() => {
if (misc.workflow.cyclesDone === 1) {
doScroll(misc);
}
else if (misc.workflow.cyclesDone === 2) {
} else if (misc.workflow.cyclesDone === 2) {
doScrollOpposite(misc);
} else {
expectLimit(misc, direction);
Expand All @@ -87,9 +88,9 @@ describe('EOF/BOF Spec', () => {
});

makeTest({
config: config[eof],
config: (<any>config)[eof],
title: `should reach ${_eof} after some scrolls`,
it: (misc) => (done) =>
it: (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() => {
if (misc.workflow.cyclesDone < scrollCount) {
doScroll(misc);
Expand Down
13 changes: 7 additions & 6 deletions tests/initial-load.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Direction } from '../src/component/interfaces';
import { makeTest } from './scaffolding/runner';
import { makeTest, TestBedConfig } from './scaffolding/runner';
import { Misc } from './miscellaneous/misc';

const configList = [{
datasourceSettings: { startIndex: 1, bufferSize: 1, padding: 2 },
Expand Down Expand Up @@ -47,7 +48,7 @@ const configListWithClip = [{
}];

const configListInfinite = configListWithClip
.filter((item, i) => [1, 3, 4, 5].includes(i))
.filter((item, i) => [1, 3, 4, 5].indexOf(i) !== -1)
.map(config => ({
...config,
datasourceSettings: {
Expand All @@ -56,7 +57,7 @@ const configListInfinite = configListWithClip
}
}));

const _shouldNotClip = (settings, misc, done) => {
const _shouldNotClip = (settings: TestBedConfig, misc: Misc, done: Function) => {
const startIndex = settings.datasourceSettings.startIndex;
const bufferSize = settings.datasourceSettings.bufferSize;
const padding = settings.datasourceSettings.padding;
Expand Down Expand Up @@ -85,7 +86,7 @@ const _shouldNotClip = (settings, misc, done) => {
done();
};

const _shouldClip = (settings, misc, done) => {
const _shouldClip = (settings: TestBedConfig, misc: Misc, done: Function) => {
const startIndex = settings.datasourceSettings.startIndex;
const bufferSize = settings.datasourceSettings.bufferSize;
const padding = settings.datasourceSettings.padding;
Expand Down Expand Up @@ -122,12 +123,12 @@ const _shouldClip = (settings, misc, done) => {
done();
};

const shouldNotClip = (settings) => (misc) => (done) =>
const shouldNotClip = (settings: TestBedConfig) => (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() =>
_shouldNotClip(settings, misc, done)
);

const shouldClip = (settings) => (misc) => (done) =>
const shouldClip = (settings: TestBedConfig) => (misc: Misc) => (done: Function) =>
spyOn(misc.workflow, 'finalize').and.callFake(() =>
_shouldClip(settings, misc, done)
);
Expand Down
8 changes: 4 additions & 4 deletions tests/miscellaneous/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export function debounce(func, wait, immediate?) {
let timeout, context, args;
export function debounce(func: Function, wait: number, immediate?: boolean) {
let timeout: number, context: any, args: any;
return function (this: any) {
context = this;
args = arguments;
const later = function () {
timeout = null;
timeout = 0;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
timeout = <any>setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
Expand Down
Loading

0 comments on commit afbe6e5

Please sign in to comment.