Skip to content

Commit

Permalink
test(slider): refactor tests to use beforeEach for page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain committed Dec 17, 2024
1 parent 4258ffa commit fda7c03
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/slider/test/default/darkmode/index.html';

test.describe.parallel('tds-slider-default-darkmode', () => {
test('renders default slider correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('renders default slider correctly', async ({ page }) => {
const slider = page.locator('tds-slider');
await expect(slider).toHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/slider/test/default/lightmode/index.html';

test.describe.parallel('tds-slider-default-lightmode', () => {
test('renders default slider correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('renders default slider correctly', async ({ page }) => {
const slider = page.locator('tds-slider');
await expect(slider).toHaveCount(1);

Expand All @@ -14,13 +17,11 @@ test.describe.parallel('tds-slider-default-lightmode', () => {
});

test('value is set to 50', async ({ page }) => {
await page.goto(componentTestPath);
const sliderValue = page.locator('.tds-slider__value');
await expect(sliderValue).toHaveText('50');
});

test('min value is set to 0', async ({ page }) => {
await page.goto(componentTestPath);
/* Find thumb and pull it towards a left and check if min value is 0 */
await page.locator('.tds-slider__thumb-inner').hover();
await page.mouse.down();
Expand All @@ -33,7 +34,6 @@ test.describe.parallel('tds-slider-default-lightmode', () => {
});

test('max value is set to 100', async ({ page }) => {
await page.goto(componentTestPath);
/* Find thumb and pull it towards a right and check if min value is 0 */
await page.locator('.tds-slider__thumb-inner').hover();
await page.mouse.down();
Expand All @@ -46,15 +46,12 @@ test.describe.parallel('tds-slider-default-lightmode', () => {
});

test('label is hidden', async ({ page }) => {
await page.goto(componentTestPath);
const slider = page.locator('tds-slider');
const sliderLabel = slider.locator('label');
await expect(sliderLabel).toHaveText('');
});

test('slider is not read only or disabled', async ({ page }) => {
await page.goto(componentTestPath);

/* Find thumb and pull it towards a left and check if value in thumb is changing */
await page.locator('.tds-slider__thumb-inner').hover();
await page.mouse.down();
Expand All @@ -67,7 +64,6 @@ test.describe.parallel('tds-slider-default-lightmode', () => {
});

test('thumb is size large', async ({ page }) => {
await page.goto(componentTestPath);
const sliderThumb = page.locator('.tds-slider__thumb-inner');
const sliderThumbWidth = await sliderThumb.evaluate((style) => getComputedStyle(style).width);
const sliderThumbHeight = await sliderThumb.evaluate((style) => getComputedStyle(style).height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';

const componentTestPath = 'src/components/slider/test/disabled/index.html';

test.describe.parallel('tds-slider-disabled', () => {
test('read-only is false', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('read-only is false', async ({ page }) => {
const slider = page.locator('tds-slider');
await expect(slider).not.toHaveAttribute('read-only');
});

test('slider is disabled', async ({ page }) => {
await page.goto(componentTestPath);
const slider = page.locator('tds-slider input');
const sliderThumb = page.locator('.tds-slider__thumb');
const sliderCursorStyle = await sliderThumb.evaluate((style) => getComputedStyle(style).cursor);
Expand All @@ -21,7 +24,6 @@ test.describe.parallel('tds-slider-disabled', () => {
});

test('slider can not be clicked on', async ({ page }) => {
await page.goto(componentTestPath);
const sliderThumb = page.locator('.tds-slider__thumb-inner');
const sliderPointerEvents = await sliderThumb.evaluate(
(style) => getComputedStyle(style).pointerEvents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';

const componentTestPath = 'src/components/slider/test/read-only/index.html';

test.describe.parallel('tds-slider-read-only', () => {
test('read-only is true', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('read-only is true', async ({ page }) => {
const slider = page.locator('tds-slider');
await expect(slider).toHaveAttribute('read-only');
});

test('is not disabled', async ({ page }) => {
await page.goto(componentTestPath);
const sliderThumb = page.locator('.tds-slider__thumb-inner');
const sliderCursorStyle = await sliderThumb.evaluate((style) => getComputedStyle(style).cursor);
expect(sliderCursorStyle).toBe('pointer');
Expand All @@ -19,7 +22,6 @@ test.describe.parallel('tds-slider-read-only', () => {
});

test('slider can not be clicked on', async ({ page }) => {
await page.goto(componentTestPath);
const sliderThumb = page.locator('.tds-slider__thumb-inner');
const sliderThumbStyle = await sliderThumb.evaluate(
(style) => getComputedStyle(style).pointerEvents,
Expand Down

0 comments on commit fda7c03

Please sign in to comment.