Skip to content

Commit

Permalink
test(NumberInput): add @AVT tests (#14366)
Browse files Browse the repository at this point in the history
* test(NumberInput): add @AVT tests

* test(NumberInput): check for invalid state

* test(NumberInput): check for invalid state when value is outside min

---------

Co-authored-by: Guilherme Datilio Ribeiro <guilhermedatilio@gmail.com>
  • Loading branch information
tw15egan and guidari committed Aug 3, 2023
1 parent 2aff3d5 commit 81c85c8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 13 deletions.
88 changes: 88 additions & 0 deletions e2e/components/NumberInput/NumberInput-test.avt.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { expect, test } = require('@playwright/test');
const { visitStory } = require('../../test-utils/storybook');

test.describe('NumberInput @avt', () => {
test('accessibility-checker default', async ({ page }) => {
await visitStory(page, {
component: 'NumberInput',
id: 'components-numberinput--default',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('components-numberinput--default');
});

test('accessibility-checker skeleton', async ({ page }) => {
await visitStory(page, {
component: 'NumberInput',
id: 'components-numberinput--skeleton',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('components-numberinput--skeleton');
});

test('number input - keyboard nav', async ({ page }) => {
await visitStory(page, {
component: 'NumberInput',
id: 'components-numberinput--default',
globals: {
theme: 'white',
},
});

const input = page.getByRole('spinbutton');
const increment = page.getByRole('button', {
name: 'Increment number',
});

const decrement = page.getByRole('button', {
name: 'Decrement number',
});

await expect(input).toBeVisible();
await expect(input).toHaveValue('50');

// Tab to the NumberInput and receive focus
await page.keyboard.press('Tab');
await expect(input).toBeFocused();

// Increase value with ArrowUp
await page.keyboard.press('ArrowUp');
await expect(input).toHaveValue('51');

// Decrease value with ArrowDown
await page.keyboard.press('ArrowDown');
await expect(input).toHaveValue('50');

// Increase value with increment button
await increment.click();
await expect(input).toHaveValue('51');

// Decrease value with decrement button
await decrement.click();
await expect(input).toHaveValue('50');
await expect(input).not.toBeFocused();

// Allow setting value over `max`, but should cause input to be invalid
await input.fill('101');
await expect(input).toHaveValue('101');
await expect(input).toHaveAttribute('data-invalid', 'true');

// Allow setting value under `min`, but should cause input to be invalid
await input.fill('-1');
await expect(input).toHaveValue('-1');
await expect(input).toHaveAttribute('data-invalid', 'true');
});
});
15 changes: 2 additions & 13 deletions e2e/components/NumberInput/NumberInput-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

'use strict';

const { expect, test } = require('@playwright/test');
const { test } = require('@playwright/test');
const { themes } = require('../../test-utils/env');
const { snapshotStory, visitStory } = require('../../test-utils/storybook');
const { snapshotStory } = require('../../test-utils/storybook');

test.describe('NumberInput', () => {
themes.forEach((theme) => {
Expand All @@ -23,15 +23,4 @@ test.describe('NumberInput', () => {
});
});
});

test('accessibility-checker @avt', async ({ page }) => {
await visitStory(page, {
component: 'NumberInput',
id: 'components-numberinput--default',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('NumberInput');
});
});

0 comments on commit 81c85c8

Please sign in to comment.