From 96c866d8372739da57bb53e7d649c090af3e7cd3 Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Sun, 17 Mar 2024 18:40:20 +0100 Subject: [PATCH] e2e: types for initialization spec --- tests/e2e/index.d.ts | 7 +++++++ tests/e2e/index.ts | 1 + tests/e2e/initialization.spec.ts | 20 ++++++++++++-------- tests/e2e/misc/types.ts | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 tests/e2e/index.d.ts create mode 100644 tests/e2e/index.ts create mode 100644 tests/e2e/misc/types.ts diff --git a/tests/e2e/index.d.ts b/tests/e2e/index.d.ts new file mode 100644 index 00000000..ad1412ee --- /dev/null +++ b/tests/e2e/index.d.ts @@ -0,0 +1,7 @@ +import { VSCROLL } from './misc/types'; + +declare global { + interface Window { + __vscroll__: VSCROLL; + } +} \ No newline at end of file diff --git a/tests/e2e/index.ts b/tests/e2e/index.ts new file mode 100644 index 00000000..b86fe813 --- /dev/null +++ b/tests/e2e/index.ts @@ -0,0 +1 @@ +import './initialization.spec'; \ No newline at end of file diff --git a/tests/e2e/initialization.spec.ts b/tests/e2e/initialization.spec.ts index 512b52c4..2d7e45c1 100644 --- a/tests/e2e/initialization.spec.ts +++ b/tests/e2e/initialization.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/test'; +import { test, expect, Page } from '@playwright/test'; const URL = '127.0.0.1:3000'; @@ -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 }; @@ -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; @@ -140,7 +142,9 @@ test('Multiple instances subscriptions', async ({ page }) => { // subscriptions should not interfere const [c1, c2] = await page.evaluate(() => 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); @@ -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(); }; })); diff --git a/tests/e2e/misc/types.ts b/tests/e2e/misc/types.ts new file mode 100644 index 00000000..8e001aae --- /dev/null +++ b/tests/e2e/misc/types.ts @@ -0,0 +1,18 @@ +import { Workflow, IDatasourceConstructed } from '../../../src/index'; + +interface Scroller { + workflow: InstanceType; + 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; +};