|
1 | 1 | import { makeTest, TestBedConfig } from './scaffolding/runner';
|
2 | 2 | import { Misc } from './miscellaneous/misc';
|
3 | 3 | import { removeItems } from './miscellaneous/items';
|
4 |
| -import { AdapterProcess } from '../src/component/interfaces/index'; |
| 4 | +import { AdapterProcess, ItemsPredicate } from '../src/component/interfaces/index'; |
5 | 5 |
|
6 | 6 | const baseConfig: TestBedConfig = {
|
7 | 7 | datasourceName: 'limited--99-100-processor',
|
@@ -56,6 +56,14 @@ const configListIndexes = [
|
56 | 56 | }
|
57 | 57 | }));
|
58 | 58 |
|
| 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 | + |
59 | 67 | const configListBad = [{
|
60 | 68 | ...configList[0],
|
61 | 69 | custom: { ...configList[0].custom, predicate: null }
|
@@ -173,21 +181,31 @@ const shouldRemove = (config: TestBedConfig, byId = false) => (misc: Misc) => as
|
173 | 181 | done();
|
174 | 182 | };
|
175 | 183 |
|
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(); |
191 | 209 | };
|
192 | 210 |
|
193 | 211 | const shouldRemoveOutOfViewFixed = (config: TestBedConfig) => (misc: Misc) => async (done: Function) => {
|
@@ -295,15 +313,23 @@ describe('Adapter Remove Spec', () => {
|
295 | 313 | );
|
296 | 314 | });
|
297 | 315 |
|
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 | + |
299 | 325 | configListBad.forEach(config =>
|
300 | 326 | makeTest({
|
301 | 327 | config,
|
302 | 328 | title: 'should break due to wrong predicate',
|
303 | 329 | it: shouldBreak(config)
|
304 | 330 | })
|
305 |
| - ) |
306 |
| - ); |
| 331 | + ); |
| 332 | + }); |
307 | 333 |
|
308 | 334 | describe('Virtual', () => {
|
309 | 335 | configListOutFixed.forEach(config =>
|
|
0 commit comments