Skip to content

Commit

Permalink
e2e: makeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed May 24, 2024
1 parent 2ebdda3 commit a7fa2a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
18 changes: 15 additions & 3 deletions tests/e2e/misc/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Page } from '@playwright/test';
import { Config } from './types';
import test, { Page } from '@playwright/test';
import { Config, It } from './types';

const URL = '127.0.0.1:3000';

export const runScroller = async (page: Page, config: Config = {}) =>
await page.evaluate(config => {
Expand Down Expand Up @@ -39,4 +41,14 @@ export const runScroller = async (page: Page, config: Config = {}) =>

const { workflow } = new Scroller(datasource);
window['__vscroll__'].workflow = workflow;
}, config as unknown);
}, config as unknown);

export const makeTest = (
{ title, config, it }: { title: string; config: Config; it: It }
) =>
test(title, async ({ page }) => {
await page.goto(URL + '/need-run');
await runScroller(page, config as Config);
await it({ config, page });
// await new Promise(r => setTimeout(r, 2000));
});
4 changes: 1 addition & 3 deletions tests/e2e/misc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TemplateSettings = {
headerHeight?: number;
}

export type Config<Custom = void> = {
export type Config<Custom = unknown> = {
datasourceClass?: { new(): unknown };
datasourceName?: string;
datasourceSettings?: Settings;
Expand All @@ -48,5 +48,3 @@ export type Config<Custom = void> = {
}

export type It<T = unknown> = (args: { config: Config<T>, page: Page }) => Promise<void>;

export type MakeTest<T = unknown> = (args: { title: string; config: Config<T>; it: It<T> }) => void;
18 changes: 3 additions & 15 deletions tests/e2e/scroll-basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test, expect, Page } from '@playwright/test';
import { ScrollResult, initializeItemsCounter } from './misc/itemsCounter';
import { Config, It, MakeTest } from './misc/types';
import { runScroller } from './misc/runner';
import { Config } from './misc/types';
import { makeTest } from './misc/runner';
import { Direction } from '../../src/inputs/common';

// test.use({ headless: false });

const URL = '127.0.0.1:3000';

interface ICustom {
direction: Direction;
count: number;
Expand Down Expand Up @@ -112,7 +110,7 @@ const massTwoDirectionalScrollsConfigList_bwd =
} as Config<ICustom>));


const shouldScroll = async (config: Config<ICustom>, page: Page) => {
const shouldWork = async ({ config, page }: { config: Config, page: Page }) => {

await initializeItemsCounter(page);

Expand Down Expand Up @@ -167,16 +165,6 @@ const shouldScroll = async (config: Config<ICustom>, page: Page) => {
.toHaveText(`${oppositeItemIndex[0]}) item #${oppositeItemIndex[0]}`);
};

const makeTest: MakeTest<ICustom> = ({ title, config, it }) =>
test(title, ({ page }) => it({ config, page }));

const shouldWork: It<ICustom> = async ({ config, page }) => {
await page.goto(URL + '/need-run');
await runScroller(page, config as Config);
await shouldScroll(config, page);
// await new Promise(r => setTimeout(r, 2000));
};

test.describe('Scroll Basic Spec', () => {
test.describe.configure({ mode: 'serial' });

Expand Down

0 comments on commit a7fa2a0

Please sign in to comment.