Skip to content

Commit

Permalink
e2e: types for initialization spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed May 23, 2024
1 parent 9f7f438 commit 3acaace
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
7 changes: 7 additions & 0 deletions tests/e2e/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { VSCROLL } from './misc/types';

declare global {
interface Window {
__vscroll__: VSCROLL;
}
}
1 change: 1 addition & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './initialization.spec';
20 changes: 12 additions & 8 deletions tests/e2e/initialization.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { test, expect, Page } from '@playwright/test';

const URL = '127.0.0.1:3000';

Expand Down Expand Up @@ -30,7 +30,7 @@ test('DOM + Workflow', async ({ page }) => {
expect(name).toBe('vscroll');
});

const runScroller = async (page, { settings = {}, devSettings = {} } = {}) =>
const runScroller = async (page: Page, { settings = {}, devSettings = {} } = {}) =>
await page.evaluate(({ settings, devSettings }) => {
const { Scroller, datasource } = window['__vscroll__'];
datasource.settings = { ...datasource.settings, ...settings };
Expand Down Expand Up @@ -128,7 +128,9 @@ test('Multiple instances initialization', async ({ page }) => {

// Adapters
await page.waitForFunction(() => {
const { datasource1, datasource2 } = window['__vscroll__'];
const { scroller1, scroller2 } = window['__vscroll__'];
const { datasource: datasource1 } = scroller1;
const { datasource: datasource2 } = scroller2;
const a1Ok = datasource1.adapter.init && datasource1.adapter.id === 1;
const a2Ok = datasource2.adapter.init && datasource2.adapter.id === 2;
return a1Ok && a2Ok;
Expand All @@ -140,7 +142,9 @@ test('Multiple instances subscriptions', async ({ page }) => {

// subscriptions should not interfere
const [c1, c2] = await page.evaluate<number[]>(() => new Promise(resolve => {
const { datasource1, datasource2, scroller1, scroller2 } = window['__vscroll__'];
const { scroller1, scroller2 } = window['__vscroll__'];
const { datasource: datasource1 } = scroller1;
const { datasource: datasource2 } = scroller2;
let c1 = 0, c2 = 0, count = 0;
datasource1.adapter.isLoading$.on(v => c1 += v ? 0 : 1);
datasource2.adapter.isLoading$.on(v => c2 += v ? 0 : 1);
Expand All @@ -150,13 +154,13 @@ test('Multiple instances subscriptions', async ({ page }) => {
}
};
const fin1 = scroller1.workflow.finalize;
scroller1.workflow.finalize = (...args) => {
fin1.apply(scroller1.workflow, args);
scroller1.workflow.finalize = () => {
fin1.call(scroller1.workflow);
done();
};
const fin2 = scroller2.workflow.finalize;
scroller2.workflow.finalize = (...args) => {
fin2.apply(scroller2.workflow, args);
scroller2.workflow.finalize = () => {
fin2.call(scroller2.workflow);
done();
};
}));
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/misc/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Workflow, IDatasourceConstructed } from '../../../src/index';

interface Scroller {
workflow: InstanceType<typeof Workflow>;
datasource: IDatasourceConstructed;
}
interface ScrollerClass {
new(datasource: IDatasourceConstructed): Scroller;
}

export type VSCROLL = {
workflow: Scroller['workflow'];
datasource: Scroller['datasource'];
Scroller: ScrollerClass;
scroller: Scroller;
scroller1: Scroller;
scroller2: Scroller;
};

0 comments on commit 3acaace

Please sign in to comment.