Skip to content

Commit

Permalink
issue-351 pause-resume spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed Mar 3, 2024
1 parent a35adaf commit 6820bcd
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './specs/adapter.append-prepend.spec';
import './specs/adapter.check.spec';
import './specs/adapter.clip.spec';
import './specs/adapter.insert.spec';
import './specs/adapter.pause.spec';
import './specs/adapter.prepend.spec';
import './specs/adapter.reload.spec';
import './specs/adapter.remove.spec';
Expand Down
103 changes: 103 additions & 0 deletions tests/specs/adapter.pause.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Misc } from 'miscellaneous/misc';
import { makeTest } from '../scaffolding/runner';

const checkCanNotScroll = async (misc: Misc, value: number) => {
const scrollElt = misc.getScrollableElement();
scrollElt.scrollTop = value;
await misc.delay(50);
expect(misc.adapter.isLoading).toBe(false);
};

const checkCanNotCallAdapter = async (misc: Misc, method: string) => {
const result = await misc.adapter[method]();
expect(result.success).toBe(true);
expect(result.immediate).toBe(true);
expect(result.details).toBe('Scroller is paused');
await misc.delay(50);
expect(misc.adapter.isLoading).toBe(false);
};

describe('Adapter Pause/Resume Spec', () => {
makeTest({
title: 'should pause & resume',
config: { datasourceSettings: { adapter: true } },
it: misc => async done => {
let paused;
const { adapter, workflow } = misc;
adapter.paused$.subscribe(v => (paused = v));

await misc.relaxNext();
expect(workflow.cyclesDone).toBe(1);
const lastVisibleIndexInit = adapter.lastVisible.$index;
const minIndexInit = adapter.bufferInfo.maxIndex;
expect(adapter.paused).toBe(false);
expect(paused).toBeFalsy();

// pause should work immediately
const pauseResult = await adapter.pause();
expect(pauseResult.success).toBe(true);
expect(pauseResult.immediate).toBe(true);
expect(paused).toBe(true);
expect(adapter.paused).toBe(true);

// relax does nothing but resolve immediately
const relaxResult = await adapter.relax();
expect(relaxResult.success).toBe(true);
expect(relaxResult.immediate).toBe(true);

// scroll & adapter methods don't work (except resume and reset)
await checkCanNotScroll(misc, 0);
await checkCanNotScroll(misc, 9999);
await checkCanNotCallAdapter(misc, 'reload');
await checkCanNotCallAdapter(misc, 'clip');
await checkCanNotCallAdapter(misc, 'fix');
await checkCanNotCallAdapter(misc, 'pause');

expect(workflow.cyclesDone).toBe(1);
expect(adapter.lastVisible.$index).toBe(lastVisibleIndexInit);
expect(adapter.bufferInfo.maxIndex).toBe(minIndexInit);

// resume runs the workflow
const resumeResult = await adapter.resume();
expect(resumeResult.success).toBe(true);
expect(resumeResult.immediate).toBe(false);
expect(paused).toBe(false);
expect(adapter.paused).toBe(false);

expect(workflow.cyclesDone).toBe(2);
expect(adapter.lastVisible.$index).toBe(minIndexInit);
expect(adapter.bufferInfo.maxIndex).toBeGreaterThan(minIndexInit);

// scroll & adapter methods start working after resume
await misc.scrollMaxRelax();
expect(workflow.cyclesDone).toBe(3);
await adapter.reload();
expect(workflow.cyclesDone).toBe(4);

done();
}
});

makeTest({
title: 'should allow only "reset" when paused',
config: { datasourceSettings: { adapter: true } },
it: misc => async done => {
await misc.relaxNext();
expect(misc.workflow.cyclesDone).toBe(1);
expect(misc.adapter.paused).toBe(false);
await misc.adapter.pause();
await checkCanNotCallAdapter(misc, 'reload');
expect(misc.workflow.cyclesDone).toBe(1);
expect(misc.adapter.paused).toBe(true);
await misc.adapter.reset();
expect(misc.workflow.cyclesDone).toBe(2);
expect(misc.adapter.paused).toBe(false);
// scroll & adapter work as usual after reset
await misc.scrollMaxRelax();
expect(misc.workflow.cyclesDone).toBe(3);
await misc.adapter.reload();
expect(misc.workflow.cyclesDone).toBe(4);
done();
}
});
});

0 comments on commit 6820bcd

Please sign in to comment.