Skip to content

Commit

Permalink
refactor(elements/ino-range): migrate stencil e2e tests to playwright…
Browse files Browse the repository at this point in the history
… tests (#1349)

Part of #1258

## Proposed Changes
- migrate existing stencil e2e tests to jest spec tests

---------

Co-authored-by: Jan-Niklas Voß <[email protected]>
  • Loading branch information
BenPag and janivo committed Apr 5, 2024
1 parent c7eaf0c commit e4d41ad
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 122 deletions.
85 changes: 0 additions & 85 deletions packages/elements/src/components/ino-range/ino-range.e2e.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/elements/src/components/ino-range/ino-range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class Range implements ComponentInterface {
* Disables this element.
*/
@Prop() disabled?: boolean;
@Watch('disabled')
handleDisabledChange(isDisabled: boolean) {
this.sliderInstance.setDisabled(isDisabled);
}

/**
* Restricts the slider to only allow discrete values.
Expand Down Expand Up @@ -131,7 +135,7 @@ export class Range implements ComponentInterface {
);
this.inputElStart?.setAttribute('value', `${this.valueStart}`);
this.sliderInstance = new MDCSlider(this.sliderEl);

this.sliderInstance.setDisabled(this.disabled);
this.sliderInstance.listen('MDCSlider:change', preventEvent);
this.sliderInstance.listen('MDCSlider:input', this.handleInput);
}
Expand All @@ -144,7 +148,6 @@ export class Range implements ComponentInterface {

private handleInput = (e: CustomEvent<MDCSliderChangeEventDetail>) => {
e.stopPropagation();

const { thumb, value } = e.detail;

if (!this.ranged) {
Expand Down
4 changes: 3 additions & 1 deletion packages/storybook/src/stories/ino-button/ino-button.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import '../utils';

#story--buttons-ino-button--leading-and-trailing-icon-inner {
#root-inner {
@include story-container {
display: flex;
column-gap: 20px;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/storybook/src/stories/ino-fab-set/ino-fab-set.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@import '../utils';

// only selects Stories of ino-fab-set without decorating stories with wrapper classes
.sbdocs.sbdocs-content:has(#anchor--buttons-ino-fab-set--default) {
[scale] {
width: 100%;
}
}

#root-inner {
@include story-container {
min-width: 10px;
min-height: 10px;
}
14 changes: 9 additions & 5 deletions packages/storybook/src/stories/ino-input/ino-input.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
@import '../utils';

.sbdocs.sbdocs-content:has(#anchor--input-ino-input--default) {
[scale] {
width: 100%;
}

#story--input-ino-input--states-inner #root-inner,
#story--input-ino-input--labels-inner #root-inner {
display: flex;
flex-direction: column;
gap: 15px;
#story--input-ino-input--states-inner,
#story--input-ino-input--labels-inner {
@include story-container {
display: flex;
flex-direction: column;
gap: 15px;
}
}
}
4 changes: 3 additions & 1 deletion packages/storybook/src/stories/ino-popover/ino-popover.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../utils';

.sbdocs.sbdocs-content:has(#anchor--notification-ino-popover--default) {
[scale] {
width: 100%;
Expand All @@ -16,7 +18,7 @@
.innerZoomElementWrapper > div > div {
overflow: unset;

#root-inner {
@include story-container {
display: flex;
gap: 5px;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook/src/stories/ino-range/ino-range.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@import '../utils';

.sbdocs.sbdocs-content:has(#anchor--input-ino-range--default) {
[scale] {
width: 100%;
}
}

@include story-container {
min-width: 200px;
}
64 changes: 64 additions & 0 deletions packages/storybook/src/stories/ino-range/ino-range.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expect, Page, test } from '@playwright/test';
import { goToStory, setAttribute } from '../test-utils';

test.describe('ino-range', () => {
const move = async (page: Page, targetPercentage: number) => {
const slider = page.locator('.mdc-slider');
const knob = slider.locator('.mdc-slider__thumb-knob');
const knobBox = await knob.boundingBox();
const sliderBox = await slider.boundingBox();

// Start from the middle of the slider's thumb
const start = {
x: knobBox.x + knobBox.width / 2,
y: knobBox.y + knobBox.height / 2,
};
// Slide it to some endpoint determined by the target percentage
const end = {
x: sliderBox.x + sliderBox.width * targetPercentage,
y: knobBox.y + knobBox.height / 2,
};

await page.mouse.move(start.x, start.y);
await page.mouse.down();
await page.mouse.move(end.x, end.y);
await page.mouse.up();
};

test('should not move thumb knob when is disabled', async ({ page }) => {
await goToStory(page, ['Input', 'ino-range', 'default']);
const inoRange = page.locator('ino-range');
const input = inoRange.getByRole('slider');
await expect(input).toHaveValue('70');

await setAttribute(inoRange, 'disabled', 'disabled');
await expect(input).toBeDisabled();

await move(page, 0.1);
await expect(input).toHaveValue('70');
});

test('should move thumb knob', async ({ page }) => {
await goToStory(page, ['Input', 'ino-range', 'default']);
const input = page.getByRole('slider');
await expect(input).toHaveValue('70');

await move(page, 0.95);
await expect(input).toHaveValue('95');
await move(page, 0.17);
await expect(input).toHaveValue('17');
});

test('should apply custom step value', async ({ page }) => {
await goToStory(page, ['Input', 'ino-range', 'default']);
const inoRange = page.locator('ino-range');
await setAttribute(inoRange, 'step', '10');
const input = page.getByRole('slider');
await expect(input).toHaveValue('70');

await move(page, 0.61);
await expect(input).toHaveValue('60');
await move(page, 0.86);
await expect(input).toHaveValue('90');
});
});
25 changes: 8 additions & 17 deletions packages/storybook/src/stories/ino-select/ino-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@ import { expect, Locator, test } from '@playwright/test';
import { goToStory, setAttribute } from '../test-utils';

test.describe('ino-select - Properties', () => {
let inoSelect: Locator;

test.beforeEach(async ({ page }) => {
await goToStory(page, ['Input', 'ino-select', 'default']);
inoSelect = page.locator('ino-select');
});

test('should render with the disabled property set to true', async () => {
test('should render with the disabled property set to true', async ({
page,
}) => {
const inoSelect = page.locator('ino-select');
await setAttribute(inoSelect, 'disabled', 'true');
await inoSelect.click();
await expect(inoSelect.locator('li').first()).toBeHidden();
});

test('should render with the required property set to true', async () => {
test('should render with the required property set to true', async ({
page,
}) => {
const inoSelect = page.locator('ino-select');
await setAttribute(inoSelect, 'required', 'true');
await expect(inoSelect.locator('input[required]')).toBeAttached();
});

test('should render as an outlined element if inoOutlined is true', async () => {
await inoSelect.hover();
const bBoxDefault = await inoSelect.boundingBox();

await setAttribute(inoSelect, 'outline', 'true');
await inoSelect.hover();
const bBoxOutline = await inoSelect.boundingBox();

expect(bBoxOutline.height).toBe(bBoxDefault.height);
expect(bBoxOutline.width).toBeGreaterThan(bBoxDefault.width);
});
});

test.describe('ino-select - Form integration', () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/storybook/src/stories/ino-textarea/ino-textarea.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../utils';

.sbdocs.sbdocs-content:has(#anchor--input-ino-textarea--default) {
[scale] {
width: 100%;
Expand All @@ -8,8 +10,10 @@
margin-bottom: 15px;
}

#story--input-ino-textarea--label-inner #root-inner {
display: flex;
gap: 15px;
#story--input-ino-textarea--label-inner {
@include story-container {
display: flex;
gap: 15px;
}
}
}
10 changes: 6 additions & 4 deletions packages/storybook/src/stories/ino-textarea/ino-textarea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ test.describe('ino-textarea', () => {
page,
}) => {
const inoTextArea = page.locator('ino-textarea');
const textarea = inoTextArea.getByRole('textbox');

await setAttribute(inoTextArea, 'cols', '1');
await inoTextArea.hover();
const { width: oneColWidth } = await inoTextArea.boundingBox();
await inoTextArea.blur();
const { width: oneColWidth } = await textarea.boundingBox();

await setAttribute(inoTextArea, 'cols', '10');
await inoTextArea.hover();
const { width: tenColsWidth } = await inoTextArea.boundingBox();
await inoTextArea.blur();
const { width: tenColsWidth } = await textarea.boundingBox();

expect(oneColWidth).toBeLessThan(tenColsWidth);
});
Expand Down
10 changes: 7 additions & 3 deletions packages/storybook/src/stories/ino-tooltip/ino-tooltip.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../utils';

.story-tooltip {
display: flex;
justify-content: center;
Expand All @@ -21,9 +23,11 @@
align-items: flex-end;
height: 110px;

#story--notification-ino-tooltip--color-scheme-inner #root-inner {
display: flex;
gap: 15px;
#story--notification-ino-tooltip--color-scheme-inner {
@include story-container {
display: flex;
gap: 15px;
}
}

h4 {
Expand Down
9 changes: 9 additions & 0 deletions packages/storybook/src/stories/utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Applies styling to the container of a story.
* The styling is encapsulated within this mixin because the ID may change in the future.
*/
@mixin story-container {
#root-inner {
@content;
}
}

0 comments on commit e4d41ad

Please sign in to comment.