Skip to content

Commit b1a4ecb

Browse files
committed
issue-171 Adapter.remove skip spec
1 parent ead77aa commit b1a4ecb

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

tests/adapter.remove.spec.ts

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { makeTest, TestBedConfig } from './scaffolding/runner';
22
import { Misc } from './miscellaneous/misc';
33
import { removeItems } from './miscellaneous/items';
4-
import { AdapterProcess } from '../src/component/interfaces/index';
4+
import { AdapterProcess, ItemsPredicate } from '../src/component/interfaces/index';
55

66
const baseConfig: TestBedConfig = {
77
datasourceName: 'limited--99-100-processor',
@@ -56,6 +56,14 @@ const configListIndexes = [
5656
}
5757
}));
5858

59+
const configListEmpty = [{
60+
...configList[0],
61+
custom: { ...configList[0].custom, predicate: (({ $index }) => $index > 999) as ItemsPredicate }
62+
}, {
63+
...configList[1],
64+
custom: { ...configList[1].custom, indexes: [999] }
65+
}];
66+
5967
const configListBad = [{
6068
...configList[0],
6169
custom: { ...configList[0].custom, predicate: null }
@@ -173,21 +181,31 @@ const shouldRemove = (config: TestBedConfig, byId = false) => (misc: Misc) => as
173181
done();
174182
};
175183

176-
const shouldBreak = (config: TestBedConfig) => (misc: Misc) => (done: Function) => {
177-
spyOn(misc.workflow, 'finalize').and.callFake(() => {
178-
if (misc.workflow.cyclesDone === 1) {
179-
const innerLoopCount = misc.innerLoopCount;
180-
// call remove with wrong predicate
181-
misc.adapter.remove({ predicate: config.custom.predicate });
182-
setTimeout(() => {
183-
expect(misc.workflow.cyclesDone).toEqual(1);
184-
expect(misc.innerLoopCount).toEqual(innerLoopCount);
185-
expect(misc.workflow.errors.length).toEqual(1);
186-
expect(misc.workflow.errors[0].process).toEqual(AdapterProcess.remove);
187-
done();
188-
}, 40);
189-
}
190-
});
184+
const shouldSkip = (config: TestBedConfig) => (misc: Misc) => async (done: Function) => {
185+
await misc.relaxNext();
186+
const innerLoopCount = misc.innerLoopCount;
187+
const { predicate, indexes } = config.custom;
188+
if (predicate) {
189+
await misc.adapter.remove({ predicate });
190+
} else if (indexes) {
191+
await misc.adapter.remove({ indexes });
192+
}
193+
expect(misc.workflow.cyclesDone).toEqual(1);
194+
expect(misc.innerLoopCount).toEqual(innerLoopCount);
195+
expect(misc.workflow.errors.length).toEqual(0);
196+
done();
197+
};
198+
199+
const shouldBreak = (config: TestBedConfig) => (misc: Misc) => async (done: Function) => {
200+
await misc.relaxNext();
201+
const innerLoopCount = misc.innerLoopCount;
202+
// call remove with wrong predicate
203+
await misc.adapter.remove({ predicate: config.custom.predicate });
204+
expect(misc.workflow.cyclesDone).toEqual(1);
205+
expect(misc.innerLoopCount).toEqual(innerLoopCount);
206+
expect(misc.workflow.errors.length).toEqual(1);
207+
expect(misc.workflow.errors[0].process).toEqual(AdapterProcess.remove);
208+
done();
191209
};
192210

193211
const shouldRemoveOutOfViewFixed = (config: TestBedConfig) => (misc: Misc) => async (done: Function) => {
@@ -295,15 +313,23 @@ describe('Adapter Remove Spec', () => {
295313
);
296314
});
297315

298-
describe('Wrong', () =>
316+
describe('Empty', () => {
317+
configListEmpty.forEach(config =>
318+
makeTest({
319+
config,
320+
title: `should not remove due to empty ${config.custom.predicate ? 'predicate' : 'indexes'}`,
321+
it: shouldSkip(config)
322+
})
323+
);
324+
299325
configListBad.forEach(config =>
300326
makeTest({
301327
config,
302328
title: 'should break due to wrong predicate',
303329
it: shouldBreak(config)
304330
})
305-
)
306-
);
331+
);
332+
});
307333

308334
describe('Virtual', () => {
309335
configListOutFixed.forEach(config =>

0 commit comments

Comments
 (0)