-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(elements/ino-textarea): migrate stencil e2e tests to spec te…
…st (#1305) * wip * wip fix spec tests * provide ino-textarea spec tests * migrate e2e tests to playwright * format fix * revert changes in stencil.config.ts * implement PR feedback * remove form locator * enable retries
- Loading branch information
Showing
6 changed files
with
140 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 0 additions & 194 deletions
194
packages/elements/src/components/ino-textarea/ino-textarea.e2e.ts
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
packages/elements/src/components/ino-textarea/ino-textarea.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { newSpecPage, SpecPage } from '@stencil/core/testing'; | ||
import { Textarea } from './ino-textarea'; | ||
import { listenForEvent } from '../../util/test-utils'; | ||
|
||
describe('ino-textarea', () => { | ||
let page: SpecPage; | ||
let inoTextarea: HTMLInoTextareaElement; | ||
let innerTextarea: HTMLTextAreaElement; | ||
|
||
describe('Events', () => { | ||
const typeText = async (value: string) => { | ||
const arr = [...value]; | ||
innerTextarea.value = ''; | ||
arr.forEach((char) => { | ||
innerTextarea.value += char; | ||
innerTextarea.dispatchEvent(new Event('input')); | ||
}); | ||
await page.waitForChanges(); | ||
}; | ||
|
||
beforeEach(async () => { | ||
page = await newSpecPage({ | ||
components: [Textarea], | ||
html: '<ino-textarea outline="false" value="Some Text"></ino-textarea>', | ||
}); | ||
|
||
inoTextarea = page.body.querySelector('ino-textarea'); | ||
innerTextarea = inoTextarea.querySelector('textarea'); | ||
innerTextarea.setSelectionRange = jest.fn(); | ||
}); | ||
|
||
it('should render with an defined value', async () => { | ||
expect(inoTextarea.value).toEqual('Some Text'); | ||
}); | ||
|
||
it('should emit valueChange event while typing in textarea and have the typed string in event.detail', async () => { | ||
const { assertEventDetails } = listenForEvent(page, 'valueChange'); | ||
await typeText('t'); | ||
await page.waitForChanges(); | ||
assertEventDetails('t'); | ||
}); | ||
|
||
it("should emit 4 valueChange events while typing 'test' in textarea", async () => { | ||
const { eventSpy } = listenForEvent(page, 'valueChange'); | ||
await typeText('test'); | ||
await page.waitForChanges(); | ||
expect(eventSpy).toHaveBeenCalledTimes(4); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/storybook/src/stories/ino-textarea/ino-textarea.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { expect, Locator, test } from '@playwright/test'; | ||
import { goToStory, setAttribute } from '../test-utils'; | ||
|
||
test.describe('ino-textarea', () => { | ||
let inoTextArea: Locator; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-textarea', 'default']); | ||
inoTextArea = page.locator('ino-textarea'); | ||
}); | ||
|
||
test.describe('Component Behaviour', () => { | ||
test('should be not focused after render', async () => { | ||
await expect(inoTextArea).not.toBeFocused(); | ||
}); | ||
|
||
test('should render with an above floating label after focus', async () => { | ||
const sampleText = 'Some Label'; | ||
await setAttribute(inoTextArea, 'label', sampleText); | ||
await inoTextArea.click(); | ||
const label = inoTextArea.locator('label'); | ||
await expect(label).toHaveClass(/mdc-floating-label--float-above/); | ||
}); | ||
|
||
test('should have higher height after increasing the rows', async () => { | ||
await setAttribute(inoTextArea, 'rows', '1'); | ||
const { height: oneRowHeight } = await inoTextArea.boundingBox(); | ||
|
||
await setAttribute(inoTextArea, 'rows', '10'); | ||
const { height: tenRowsHeight } = await inoTextArea.boundingBox(); | ||
|
||
expect(oneRowHeight).toBeLessThan(tenRowsHeight); | ||
}); | ||
|
||
test('should have wider widths after increasing the columns', async () => { | ||
await setAttribute(inoTextArea, 'cols', '1'); | ||
const { width: oneColWidth } = await inoTextArea.boundingBox(); | ||
|
||
await setAttribute(inoTextArea, 'cols', '10'); | ||
const { width: tenColsWidth } = await inoTextArea.boundingBox(); | ||
|
||
expect(oneColWidth).toBeLessThan(tenColsWidth); | ||
}); | ||
|
||
test('should NOT increase width when input exceeds width and autogrow not set', async () => { | ||
await setAttribute(inoTextArea, 'rows', '2'); | ||
await setAttribute(inoTextArea, 'cols', '2'); | ||
|
||
const bBoxBefore = await inoTextArea.boundingBox(); | ||
await setAttribute(inoTextArea, 'value', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'); | ||
const bBoxAfter = await inoTextArea.boundingBox(); | ||
|
||
expect(bBoxAfter.height).toEqual(bBoxBefore.height); | ||
}); | ||
|
||
test('should increase width when input exceeds width and autogrow set', async () => { | ||
await setAttribute(inoTextArea, 'rows', '2'); | ||
await setAttribute(inoTextArea, 'cols', '2'); | ||
await setAttribute(inoTextArea, 'autogrow', 'true'); | ||
|
||
const bBoxBefore = await inoTextArea.boundingBox(); | ||
await setAttribute(inoTextArea, 'value', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'); | ||
const bBoxAfter = await inoTextArea.boundingBox(); | ||
|
||
expect(bBoxAfter.height).toBeGreaterThan(bBoxBefore.height); | ||
}); | ||
|
||
test('should not enter more than max length', async () => { | ||
const nativeTextarea = inoTextArea.locator('textarea'); | ||
await setAttribute(inoTextArea, 'maxlength', '3'); | ||
|
||
await nativeTextarea.fill('ABC'); | ||
await expect(nativeTextarea).toHaveValue('ABC'); | ||
|
||
await nativeTextarea.fill('DEFG'); | ||
await expect(nativeTextarea).toHaveValue('DEF'); | ||
}); | ||
}); | ||
}); |