Skip to content

Commit

Permalink
feat(chat-e2e): view shared prompt tests (#2059)
Browse files Browse the repository at this point in the history
  • Loading branch information
irinakartun authored Sep 6, 2024
1 parent 0f37d37 commit 7a24d2a
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 4 deletions.
16 changes: 16 additions & 0 deletions apps/chat-e2e/src/assertions/downloadAssertion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ExpectedMessages } from '@/src/testData';
import { UploadDownloadData } from '@/src/ui/pages';
import { FileUtil } from '@/src/utils';
import { expect } from '@playwright/test';

export class DownloadAssertion {
Expand All @@ -9,4 +11,18 @@ export class DownloadAssertion {
expect(downloadedData.path).toBeTruthy();
expect(downloadedData.path).toMatch(new RegExp(`${expectedExtension}$`));
}

public async assertFileIsDownloaded(downloadedData: UploadDownloadData) {
const downloadedFiles = FileUtil.getExportedFiles();
expect
.soft(
downloadedFiles?.find(
(f) =>
f.includes(downloadedData.path) &&
FileUtil.readFileData(downloadedData.path) !== undefined,
),
ExpectedMessages.dataIsExported,
)
.toBeDefined();
}
}
20 changes: 19 additions & 1 deletion apps/chat-e2e/src/assertions/promptModalAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,30 @@ export class PromptModalAssertion {
.toBe('');
}

public async assertPromptNameIsValid(expectedPromptName: string) {
public async assertPromptName(expectedPromptName: string) {
expect
.soft(
await this.promptModalDialog.getName(),
ExpectedMessages.promptNameValid,
)
.toBe(expectedPromptName);
}

public async assertPromptDescription(expectedValue: string | undefined) {
expect
.soft(
await this.promptModalDialog.getDescription(),
ExpectedMessages.promptDescriptionValid,
)
.toBe(expectedValue ?? '');
}

public async assertPromptContent(expectedValue: string) {
expect
.soft(
await this.promptModalDialog.getPrompt(),
ExpectedMessages.promptContentValid,
)
.toBe(expectedValue);
}
}
39 changes: 39 additions & 0 deletions apps/chat-e2e/src/assertions/sharedPromptPreviewModalAssertion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ElementState, ExpectedMessages } from '@/src/testData';
import { Styles } from '@/src/ui/domData';
import { SharedPromptPreviewModal } from '@/src/ui/webElements';
import { expect } from '@playwright/test';

Expand Down Expand Up @@ -67,4 +68,42 @@ export class SharedPromptPreviewModalAssertion {
)
.toBe(expectedValue);
}

public async assertExportButtonColors(expectedColor: string) {
const buttonColor =
await this.sharedPromptPreviewModal.promptExportButton.getComputedStyleProperty(
Styles.color,
);
const buttonBordersColor =
await this.sharedPromptPreviewModal.promptExportButton.getAllBorderColors();
expect
.soft(buttonColor[0], ExpectedMessages.elementColorIsValid)
.toBe(expectedColor);
Object.values(buttonBordersColor).forEach((borders) => {
borders.forEach((borderColor) => {
expect
.soft(borderColor, ExpectedMessages.borderColorsAreValid)
.toBe(expectedColor);
});
});
}

public async assertDeleteButtonColors(expectedColor: string) {
const buttonColor =
await this.sharedPromptPreviewModal.promptDeleteButton.getComputedStyleProperty(
Styles.color,
);
const buttonBordersColor =
await this.sharedPromptPreviewModal.promptDeleteButton.getAllBorderColors();
expect
.soft(buttonColor[0], ExpectedMessages.elementColorIsValid)
.toBe(expectedColor);
Object.values(buttonBordersColor).forEach((borders) => {
borders.forEach((borderColor) => {
expect
.soft(borderColor, ExpectedMessages.borderColorsAreValid)
.toBe(expectedColor);
});
});
}
}
52 changes: 52 additions & 0 deletions apps/chat-e2e/src/core/dialSharedWithMeFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ErrorToast,
FolderPrompts,
PromptBar,
PromptModalDialog,
Prompts,
RecentEntities,
SendMessage,
Expand All @@ -24,8 +25,11 @@ import {
} from '../ui/webElements';

import config from '@/config/chat.playwright.config';
import { ConfirmationDialogAssertion } from '@/src/assertions/confirmationDialogAssertion';
import { FolderAssertion } from '@/src/assertions/folderAssertion';
import { MenuAssertion } from '@/src/assertions/menuAssertion';
import { PromptAssertion } from '@/src/assertions/promptAssertion';
import { PromptModalAssertion } from '@/src/assertions/promptModalAssertion';
import { SendMessageAssertion } from '@/src/assertions/sendMessageAssertion';
import { SharedPromptPreviewModalAssertion } from '@/src/assertions/sharedPromptPreviewModalAssertion';
import { SharedWithMePromptsAssertion } from '@/src/assertions/sharedWithMePromptsAssertion';
Expand Down Expand Up @@ -64,6 +68,7 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserFolderDropdownMenu: DropdownMenu;
additionalShareUserSharedWithMeFolderDropdownMenu: DropdownMenu;
additionalShareUserSharedWithMeConversationDropdownMenu: DropdownMenu;
additionalShareUserSharedWithMePromptDropdownMenu: DropdownMenu;
additionalShareUserConversations: Conversations;
additionalShareUserPrompts: Prompts;
additionalShareUserCompare: Compare;
Expand All @@ -75,13 +80,17 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserPromptPreviewModal: SharedPromptPreviewModal;
additionalShareUserVariableModalDialog: VariableModalDialog;
additionalShareUserPromptDropdownMenu: DropdownMenu;
additionalShareUserPromptModalDialog: PromptModalDialog;
additionalShareUserSharedWithMePromptAssertion: SharedWithMePromptsAssertion;
additionalShareUserSharedPromptPreviewModalAssertion: SharedPromptPreviewModalAssertion;
additionalShareUserSendMessageAssertion: SendMessageAssertion;
additionalShareUserVariableModalAssertion: VariableModalAssertion;
additionalShareUserSharedFolderPromptsAssertions: FolderAssertion;
additionalShareUserPromptsDropdownMenuAssertion: MenuAssertion;
additionalShareUserFolderDropdownMenuAssertion: MenuAssertion;
additionalShareUserConfirmationDialogAssertion: ConfirmationDialogAssertion;
additionalShareUserPromptAssertion: PromptAssertion;
additionalShareUserPromptModalAssertion: PromptModalAssertion;
}>({
additionalShareUserPage: async ({ browser }, use) => {
const context = await browser.newContext({
Expand Down Expand Up @@ -247,6 +256,14 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserSharedWithMeConversations.getDropdownMenu();
await use(additionalShareUserSharedWithMeConversationDropdownMenu);
},
additionalShareUserSharedWithMePromptDropdownMenu: async (
{ additionalShareUserSharedWithMePrompts },
use,
) => {
const additionalShareUserSharedWithMePromptDropdownMenu =
additionalShareUserSharedWithMePrompts.getDropdownMenu();
await use(additionalShareUserSharedWithMePromptDropdownMenu);
},
additionalShareUserFolderPrompts: async (
{ additionalShareUserPromptBar },
use,
Expand Down Expand Up @@ -328,6 +345,15 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserPrompts.getDropdownMenu();
await use(additionalShareUserPromptDropdownMenu);
},
additionalShareUserPromptModalDialog: async (
{ additionalShareUserPage },
use,
) => {
const additionalShareUserPromptModalDialog = new PromptModalDialog(
additionalShareUserPage,
);
await use(additionalShareUserPromptModalDialog);
},
additionalShareUserSharedWithMePromptAssertion: async (
{ additionalShareUserSharedWithMePrompts },
use,
Expand Down Expand Up @@ -389,6 +415,32 @@ const dialSharedWithMeTest = dialTest.extend<{
);
await use(additionalShareUserFolderDropdownMenuAssertion);
},
additionalShareUserConfirmationDialogAssertion: async (
{ additionalShareUserConfirmationDialog },
use,
) => {
const additionalShareUserConfirmationDialogAssertion =
new ConfirmationDialogAssertion(additionalShareUserConfirmationDialog);
await use(additionalShareUserConfirmationDialogAssertion);
},
additionalShareUserPromptAssertion: async (
{ additionalShareUserPrompts },
use,
) => {
const additionalShareUserPromptAssertion = new PromptAssertion(
additionalShareUserPrompts,
);
await use(additionalShareUserPromptAssertion);
},
additionalShareUserPromptModalAssertion: async (
{ additionalShareUserPromptModalDialog },
use,
) => {
const additionalShareUserPromptModalAssertion = new PromptModalAssertion(
additionalShareUserPromptModalDialog,
);
await use(additionalShareUserPromptModalAssertion);
},
});

export let shareUserBucket: string;
Expand Down
5 changes: 5 additions & 0 deletions apps/chat-e2e/src/testData/expectedConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export const ExpectedConstants = {
'Model changing will stop sharing and other users will no longer see this conversation.',
renameSharedPromptMessage:
'Renaming will stop sharing and other users will no longer see this prompt.',
deletePromptConfirmationModalTitle: 'Confirm deleting prompt',
deletePromptConfirmationModalMessage:
'Are you sure that you want to delete a prompt?',
unshareFolderMessage: 'Are you sure that you want to unshare this folder?',
backgroundColorPattern: /(rgba\(\d+,\s*\d+,\s*\d+),\s*\d+\.*\d+\)/,
sendMessageTooltip: 'Please type a message',
Expand Down Expand Up @@ -169,6 +172,7 @@ export const ExpectedConstants = {
) =>
`Prompt limit is ${maxPromptTokens} tokens. You have entered ${enteredTokens} tokens and are trying to select a prompt with more than ${remainedTokes} tokens. 1 token approximately equals to 4 characters.`,
replayVariableModalTitle: 'Please, enter variables for template:',
exportedFileExtension: 'json',
};

export enum Groups {
Expand Down Expand Up @@ -202,6 +206,7 @@ export enum MenuOptions {
attachFolders = 'Attach folders',
attachLink = 'Attach link',
select = 'Select',
view = 'View',
}

export enum FilterMenuOptions {
Expand Down
2 changes: 1 addition & 1 deletion apps/chat-e2e/src/tests/promptsNames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dialTest(
await dialHomePage.copyToClipboard(nameWithRestrictedChars);
await promptModalDialog.name.click();
await dialHomePage.pasteFromClipboard();
await promptModalAssertion.assertPromptNameIsValid(expectedPromptName);
await promptModalAssertion.assertPromptName(expectedPromptName);
await promptModalDialog.saveButton.click();
prompt.name = expectedPromptName;
},
Expand Down
Loading

0 comments on commit 7a24d2a

Please sign in to comment.