Skip to content

Commit

Permalink
feat(chat-e2e): publish single chat tests (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
irinakartun authored Oct 3, 2024
1 parent 7cdee44 commit e077478
Show file tree
Hide file tree
Showing 51 changed files with 1,442 additions and 265 deletions.
2 changes: 1 addition & 1 deletion apps/chat-e2e/src/assertions/api/shareApiAssertion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackendChatEntity } from '@/chat/types/common';
import { ShareEntity } from '@/shared/types';
import { ElementState, ExpectedMessages } from '@/src/testData';
import { ShareEntity } from '@epam/ai-dial-shared';
import { expect } from '@playwright/test';

export class ShareApiAssertion {
Expand Down
5 changes: 4 additions & 1 deletion apps/chat-e2e/src/assertions/conversationAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class ConversationAssertion extends SideBarEntityAssertion<ConversationsT
const conversationBackgroundColor =
await this.sideBarEntitiesTree.getEntityBackgroundColor(conversationName);
expect
.soft(conversationBackgroundColor, 'Conversation is selected')
.soft(
conversationBackgroundColor,
ExpectedMessages.conversationIsSelected,
)
.toBe(Colors.backgroundAccentSecondary);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PublishEntityAssertion } from '@/src/assertions/publishEntityAssertion';
import { ConversationsToApproveTree } from '@/src/ui/webElements/entityTree';

export class ConversationToApproveAssertion extends PublishEntityAssertion<ConversationsToApproveTree> {}
173 changes: 173 additions & 0 deletions apps/chat-e2e/src/assertions/entityTreeAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import {
CheckboxState,
ElementState,
ExpectedMessages,
TreeEntity,
} from '@/src/testData';
import { Styles } from '@/src/ui/domData';
import { EntitiesTree } from '@/src/ui/webElements/entityTree';
import { expect } from '@playwright/test';

export class EntityTreeAssertion<T extends EntitiesTree> {
readonly treeEntities: T;

constructor(treeEntities: T) {
this.treeEntities = treeEntities;
}

public async assertEntityState(
entity: TreeEntity,
expectedState: ElementState,
) {
const entityLocator = this.treeEntities.getEntityByName(
entity.name,
entity.index,
);
expectedState === 'visible'
? await expect
.soft(entityLocator, ExpectedMessages.entityIsVisible)
.toBeVisible()
: await expect
.soft(entityLocator, ExpectedMessages.entityIsNotVisible)
.toBeHidden();
}

public async assertEntityCheckbox(
entity: TreeEntity,
expectedState: ElementState,
) {
const entityCheckboxLocator = this.treeEntities.getEntityCheckbox(
entity.name,
entity.index,
);
expectedState === 'visible'
? await expect
.soft(entityCheckboxLocator, ExpectedMessages.entityIsChecked)
.toBeVisible()
: await expect
.soft(entityCheckboxLocator, ExpectedMessages.entityIsNotChecked)
.toBeHidden();
}

public async assertEntityCheckboxState(
entity: TreeEntity,
expectedState: CheckboxState,
) {
const message =
expectedState === CheckboxState.checked
? ExpectedMessages.entityIsChecked
: ExpectedMessages.entityIsNotChecked;
expect
.soft(
await this.treeEntities.getEntityCheckboxState(
entity.name,
entity.index,
),
message,
)
.toBe(expectedState);
}

public async assertEntityBackgroundColor(
entity: TreeEntity,
expectedColor: string,
) {
const entityBackgroundColor =
await this.treeEntities.getEntityBackgroundColor(
entity.name,
entity.index,
);
expect
.soft(
entityBackgroundColor,
ExpectedMessages.entityBackgroundColorIsValid,
)
.toBe(expectedColor);
}

public async assertEntityCheckboxColor(
entity: TreeEntity,
expectedColor: string,
) {
const checkboxElement = this.treeEntities.getEntityCheckboxElement(
entity.name,
entity.index,
);
const color = await checkboxElement.getComputedStyleProperty(Styles.color);
expect
.soft(color[0], ExpectedMessages.iconColorIsValid)
.toBe(expectedColor);
}

public async assertEntityCheckboxBorderColors(
entity: TreeEntity,
expectedColor: string,
) {
const checkboxElement = this.treeEntities.getEntityCheckboxElement(
entity.name,
entity.index,
);
const borderColors = await checkboxElement.getAllBorderColors();

Object.values(borderColors).forEach((borders) => {
borders.forEach((borderColor) => {
expect
.soft(borderColor, ExpectedMessages.borderColorsAreValid)
.toBe(expectedColor);
});
});
}

public async assertEntityIcon(entity: TreeEntity, expectedIcon: string) {
const entityIcon = await this.treeEntities.getEntityIcon(
entity.name,
entity.index,
);
expect
.soft(entityIcon, ExpectedMessages.entityIconIsValid)
.toBe(expectedIcon);
}

public async assertEntityArrowIconState(
entity: TreeEntity,
expectedState: ElementState,
) {
const arrowIcon = this.sideBarEntitiesTree.getEntityArrowIcon(
entity.name,
entity.index,
);
expectedState === 'visible'
? await expect
.soft(arrowIcon, ExpectedMessages.sharedEntityIconIsVisible)
.toBeVisible()
: await expect
.soft(arrowIcon, ExpectedMessages.sharedEntityIconIsNotVisible)
.toBeHidden();
}

public async assertEntityArrowIconColor(
entity: TreeEntity,
expectedColor: string,
) {
const arrowIconColor =
await this.sideBarEntitiesTree.getEntityArrowIconColor(
entity.name,
entity.index,
);
expect
.soft(arrowIconColor[0], ExpectedMessages.sharedIconColorIsValid)
.toBe(expectedColor);
}

public async assertEntityArrowIconsCount(
entity: TreeEntity,
expectedCount: number,
) {
const arrowIconsCount = await this.sideBarEntitiesTree
.getEntityArrowIcon(entity.name, entity.index)
.count();
expect
.soft(arrowIconsCount, ExpectedMessages.entitiesIconsCountIsValid)
.toBe(expectedCount);
}
}
6 changes: 3 additions & 3 deletions apps/chat-e2e/src/assertions/folderAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Folders } from '@/src/ui/webElements/entityTree';
import { ThemesUtil } from '@/src/utils/themesUtil';
import { expect } from '@playwright/test';

export class FolderAssertion {
readonly folder: Folders;
export class FolderAssertion<T extends Folders> {
readonly folder: T;

constructor(folder: Folders) {
constructor(folder: T) {
this.folder = folder;
}

Expand Down
32 changes: 32 additions & 0 deletions apps/chat-e2e/src/assertions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export * from './api/apiAssertion';
export * from './api/shareApiAssertion';

export * from './accountSettingsAssertion';
export * from './chatAssertion';
export * from './chatHeaderAssertion';
export * from './chatMessagesAssertion';
export * from './confirmationDialogAssertion';
export * from './conversationAssertion';
export * from './conversationToApproveAssertion';
export * from './downloadAssertion';
export * from './entitySettingAssertion';
export * from './entityTreeAssertion';
export * from './errorToastAssertion';
export * from './folderAssertion';
export * from './footerAssertion';
export * from './menuAssertion';
export * from './playbackAssertion';
export * from './promptAssertion';
export * from './promptListAssertion';
export * from './promptModalAssertion';
export * from './publishEntityAssertion';
export * from './publishingApprovalModalAssertion';
export * from './publishingRequestModalAssertion';
export * from './recentEntitiesAssertion';
export * from './sendMessageAssertion';
export * from './sharedPromptPreviewModalAssertion';
export * from './sharedWithMePromptsAssertion';
export * from './shareModalAssertion';
export * from './sideBarAssertion';
export * from './tooltipAssertion';
export * from './variableModalAssertion';
27 changes: 27 additions & 0 deletions apps/chat-e2e/src/assertions/publishEntityAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { EntityTreeAssertion } from '@/src/assertions/entityTreeAssertion';
import { PublishingExpectedMessages, TreeEntity } from '@/src/testData';
import { PublishEntitiesTree } from '@/src/ui/webElements/entityTree';
import { expect } from '@playwright/test';

export class PublishEntityAssertion<
T extends PublishEntitiesTree,
> extends EntityTreeAssertion<PublishEntitiesTree> {
readonly publishEntities: T;

constructor(publishEntities: T) {
super(publishEntities);
this.publishEntities = publishEntities;
}

public async assertEntityVersion(
entity: TreeEntity,
expectedVersion: string,
) {
await expect
.soft(
this.publishEntities.getEntityVersion(entity.name, entity.index),
PublishingExpectedMessages.entityVersionIsValid,
)
.toHaveText(expectedVersion);
}
}
118 changes: 118 additions & 0 deletions apps/chat-e2e/src/assertions/publishingApprovalModalAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Publication } from '@/chat/types/publication';
import {
ElementState,
ExpectedConstants,
ExpectedMessages,
PublishingExpectedMessages,
} from '@/src/testData';
import { BaseElement, PublishingApprovalModal } from '@/src/ui/webElements';
import { DateUtil } from '@/src/utils';
import { expect } from '@playwright/test';

export class PublishingApprovalModalAssertion {
readonly publishingApprovalModal: PublishingApprovalModal;

constructor(publishingApprovalModal: PublishingApprovalModal) {
this.publishingApprovalModal = publishingApprovalModal;
}

public async assertPublishingApprovalModalState(expectedState: ElementState) {
expectedState === 'visible'
? await expect
.soft(
this.publishingApprovalModal.getElementLocator(),
ExpectedMessages.modalWindowIsOpened,
)
.toBeVisible()
: await expect
.soft(
this.publishingApprovalModal.getElementLocator(),
ExpectedMessages.modalWindowIsClosed,
)
.toBeHidden();
}

public async assertPublishToLabelState(expectedState: ElementState) {
await this.assertElementState(
this.publishingApprovalModal.publishToPathLabel,
expectedState,
ExpectedConstants.publishToLabel,
);
}

public async assertPublishToPath(expectedPath: string) {
expect
.soft(
await this.publishingApprovalModal.publishToPath.getElementInnerContent(),
PublishingExpectedMessages.publishToPathIsValid,
)
.toBe(expectedPath);
}

public async assertRequestCreationDate(publicationRequest: Publication) {
expect
.soft(
await this.publishingApprovalModal.publishDate.getElementInnerContent(),
PublishingExpectedMessages.publishToPathIsValid,
)
.toBe(
DateUtil.convertUnixTimestampToLocalDate(publicationRequest.createdAt),
);
}

public async assertRequestCreationDateLabelState(
expectedState: ElementState,
) {
await this.assertElementState(
this.publishingApprovalModal.publishDateLabel,
expectedState,
ExpectedConstants.requestCreationDateLabel,
);
}

public async assertAllowAccessLabelState(expectedState: ElementState) {
await this.assertElementState(
this.publishingApprovalModal.allowAccessLabel,
expectedState,
ExpectedConstants.allowAccessLabel,
);
}

public async assertNoChangesLabelState(expectedState: ElementState) {
await this.assertElementState(
this.publishingApprovalModal.noChangesLabel,
expectedState,
ExpectedConstants.noChangesLabel,
);
}

public async assertAvailabilityLabelState(expectedState: ElementState) {
await this.assertElementState(
this.publishingApprovalModal.availabilityLabel,
expectedState,
ExpectedConstants.availabilityLabel,
);
}

public async assertElementState(
element: BaseElement,
expectedState: ElementState,
expectedText?: string,
) {
const elementLocator = element.getElementLocator();
if (expectedState === 'visible') {
await expect
.soft(elementLocator, ExpectedMessages.entityIsVisible)
.toBeVisible();
if (expectedText !== undefined) {
await expect
.soft(elementLocator, ExpectedMessages.fieldLabelIsValid)
.toHaveText(expectedText);
}
} else {
await expect
.soft(elementLocator, ExpectedMessages.entityIsVisible)
.toBeHidden();
}
}
}
Loading

0 comments on commit e077478

Please sign in to comment.