-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(textarea): add screenshot tests using reusable test code
- Loading branch information
Showing
19 changed files
with
115 additions
and
79 deletions.
There are no files selected for viewing
54 changes: 33 additions & 21 deletions
54
packages/core/src/components/textarea/test/basic/textarea.e2e.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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
import { test } from 'stencil-playwright'; | ||
import { expect } from '@playwright/test'; | ||
import { | ||
testConfigurations, | ||
getTestDescribeText, | ||
setupPage, | ||
} from '../../../../utils/testConfiguration'; | ||
|
||
const componentTestPath = 'src/components/textarea/test/basic/index.html'; | ||
const componentName = 'tds-textarea'; | ||
|
||
test.describe.parallel('tds-textarea', () => { | ||
test('renders default textarea correctly', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
testConfigurations.withModeVariants.forEach((config) => { | ||
test.describe.parallel(getTestDescribeText(config, componentName), () => { | ||
test.beforeEach(async ({ page }) => { | ||
await setupPage(page, config, componentTestPath, componentName); | ||
}); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
test('renders default textarea correctly', async ({ page }) => { | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('test if able to type in textarea', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const textarea = page.getByRole('textbox'); | ||
test('test if able to type in textarea', async ({ page }) => { | ||
const textarea = page.getByRole('textbox'); | ||
|
||
/* Expect to have received an event from clicking on the textarea */ | ||
const myEventSpy = await page.spyOnEvent('click'); | ||
await textarea.click(); | ||
expect(myEventSpy).toHaveReceivedEvent(); | ||
/* Expect to have received an event from clicking on the textarea */ | ||
const myEventSpy = await page.spyOnEvent('click'); | ||
await textarea.click(); | ||
expect(myEventSpy).toHaveReceivedEvent(); | ||
|
||
/* Expect the textbox to have the cursor text style */ | ||
const textareaCursorState = await textarea.evaluate((style) => getComputedStyle(style).cursor); | ||
expect(textareaCursorState).toBe('text'); | ||
/* Expect the textbox to have the cursor text style */ | ||
const textareaCursorState = await textarea.evaluate( | ||
(style) => getComputedStyle(style).cursor, | ||
); | ||
expect(textareaCursorState).toBe('text'); | ||
|
||
/* Expect the inputValue of textarea to have "Adding some text" after it has been typed */ | ||
await textarea.fill('Adding some text'); | ||
expect(await textarea.inputValue()).toBe('Adding some text'); | ||
/* Expect the inputValue of textarea to have "Adding some text" after it has been typed */ | ||
await textarea.fill('Adding some text'); | ||
expect(await textarea.inputValue()).toBe('Adding some text'); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+4.67 KB
...ts/tds-textarea-primary-darkmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.59 KB
...s/tds-textarea-primary-lightmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.65 KB
.../tds-textarea-secondary-darkmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.6 KB
...tds-textarea-secondary-lightmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 49 additions & 37 deletions
86
packages/core/src/components/textarea/test/default/textarea.e2e.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 |
---|---|---|
@@ -1,43 +1,55 @@ | ||
import { test } from 'stencil-playwright'; | ||
import { expect } from '@playwright/test'; | ||
import { | ||
testConfigurations, | ||
getTestDescribeText, | ||
setupPage, | ||
} from '../../../../utils/testConfiguration'; | ||
|
||
const componentTestPath = 'src/components/textarea/test/default/index.html'; | ||
|
||
test.describe.parallel('tds-textarea-default', () => { | ||
test('renders default textarea correctly', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('test if able to type in textarea', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const textarea = page.getByRole('textbox'); | ||
|
||
/* Expect to have received an event from clicking on the textarea */ | ||
const myEventSpy = await page.spyOnEvent('click'); | ||
await textarea.click(); | ||
expect(myEventSpy).toHaveReceivedEvent(); | ||
|
||
/* Expect the textbox to have the cursor text style */ | ||
const textareaCursorState = await textarea.evaluate((style) => getComputedStyle(style).cursor); | ||
expect(textareaCursorState).toBe('text'); | ||
|
||
/* Expect the inputValue of textarea to have "Adding some text" after it has been typed */ | ||
await textarea.fill('Adding some text'); | ||
expect(await textarea.inputValue()).toBe('Adding some text'); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('not able to find label if "no-label" is set', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const textareaLabel = page.getByText('Label'); | ||
await expect(textareaLabel).toHaveCount(0); | ||
await expect(textareaLabel).toBeHidden(); | ||
const componentName = 'tds-textarea'; | ||
const testDescription = 'tds-textarea-default'; | ||
|
||
testConfigurations.withModeVariants.forEach((config) => { | ||
test.describe.parallel(getTestDescribeText(config, testDescription), () => { | ||
test.beforeEach(async ({ page }) => { | ||
await setupPage(page, config, componentTestPath, componentName); | ||
}); | ||
|
||
test('renders default textarea correctly', async ({ page }) => { | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('test if able to type in textarea', async ({ page }) => { | ||
const textarea = page.getByRole('textbox'); | ||
|
||
/* Expect to have received an event from clicking on the textarea */ | ||
const myEventSpy = await page.spyOnEvent('click'); | ||
await textarea.click(); | ||
expect(myEventSpy).toHaveReceivedEvent(); | ||
|
||
/* Expect the textbox to have the cursor text style */ | ||
const textareaCursorState = await textarea.evaluate( | ||
(style) => getComputedStyle(style).cursor, | ||
); | ||
expect(textareaCursorState).toBe('text'); | ||
|
||
/* Expect the inputValue of textarea to have "Adding some text" after it has been typed */ | ||
await textarea.fill('Adding some text'); | ||
expect(await textarea.inputValue()).toBe('Adding some text'); | ||
|
||
/* Expect no difference in screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('not able to find label if "no-label" is set', async ({ page }) => { | ||
const textareaLabel = page.getByText('Label'); | ||
await expect(textareaLabel).toHaveCount(0); | ||
await expect(textareaLabel).toBeHidden(); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+5.95 KB
...extarea-default-primary-darkmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.5 KB
...-textarea-default-primary-darkmode-test-if-able-to-type-in-textarea-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.72 KB
...xtarea-default-primary-lightmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.43 KB
...textarea-default-primary-lightmode-test-if-able-to-type-in-textarea-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.91 KB
...tarea-default-secondary-darkmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.49 KB
...extarea-default-secondary-darkmode-test-if-able-to-type-in-textarea-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.73 KB
...area-default-secondary-lightmode-renders-default-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.43 KB
...xtarea-default-secondary-lightmode-test-if-able-to-type-in-textarea-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 33 additions & 21 deletions
54
packages/core/src/components/textarea/test/read-only/textarea.e2e.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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
import { test } from 'stencil-playwright'; | ||
import { expect } from '@playwright/test'; | ||
import { | ||
testConfigurations, | ||
getTestDescribeText, | ||
setupPage, | ||
} from '../../../../utils/testConfiguration'; | ||
|
||
const componentTestPath = 'src/components/textarea/test/read-only/index.html'; | ||
const componentName = 'tds-textarea'; | ||
const testDescription = 'tds-textarea-read-only'; | ||
|
||
test.describe.parallel('tds-textarea-read-only', () => { | ||
test('renders read-only textarea correctly', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
testConfigurations.withModeVariants.forEach((config) => { | ||
test.describe.parallel(getTestDescribeText(config, testDescription), () => { | ||
test.beforeEach(async ({ page }) => { | ||
await setupPage(page, config, componentTestPath, componentName); | ||
}); | ||
|
||
/* Expect the tds-textarea to have the read-only attribute */ | ||
await expect(tdsTextarea).toHaveAttribute('read-only'); | ||
test('renders read-only textarea correctly', async ({ page }) => { | ||
const tdsTextarea = page.getByTestId('tds-textarea-testid'); | ||
await expect(tdsTextarea).toHaveCount(1); | ||
|
||
/* Expect no diff on screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
/* Expect the tds-textarea to have the read-only attribute */ | ||
await expect(tdsTextarea).toHaveAttribute('read-only'); | ||
|
||
test('read-only textarea - native textarea should have readonly attribute', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const textarea = page.getByRole('textbox'); | ||
/* Expect no diff on screenshot */ | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
/* Expect the textarea within tds-textarea to have the readonly attribute */ | ||
await expect(textarea).toHaveAttribute('readonly'); | ||
}); | ||
test('read-only textarea - native textarea should have readonly attribute', async ({ | ||
page, | ||
}) => { | ||
const textarea = page.getByRole('textbox'); | ||
|
||
/* Expect the textarea within tds-textarea to have the readonly attribute */ | ||
await expect(textarea).toHaveAttribute('readonly'); | ||
}); | ||
|
||
test('be able to find label if "outside" is set', async ({ page }) => { | ||
await page.goto(componentTestPath); | ||
const textareaLabel = page.getByText('Label'); | ||
await expect(textareaLabel).toHaveCount(1); | ||
await expect(textareaLabel).toBeVisible(); | ||
test('be able to find label if "outside" is set', async ({ page }) => { | ||
const textareaLabel = page.getByText('Label'); | ||
await expect(textareaLabel).toHaveCount(1); | ||
await expect(textareaLabel).toBeVisible(); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+6.92 KB
...rea-read-only-primary-darkmode-renders-read-only-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.74 KB
...ea-read-only-primary-lightmode-renders-read-only-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.9 KB
...a-read-only-secondary-darkmode-renders-read-only-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.77 KB
...-read-only-secondary-lightmode-renders-read-only-textarea-correctly-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.