Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chat-e2e): implemented tests for prompt names #1823

Merged
merged 25 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions apps/chat-e2e/src/assertions/promptModalAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ExpectedMessages } from '@/src/testData';
import { Colors } from '@/src/ui/domData';
import { PromptModalDialog } from '@/src/ui/webElements';
import { expect } from '@playwright/test';

export class PromptModalAssertion {
readonly promptModalDialog: PromptModalDialog;

constructor(promptModalDialog: PromptModalDialog) {
this.promptModalDialog = promptModalDialog;
}

public async assertNameFieldIsInvalid(expectedErrorMessage: string) {
const nameBorderColors =
await this.promptModalDialog.name.getAllBorderColors();
Object.values(nameBorderColors).forEach((borders) => {
borders.forEach((borderColor) => {
expect
.soft(borderColor, ExpectedMessages.fieldIsHighlightedWithRed)
.toBe(Colors.textError);
});
});

const nameFieldErrorMessage = this.promptModalDialog.getFieldBottomMessage(
this.promptModalDialog.name,
);
await nameFieldErrorMessage.waitFor();

await expect
.soft(nameFieldErrorMessage, ExpectedMessages.promptNameInvalid)
.toHaveText(expectedErrorMessage);
}

public async assertNameFieldIsEmpty() {
expect
.soft(
await this.promptModalDialog.getName(),
ExpectedMessages.charactersAreNotDisplayed,
)
.toBe('');
}

public async assertPromptNameIsValid(expectedPromptName: string) {
expect
.soft(
await this.promptModalDialog.getName(),
ExpectedMessages.promptNameValid,
)
.toBe(expectedPromptName);
}
}
6 changes: 6 additions & 0 deletions apps/chat-e2e/src/core/dialFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FolderAssertion } from '@/src/assertions/folderAssertion';
import { FooterAssertion } from '@/src/assertions/footerAssertion';
import { MenuAssertion } from '@/src/assertions/menuAssertion';
import { PromptListAssertion } from '@/src/assertions/promptListAssertion';
import { PromptModalAssertion } from '@/src/assertions/promptModalAssertion';
import { SendMessageAssertion } from '@/src/assertions/sendMessageAssertion';
import { SettingsModalAssertion } from '@/src/assertions/settingsModalAssertion';
import { SideBarAssertion } from '@/src/assertions/sideBarAssertion';
Expand Down Expand Up @@ -187,6 +188,7 @@ const dialTest = test.extend<
conversationAssertion: SideBarEntityAssertion;
chatBarFolderAssertion: FolderAssertion;
errorToastAssertion: ErrorToastAssertion;
promptModalAssertion: PromptModalAssertion;
tooltipAssertion: TooltipAssertion;
confirmationDialogAssertion: ConfirmationDialogAssertion;
chatBarAssertion: SideBarAssertion;
Expand Down Expand Up @@ -625,6 +627,10 @@ const dialTest = test.extend<
const promptErrorToastAssertion = new ErrorToastAssertion(errorToast);
await use(promptErrorToastAssertion);
},
promptModalAssertion: async ({ promptModalDialog }, use) => {
const promptModalAssertion = new PromptModalAssertion(promptModalDialog);
await use(promptModalAssertion);
},
tooltipAssertion: async ({ tooltip }, use) => {
const tooltipAssertion = new TooltipAssertion(tooltip);
await use(tooltipAssertion);
Expand Down
1 change: 1 addition & 0 deletions apps/chat-e2e/src/testData/expectedMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum ExpectedMessages {
promptModalClosed = 'Prompt modal dialog is closed',
promptNotUpdated = 'Prompt is not updated',
promptNameValid = 'Prompt name is valid',
promptNameInvalid = 'Prompt name is not valid',
promptDescriptionValid = 'Prompt description is valid',
promptContentValid = 'Prompt content is valid',
promptVariablePlaceholderValid = 'Prompt variable placeholder is valid',
Expand Down
6 changes: 5 additions & 1 deletion apps/chat-e2e/src/testData/prompts/promptData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export class PromptData extends FolderData {

public prepareDefaultPrompt(name?: string) {
const promptName = name ?? GeneratorUtil.randomString(10);
return this.promptBuilder.withName(promptName).withId(promptName).build();
return this.promptBuilder
.withName(promptName)
.withId(promptName)
.withContent(promptName)
.build();
}

public prepareDefaultSharedPrompt(name?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dialTest(
{ name: expectedFolderName },
'visible',
);
errorToastAssertion.assertToastIsHidden();
await errorToastAssertion.assertToastIsHidden();
},
);

Expand Down
172 changes: 172 additions & 0 deletions apps/chat-e2e/src/tests/promptMaximumNameLength.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import dialTest from '@/src/core/dialFixtures';
import {
ExpectedConstants,
ExpectedMessages,
MenuOptions,
} from '@/src/testData';
import { Overflow, Styles } from '@/src/ui/domData';
import { expect } from '@playwright/test';

dialTest(
'Prompt name consists of a maximum of 160 symbols.\n' +
'Long prompt name is cut in the panel.\n' +
'Prompt folder name consists of a maximum of 160 symbols',
async ({
dialHomePage,
promptData,
dataInjector,
prompts,
promptDropdownMenu,
promptModalDialog,
errorToastAssertion,
promptAssertion,
setTestIds,
promptBarFolderAssertion,
promptBar,
folderPrompts,
}) => {
setTestIds('EPMRTC-3171', 'EPMRTC-958', 'EPMRTC-3168');
const prompt = promptData.prepareDefaultPrompt();
await dataInjector.createPrompts([prompt]);
const longName =
'Lorem ipsum dolor sit amett consectetur adipiscing elit. Nullam ultricies ipsum nullaa nec viverra lectus rutrum id. Sed volutpat ante ac fringilla turpis duis!ABC';
const expectedName = longName.substring(
0,
ExpectedConstants.maxEntityNameLength,
);
const nameUnder160Symbols =
'This prompt is renamed to very long-long-long name to see how the system cuts the name';

await dialTest.step(
'Create a prompt and enter text longer than 160 symbols',
async () => {
await dialHomePage.openHomePage();
await dialHomePage.waitForPageLoaded({
isNewConversationVisible: true,
});
await promptBar.createNewPrompt();
await promptModalDialog.setField(promptModalDialog.name, longName);
await promptModalDialog.setField(
promptModalDialog.prompt,
ExpectedConstants.newPromptTitle(1),
);
},
);

await dialTest.step('Save the prompt', async () => {
await promptModalDialog.saveButton.click();
});

await dialTest.step(
'Verify the prompt name is cut to 160 symbols and no error toast is shown',
async () => {
await promptAssertion.assertEntityState(
{ name: expectedName },
'visible',
);
await errorToastAssertion.assertToastIsHidden();
},
);

await dialTest.step('Rename the prompt to a long name', async () => {
await prompts.openEntityDropdownMenu(expectedName);
await promptDropdownMenu.selectMenuOption(MenuOptions.edit);
await promptModalDialog.setField(
promptModalDialog.name,
nameUnder160Symbols,
);
// Wait for the API request to update the prompt name
await promptModalDialog.updatePromptDetailsWithButton(
nameUnder160Symbols,
prompt.description,
prompt.content!,
);
prompt.name = nameUnder160Symbols;
});

await dialTest.step('Check the prompt name in the panel', async () => {
const promptNameElement = prompts.getPromptName(prompt.name);
const promptNameOverflow =
await promptNameElement.getComputedStyleProperty(Styles.text_overflow);
expect
.soft(promptNameOverflow[0], ExpectedMessages.entityNameIsTruncated)
.toBe(Overflow.ellipsis);
});

await dialTest.step(
'Hover over the prompt name and check the name in the panel',
async () => {
await prompts.getPromptName(prompt.name).hoverOver();
await promptAssertion.assertEntityDotsMenuState(
{ name: prompt.name },
'visible',
);
},
);

await dialTest.step(
'Create two folders: Folder_parent -> Folder_child',
async () => {
for (let i = 1; i <= 2; i++) {
await promptBar.createNewFolder();
await promptBarFolderAssertion.assertFolderState(
{ name: ExpectedConstants.newPromptFolderWithIndexTitle(i) },
'visible',
);
}

await promptBar.dragAndDropEntityToFolder(
folderPrompts.getFolderByName(
ExpectedConstants.newPromptFolderWithIndexTitle(2),
),
folderPrompts.getFolderByName(
ExpectedConstants.newPromptFolderWithIndexTitle(1),
),
);
},
);

await dialTest.step(
'Edit both folder names with more than 160 symbols names',
async () => {
// Rename Folder_parent
await folderPrompts.openFolderDropdownMenu(
ExpectedConstants.newPromptFolderWithIndexTitle(1),
);
await promptDropdownMenu.selectMenuOption(MenuOptions.rename);
await folderPrompts.editFolderNameWithTick(longName);

// Rename folder_child
await folderPrompts.openFolderDropdownMenu(
ExpectedConstants.newPromptFolderWithIndexTitle(2),
);
await promptDropdownMenu.selectMenuOption(MenuOptions.rename);
await folderPrompts.editFolderNameWithTick(longName);
},
);

await dialTest.step(
'Check that the folder names are cut to 160 symbols and no error message appears',
async () => {
// Get the actual folder names
const parentFolderName = await folderPrompts
.getFolderName(expectedName, 1)
.getElementInnerContent();
const childFolderName = await folderPrompts
.getFolderName(expectedName, 2)
.getElementInnerContent();

// Assert that the names are truncated to the expectedName
expect
.soft(parentFolderName, ExpectedMessages.folderNameUpdated)
.toBe(expectedName);
expect
.soft(childFolderName, ExpectedMessages.folderNameUpdated)
.toBe(expectedName);

// Assert that no error toast is shown
await errorToastAssertion.assertToastIsHidden();
},
);
},
);
Loading