Skip to content

Commit

Permalink
FI-1471 fix: error.setMessage method in UI-mode
Browse files Browse the repository at this point in the history
refactor: turn on `--isolatedDeclarations` TypeScript option
chore: update Playwright to 1.48.1
chore: update TypeScript to 5.6.3 and other `devDependencies`
fix: remove `createSelectorByCss` function and `htmlElementSelector` from API
fix: supports regexps in `withText` method of `Selector`
FI-1477 feat: add action `selectOption`
  • Loading branch information
uid11 committed Oct 17, 2024
1 parent 129ad87 commit 889b604
Show file tree
Hide file tree
Showing 58 changed files with 287 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ rules:
- {selector: [objectLiteralProperty, typeProperty], format: null, modifiers: [requiresQuotes]}
- {selector: [classProperty, typeMethod], filter: '^toJSON$', format: null}
'@typescript-eslint/no-import-type-side-effects': error
'@typescript-eslint/no-inferrable-types': error
'@typescript-eslint/no-inferrable-types': off
'@typescript-eslint/no-invalid-void-type':
[error, {allowInGenericTypeArguments: true, allowAsThisParameter: true}]
'@typescript-eslint/no-loop-func': error
Expand Down
2 changes: 1 addition & 1 deletion autotests/configurator/doAfterPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const assertExternalPackRunId: DoAfterPack = ({customReportProperties, endTimeIn
* An array of functions that will be run after the pack.
* This is an implementation for internal tests. You must remove it from your project.
*/
export const doAfterPack = [
export const doAfterPack: readonly DoAfterPack[] = [
setExternalPackRunId,
incrementExternalPackRunId,
assertExternalPackRunId,
Expand Down
2 changes: 1 addition & 1 deletion autotests/configurator/doBeforePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const assertInternalPackRunId: DoBeforePack = ({fullPackConfig, startTimeInMs})
* An array of functions that will be run before the pack.
* This is an implementation for internal tests. You must remove it from your project.
*/
export const doBeforePack = [
export const doBeforePack: readonly DoBeforePack[] = [
setInternalPackRunId,
incrementInternalPackRunId,
assertInternalPackRunId,
Expand Down
1 change: 1 addition & 0 deletions autotests/configurator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export type {
MapLogPayloadInReport,
Pack,
SkipTests,
TestFunction,
TestMeta,
} from './types';
1 change: 1 addition & 0 deletions autotests/configurator/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type {
MapLogPayloadInLogFile,
MapLogPayloadInReport,
Pack,
TestFunction,
} from './packSpecific';
export type {SkipTests} from './skipTests';
export type {TestMeta} from './testMeta';
1 change: 1 addition & 0 deletions autotests/configurator/types/packSpecific.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type MapBackendResponseToLog = PackSpecificTypes['MapBackendResponseToLog
export type MapLogPayloadInConsole = PackSpecificTypes['MapLogPayloadInConsole'];
export type MapLogPayloadInLogFile = PackSpecificTypes['MapLogPayloadInLogFile'];
export type MapLogPayloadInReport = PackSpecificTypes['MapLogPayloadInReport'];
export type TestFunction = PackSpecificTypes['TestFunction'];
export type {Pack};
4 changes: 2 additions & 2 deletions autotests/constants/attributesOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {AttributesOptions} from 'create-locator';
/**
* Attributes options for locators.
*/
export const attributesOptions = {
export const attributesOptions: AttributesOptions = {
parameterAttributePrefix: 'data-test-',
testIdAttribute: 'data-testid',
testIdSeparator: '-',
} as const satisfies AttributesOptions;
};
20 changes: 17 additions & 3 deletions autotests/context/pageCookies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import {useContext} from 'e2ed';

import type {Cookie} from 'e2ed/types';
import type {ClearContext, Cookie, GetContext, SetContext} from 'e2ed/types';

type Cookies = readonly Cookie[];

const [get, set, clear] = useContext<Cookies>();

/**
* Get page cookies, that will be added when navigating to the page.
*/
export const getPageCookies: GetContext<Cookies> = get;

/**
* Set page cookies, that will be added when navigating to the page.
*/
export const setPageCookies: SetContext<Cookies> = set;

/**
* Get, set and clear page cookies, that will be added when navigating to the page.
* Clear page cookies, that will be added when navigating to the page.
*/
export const [getPageCookies, setPageCookies, clearPageCookies] = useContext<readonly Cookie[]>();
export const clearPageCookies: ClearContext = clear;
19 changes: 15 additions & 4 deletions autotests/context/pageRequestHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import {useContext} from 'e2ed';

import type {Headers} from 'e2ed/types';
import type {ClearContext, GetContext, Headers, SetContext} from 'e2ed/types';

const [get, set, clear] = useContext<Headers>();

/**
* Get additional page request headers, that will be added when navigating to the page.
*/
export const getPageRequestHeaders: GetContext<Headers> = get;

/**
* Set additional page request headers, that will be added when navigating to the page.
*/
export const setPageRequestHeaders: SetContext<Headers> = set;

/**
* Get, set and clear additional page request headers, that will be added when navigating to the page.
* Clear additional page request headers, that will be added when navigating to the page.
*/
export const [getPageRequestHeaders, setPageRequestHeaders, clearPageRequestHeaders] =
useContext<Headers>();
export const clearPageRequestHeaders: ClearContext = clear;
3 changes: 2 additions & 1 deletion autotests/entities/product.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {createClientFunction} from 'e2ed';

import type {ApiProduct, Product} from 'autotests/types';
import type {ClientFunction} from 'e2ed/types';

/**
* Adds product.
*/
export const addProduct = createClientFunction(
export const addProduct: ClientFunction<[Product], Promise<ApiProduct>> = createClientFunction(
(product: Product) =>
fetch(`https://reqres.in/api/product/${product.id}?size=${product.size}`, {
body: JSON.stringify({
Expand Down
5 changes: 3 additions & 2 deletions autotests/entities/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {createClientFunction} from 'e2ed';
import {log} from 'e2ed/utils';

import type {UserWorker} from 'autotests/types';
import type {ClientFunction} from 'e2ed/types';

const clientGetUsers = createClientFunction(
(delay: number) =>
Expand All @@ -12,13 +13,13 @@ const clientGetUsers = createClientFunction(
/**
* Adds user-worker.
*/
export const addUser = createClientFunction(
export const addUser: ClientFunction<[UserWorker, number?], Promise<object>> = createClientFunction(
(user: UserWorker, delay?: number) =>
fetch(`https://reqres.in/api/users${delay !== undefined ? `?delay=${delay}` : ''}`, {
body: JSON.stringify(user),
headers: {'Content-Type': 'application/json; charset=UTF-8'},
method: 'POST',
}).then((res) => res.json()),
}),
{name: 'addUser', timeout: 3_000},
);

Expand Down
21 changes: 4 additions & 17 deletions autotests/pageObjects/pages/Main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Input} from 'autotests/pageObjects/components';
import {Main as MainRoute} from 'autotests/routes/pageRoutes';
import {createSelectorByCss} from 'autotests/selectors';
import {createRootLocator, type Locator} from 'create-locator';
import {createSelector} from 'autotests/selectors';
import {Page} from 'e2ed';
import {getCssSelectorFromAttributesChain} from 'e2ed/createLocator';
import {setReadonlyProperty} from 'e2ed/utils';

import type {Language} from 'autotests/types';
Expand All @@ -12,30 +10,19 @@ import type {GetParamsType, Selector} from 'e2ed/types';
type RouteParams = GetParamsType<MainRoute>;
type CustomPageParams = Partial<RouteParams> | undefined;

type MainLocator = Locator<{header: {}}>;

const mainPageLocator = createRootLocator<MainLocator, Selector>('google', {
mapAttributesChain: (attributesChain) => {
const cssSelector = getCssSelectorFromAttributesChain(attributesChain);

return createSelectorByCss(cssSelector);
},
pathAttribute: 'data-testid',
});

/**
* The Main (index) page.
*/
export class Main extends Page<CustomPageParams> {
/**
* Body selector.
*/
readonly body = createSelectorByCss('body');
readonly body: Selector = createSelector('body');

/**
* Header selector.
*/
readonly header = mainPageLocator.header();
readonly header: Selector = createSelector('[role=navigation]');

/**
* Page language.
Expand All @@ -45,7 +32,7 @@ export class Main extends Page<CustomPageParams> {
/**
* Search input.
*/
readonly searchInput = new Input('q');
readonly searchInput: Input = new Input('q');

/**
* Current value of search query.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {createSelectorFunctions} from 'e2ed/selectors';
import {createSelectorFunction} from 'e2ed/selectors';

import type {CreateSelector} from 'e2ed/types';

/**
* Main functions for creating selectors and working with selectors.
*/
export const {createSelector, createSelectorByCss, htmlElementSelector} = createSelectorFunctions({
export const createSelector: CreateSelector = createSelectorFunction({
getLocatorAttributeName: (parameter) => {
if (parameter === 'id') {
return 'data-testid';
Expand Down
8 changes: 8 additions & 0 deletions autotests/selectors/htmlElementSelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {createSelector} from './createSelector';

import type {Selector} from 'e2ed/types';

/**
* Selector of HTML element.
*/
export const htmlElementSelector: Selector = createSelector('html');
3 changes: 2 additions & 1 deletion autotests/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {createSelector} from './createSelector';
export {htmlElementSelector} from './htmlElementSelector';
export {inputSelector} from './inputSelector';
export {cssSelector, locator, testId} from './locator';
export {createSelector, createSelectorByCss, htmlElementSelector} from './selectorFunctions';
4 changes: 2 additions & 2 deletions autotests/selectors/inputSelector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {createSelectorByCss} from 'autotests/selectors';
import {createSelector} from './createSelector';

import type {Selector} from 'e2ed/types';

/**
* Selector of input (or textarea) element by name.
*/
export const inputSelector = (name: string): Selector => createSelectorByCss(`[name="${name}"]`);
export const inputSelector = (name: string): Selector => createSelector(`[name="${name}"]`);
30 changes: 22 additions & 8 deletions autotests/selectors/locator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import {attributesOptions} from 'autotests/constants';
import {createTestUtils} from 'e2ed/createLocator';

import {createSelectorByCss} from './selectorFunctions';
import {createSelector} from './createSelector';

import type {LocatorFunction} from 'create-locator';
import type {Selector} from 'e2ed/types';

/**
* Test utils, that produce `Selector`.
* Test utils, that produce `Selector`, CSS selector string and `testId` string.
*/
export const {
locator,
selector: cssSelector,
testId,
} = createTestUtils({
const utils = createTestUtils({
attributesOptions,
createLocatorByCssSelector: (selector) =>
createSelectorByCss(selector.replace('data-test-runhash', 'data-runhash')),
createSelector(selector.replace('data-test-runhash', 'data-runhash')),
supportWildcardsInCssSelectors: true,
});

/**
* Locator, that produce `Selector`.
*/
export const locator: LocatorFunction<Selector> = utils.locator;

/**
* Locator, that produce CSS selector string.
*/
export const cssSelector: LocatorFunction<string> = utils.selector;

/**
* Locator, that produce `testId` string.
*/
export const testId: LocatorFunction<string> = utils.testId;
4 changes: 2 additions & 2 deletions autotests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {createTestFunction} from 'e2ed';

import * as hooks from './hooks';

import type {Pack} from 'autotests/configurator';
import type {Pack, TestFunction} from 'autotests/configurator';

/**
* Test function that describes the test or the task
* (test does not necessarily contain checks).
*/
export const test = createTestFunction<Pack>(hooks);
export const test: TestFunction = createTestFunction<Pack>(hooks);
6 changes: 2 additions & 4 deletions autotests/tests/expect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */

import {test} from 'autotests';
import {createSelectorByCss} from 'autotests/selectors';
import {htmlElementSelector} from 'autotests/selectors';
import {getFullPackConfig} from 'autotests/utils';
import {expect} from 'e2ed';
import {assertFunctionThrows, getTimeoutPromise} from 'e2ed/utils';
Expand Down Expand Up @@ -41,8 +41,6 @@ test('expect function works correctly', {meta: {testId: '16'}}, async () => {
// eslint-disable-next-line @typescript-eslint/await-thenable
await expect(1, 'should be an eslint error when we do not call the assertion method');

const htmlSelector = createSelectorByCss('html');

// @ts-expect-error: expect function should not accept a selector as a actual value
await expect(htmlSelector, 'should be type error when actual value is a selector').ok();
await expect(htmlElementSelector, 'should be type error when actual value is a selector').ok();
});
13 changes: 2 additions & 11 deletions autotests/tests/internalTypeTests/selectors.skip.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
createSelector,
createSelectorByCss,
htmlElementSelector,
locator,
} from 'autotests/selectors';
import {createSelector, htmlElementSelector, locator} from 'autotests/selectors';

import type {Selector} from 'e2ed/types';

Expand All @@ -22,11 +17,7 @@ htmlElementSelector.find('body').findByLocatorId('id') satisfies Selector;

// ok
createSelector('id').findByLocatorId('id').find('body').findByLocatorId('id') satisfies Selector;
// ok
createSelectorByCss('id')
.findByLocatorId('id')
.find('body')
.findByLocatorId('id') satisfies Selector;

// ok
locator('id').findByLocatorId('id').find('body').findByLocatorId('id') satisfies Selector;

Expand Down
Loading

0 comments on commit 889b604

Please sign in to comment.