Skip to content

Commit

Permalink
feat(chat-e2e): overlay sandbox component (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
irinakartun authored Dec 27, 2024
1 parent 1d196c0 commit 37b9936
Show file tree
Hide file tree
Showing 32 changed files with 892 additions and 634 deletions.
1 change: 1 addition & 0 deletions apps/chat-e2e/config/local.overlay.playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ReporterDescription } from '@playwright/test';
/**
* Config used for overlay local run
*/
config.use!.headless = false;
config.retries = 0;
config.timeout = 300000;
config.use!.video = 'on';
Expand Down
45 changes: 45 additions & 0 deletions apps/chat-e2e/src/assertions/overlay/overlayAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BaseAssertion } from '@/src/assertions';
import { ExpectedMessages } from '@/src/testData';
import { Attributes } from '@/src/ui/domData';
import { BaseElement } from '@/src/ui/webElements';
import { expect } from '@playwright/test';

const translatePropertyRegex = /translate\((\d+)px,\s*(\d+)px\)/;
const propertyNotDefinedError =
'Translate property is not defined for the element!';

export class OverlayAssertion extends BaseAssertion {
public async assertOverlayManagerIsVisible(overlayContainer: BaseElement) {
const styleAttribute = await overlayContainer
.getElementLocator()
.getAttribute(Attributes.style);
const match = styleAttribute?.match(translatePropertyRegex);
if (match) {
expect.soft(+match[1], ExpectedMessages.elementIsVisible).toBe(0);
expect.soft(+match[2], ExpectedMessages.elementIsVisible).toBe(0);
} else {
throw new Error(propertyNotDefinedError);
}
}

public async assertOverlayManagerIsHidden(
overlayContainer: BaseElement,
viewportSize: { width: number; height: number },
) {
const styleAttribute = await overlayContainer
.getElementLocator()
.getAttribute(Attributes.style);
const translateRegex = /translate\((\d+)px,\s*(\d+)px\)/;
const match = styleAttribute?.match(translateRegex);
if (match) {
expect
.soft(+match[1], ExpectedMessages.elementIsNotVisible)
.toBeGreaterThan(viewportSize.width);
expect
.soft(+match[2], ExpectedMessages.elementIsNotVisible)
.toBeGreaterThan(viewportSize.height);
} else {
throw new Error(propertyNotDefinedError);
}
}
}
67 changes: 47 additions & 20 deletions apps/chat-e2e/src/core/baseFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { KeycloakPage, LoginPage } from '@/src/ui/pages';
import { Auth0Page } from '@/src/ui/pages/auth0Page';
import { AzureADPage } from '@/src/ui/pages/azureADPage';
import { Page, test as base } from '@playwright/test';
import { allure } from 'allure-playwright';
import * as process from 'node:process';

export const skipReason = 'Execute test on CI env only';
Expand All @@ -17,26 +18,52 @@ export const noSimpleModelSkipReason =
export const noImportModelsSkipReason =
'Skip the test if imported models are not configured';

const test = base.extend<{
loginPage: LoginPage;
auth0Page: Auth0Page;
azureADPage: AzureADPage;
keycloakPage: KeycloakPage;
localStorageManager: LocalStorageManager;
auth0Login: ProviderLogin<Auth0Page>;
azureADLogin: ProviderLogin<AzureADPage>;
keycloakLogin: ProviderLogin<KeycloakPage>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
providerLogin: ProviderLogin<any>;
incognitoPage: Page;
incognitoLoginPage: LoginPage;
incognitoAuth0Page: Auth0Page;
incognitoLocalStorageManager: LocalStorageManager;
incognitoAuth0Login: ProviderLogin<Auth0Page>;
baseAssertion: BaseAssertion;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
incognitoProviderLogin: ProviderLogin<any>;
}>({
interface ReportAttributes {
setTestIds: (...testId: string[]) => void;
setIssueIds: (...issueIds: string[]) => void;
}

const test = base.extend<
ReportAttributes & {
loginPage: LoginPage;
auth0Page: Auth0Page;
azureADPage: AzureADPage;
keycloakPage: KeycloakPage;
localStorageManager: LocalStorageManager;
auth0Login: ProviderLogin<Auth0Page>;
azureADLogin: ProviderLogin<AzureADPage>;
keycloakLogin: ProviderLogin<KeycloakPage>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
providerLogin: ProviderLogin<any>;
incognitoPage: Page;
incognitoLoginPage: LoginPage;
incognitoAuth0Page: Auth0Page;
incognitoLocalStorageManager: LocalStorageManager;
incognitoAuth0Login: ProviderLogin<Auth0Page>;
baseAssertion: BaseAssertion;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
incognitoProviderLogin: ProviderLogin<any>;
}
>({
// eslint-disable-next-line no-empty-pattern
setTestIds: async ({}, use) => {
const callback = (...testIds: string[]) => {
for (const testId of testIds) {
allure.tms(testId, `${process.env.TMS_URL}/${testId}`);
}
};
await use(callback);
},
// eslint-disable-next-line no-empty-pattern
setIssueIds: async ({}, use) => {
const callback = (...issueIds: string[]) => {
for (const issueId of issueIds) {
allure.issue(issueId, `${process.env.ISSUE_URL}/${issueId}`);
test.skip();
}
};
await use(callback);
},
// eslint-disable-next-line no-empty-pattern
baseAssertion: async ({}, use) => {
const baseAssertion = new BaseAssertion();
Expand Down
Loading

0 comments on commit 37b9936

Please sign in to comment.