Skip to content

Commit

Permalink
E2E test: "Horizontal orientation" example (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
satelllte authored Oct 20, 2023
1 parent e9c3b2e commit ad985b5
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
52 changes: 49 additions & 3 deletions apps/docs/e2e/expects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ export const knobValueIsMoreThan = async (
);
};

export const knobDragsDownCorrectly = async (
knob: Locator,
{
valueNow,
page,
}: {
valueNow: number;
page: Page;
},
) => {
// It's necessary to hover over the knob and scroll it into view,
// so then we can calculate its bounds in the viewport properly
await knob.hover();

const {x, y} = await _calculateElementCenter(knob);

await page.mouse.down();
await page.mouse.move(x, y + _dragAmplitude, {steps: _dragSteps});
await page.mouse.up();
await knobValueIsLessThan(knob, {value: valueNow});
};

export const knobDragsUpCorrectly = async (
knob: Locator,
{
Expand All @@ -65,7 +87,7 @@ export const knobDragsUpCorrectly = async (
await knobValueIsMoreThan(knob, {value: valueNow});
};

export const knobDragsDownCorrectly = async (
export const knobDragsLeftCorrectly = async (
knob: Locator,
{
valueNow,
Expand All @@ -82,11 +104,33 @@ export const knobDragsDownCorrectly = async (
const {x, y} = await _calculateElementCenter(knob);

await page.mouse.down();
await page.mouse.move(x, y + _dragAmplitude, {steps: _dragSteps});
await page.mouse.move(x - _dragAmplitude, y, {steps: _dragSteps});
await page.mouse.up();
await knobValueIsLessThan(knob, {value: valueNow});
};

export const knobDragsRightCorrectly = async (
knob: Locator,
{
valueNow,
page,
}: {
valueNow: number;
page: Page;
},
) => {
// It's necessary to hover over the knob and scroll it into view,
// so then we can calculate its bounds in the viewport properly
await knob.hover();

const {x, y} = await _calculateElementCenter(knob);

await page.mouse.down();
await page.mouse.move(x + _dragAmplitude, y, {steps: _dragSteps});
await page.mouse.up();
await knobValueIsMoreThan(knob, {value: valueNow});
};

export const sourceCodeLinkIsValid = async ({
link,
page,
Expand All @@ -112,7 +156,9 @@ export const expects = {
knobValueIsEqualTo,
knobValueIsLessThan,
knobValueIsMoreThan,
knobDragsUpCorrectly,
knobDragsDownCorrectly,
knobDragsUpCorrectly,
knobDragsLeftCorrectly,
knobDragsRightCorrectly,
sourceCodeLinkIsValid,
} as const;
41 changes: 41 additions & 0 deletions apps/docs/e2e/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,44 @@ test.describe('"Interpolated knob" example', () => {
});
});
});

test.describe('"Horizontal orientation" example', () => {
let container: Locator;

test.beforeEach(({page}) => {
container = locators.exampleContainer(page, 'Horizontal orientation');
});

test('has "View source" link leading to "KnobPercentageHorizontal.tsx" source code file', async ({
page,
}) => {
const viewSourceLink = locators.exampleViewSourceLink(container);
await expects.sourceCodeLinkIsValid({
link: viewSourceLink,
page,
filePath: 'apps/docs/src/components/knobs/KnobPercentageHorizontal.tsx',
});
});

test.describe('"X" knob', () => {
let knob: Locator;

test.beforeEach(() => {
knob = locators.exampleKnob(container, 'X');
});

test('has correct default value', async () => {
const knobOutput = locators.exampleKnobOutput(container);
await expects.knobValueIsEqualTo(knob, {valueNow: 50});
await expects.knobValueTextIs(knob, {knobOutput, valueText: '50%'});
});

test('has correct drag left behaviour', async ({page}) => {
await expects.knobDragsLeftCorrectly(knob, {valueNow: 50, page});
});

test('has correct drag right behaviour', async ({page}) => {
await expects.knobDragsRightCorrectly(knob, {valueNow: 50, page});
});
});
});

0 comments on commit ad985b5

Please sign in to comment.