Skip to content

Commit

Permalink
chore(e2e): add input-files.spec.ts (#6436)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jan 12, 2024
1 parent fbb5281 commit 05e0ca8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"replicants",
"tuiiconbutton",
"hitbox",
"domcontentloaded"
"domcontentloaded",
"filechooser"
],
"ignoreRegExpList": ["\\(https?://.*?\\)", "\\/{1}.+\\/{1}", "\\%2F.+", "\\%2C.+", "\\ɵ.+", "\\ыва.+"],
"overrides": [
Expand Down

This file was deleted.

50 changes: 50 additions & 0 deletions projects/demo-playwright/tests/kit/input-files/input-files.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {TuiDocumentationApiPagePO, tuiGoto} from '@demo-playwright/utils';
import {expect, Locator, test} from '@playwright/test';
import {join} from 'path';

test.describe('InputFiles', () => {
let example: Locator;

test.beforeEach(({page}) => {
example = new TuiDocumentationApiPagePO(page).apiPageExample;
});

['english', 'dutch', 'russian'].forEach(language =>
test(`Wrong file type (i18n: ${language})`, async ({page}) => {
await tuiGoto(page, '/components/input-files/API?accept=application/pdf', {
language,
});

await example
.locator('[tuiInputFiles]')
.setInputFiles(join(__dirname, '../../../stubs/web-api.svg'));
await expect(example).toHaveScreenshot(`01-${language}-input-files.png`);
}),
);

['english', 'dutch', 'russian'].forEach(language =>
test(`File is too large (i18n: ${language})`, async ({page}) => {
await tuiGoto(
page,
'/components/input-files/API?accept=image/*&maxFileSize=2000',
{language},
);
await example
.locator('[tuiInputFiles]')
.setInputFiles(join(__dirname, '../../../stubs/web-api.svg'));
await expect(example).toHaveScreenshot(`02-${language}-input-files.png`);
}),
);

test('Link text is too long', async ({page}) => {
await page.setViewportSize({width: 550, height: 500});
await tuiGoto(
page,
'/components/input-files/API?link=Select%20a%20file%20with%20a%20too%20long%20name.%20Long%20filename.%20Very%20long%20filename',
);
await example
.locator('[tuiInputFiles]')
.setInputFiles(join(__dirname, '../../../stubs/web-api.svg'));
await expect(example).toHaveScreenshot('03-input-files.png');
});
});
9 changes: 9 additions & 0 deletions projects/demo-playwright/utils/goto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {tuiWaitForFonts} from './wait-for-fonts';

interface TuiGotoOptions extends NonNullable<Parameters<Page['goto']>[1]> {
date?: Date;
language?: string;
hideHeader?: boolean;
enableNightMode?: boolean;
hideVersionManager?: boolean;
Expand All @@ -20,6 +21,7 @@ export async function tuiGoto(
enableNightMode = false,
hideVersionManager = false,
hideLanguageSwitcher = false,
language,
...playwrightGotoOptions
}: TuiGotoOptions = {},
): ReturnType<Page['goto']> {
Expand All @@ -36,6 +38,13 @@ export async function tuiGoto(
);
}

if (language) {
await page.addInitScript(
lang => globalThis.localStorage.setItem('tuiLanguage', lang),
language,
);
}

await tuiMockDate(page, date);

const response = await page.goto(url, playwrightGotoOptions);
Expand Down

0 comments on commit 05e0ca8

Please sign in to comment.