Skip to content

Commit

Permalink
feat(chat-e2e): duplicate shared prompt tests (#2076)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Nartov <[email protected]>
  • Loading branch information
irinakartun and nartovm authored Sep 12, 2024
1 parent 7cc8b0d commit 07d26fa
Show file tree
Hide file tree
Showing 14 changed files with 427 additions and 47 deletions.
28 changes: 28 additions & 0 deletions apps/chat-e2e/src/assertions/api/apiAssertion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChatBody } from '@/chat/types/chat';
import { DialAIEntityModel } from '@/chat/types/models';
import { Prompt } from '@/chat/types/prompt';
import { ExpectedConstants, ExpectedMessages } from '@/src/testData';
import { expect } from '@playwright/test';
import { APIResponse } from 'playwright-core';
Expand Down Expand Up @@ -102,4 +103,31 @@ export class ApiAssertion {
.toBeDefined();
}
}

public async assertRequestPromptName(request: Prompt, expectedValue: string) {
expect
.soft(request.name, ExpectedMessages.promptRequestNameIsValid)
.toBe(expectedValue);
}

public async assertRequestPromptDescription(
request: Prompt,
expectedValue: string,
) {
expect
.soft(
request.description,
ExpectedMessages.promptRequestDescriptionIsValid,
)
.toBe(expectedValue);
}

public async assertRequestPromptContent(
request: Prompt,
expectedValue: string,
) {
expect
.soft(request.content, ExpectedMessages.promptRequestContentIsValid)
.toBe(expectedValue);
}
}
33 changes: 24 additions & 9 deletions apps/chat-e2e/src/assertions/promptListAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export class PromptListAssertion {
this.promptList = promptList;
}

public async assertPromptOptionOverflow(name: string) {
public async assertPromptOptionOverflow(
name: string,
expectedOverflow: Overflow,
) {
const promptOptionOverflow = await this.promptList
.getPromptOption(name)
.getComputedStyleProperty(Styles.text_overflow);
expect
.soft(promptOptionOverflow[0], ExpectedMessages.entityNameIsTruncated)
.toBe(Overflow.ellipsis);
.toBe(expectedOverflow);
}

public async assertPromptListState(expectedState: ElementState) {
Expand All @@ -35,12 +38,24 @@ export class PromptListAssertion {
.toBeHidden();
}

public async assertPromptListOptions(expectedOptions: string[]) {
expect
.soft(
await this.promptList.getPromptOptions().getElementsInnerContent(),
ExpectedMessages.promptListValuesIsValid,
)
.toEqual(expectedOptions);
public async assertPromptListOptions(
expectedIncludedOptions: string[],
expectedExcludedOptions?: string[],
) {
const listOptions = await this.promptList
.getPromptOptions()
.getElementsInnerContent();
for (const includedOption of expectedIncludedOptions) {
expect
.soft(listOptions, ExpectedMessages.promptListValuesIsValid)
.toContain(includedOption);
}
if (expectedExcludedOptions) {
for (const excludedOption of expectedExcludedOptions) {
expect
.soft(listOptions, ExpectedMessages.promptListValuesIsValid)
.not.toContain(excludedOption);
}
}
}
}
4 changes: 2 additions & 2 deletions apps/chat-e2e/src/assertions/sendMessageAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class SendMessageAssertion {
.toBe(initialWidth);
}

public async assertMessageValue(expectedValue: string) {
public async assertMessageValue(expectedValue: string | undefined) {
const messageValue = await this.sendMessage.getMessage();
expect
.soft(messageValue, ExpectedMessages.messageContentIsValid)
.toBe(expectedValue);
.toBe(expectedValue ?? '');
}

public async assertContinueReplayButtonState(expectedState: ElementState) {
Expand Down
42 changes: 42 additions & 0 deletions apps/chat-e2e/src/core/dialSharedWithMeFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Conversations,
DropdownMenu,
EntitySelector,
EntitySettings,
ErrorToast,
FolderPrompts,
PromptBar,
Expand All @@ -26,9 +27,11 @@ import {

import config from '@/config/chat.playwright.config';
import { ConfirmationDialogAssertion } from '@/src/assertions/confirmationDialogAssertion';
import { EntitySettingAssertion } from '@/src/assertions/entitySettingAssertion';
import { FolderAssertion } from '@/src/assertions/folderAssertion';
import { MenuAssertion } from '@/src/assertions/menuAssertion';
import { PromptAssertion } from '@/src/assertions/promptAssertion';
import { PromptListAssertion } from '@/src/assertions/promptListAssertion';
import { PromptModalAssertion } from '@/src/assertions/promptModalAssertion';
import { SendMessageAssertion } from '@/src/assertions/sendMessageAssertion';
import { SharedPromptPreviewModalAssertion } from '@/src/assertions/sharedPromptPreviewModalAssertion';
Expand Down Expand Up @@ -58,6 +61,7 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserSharedFolderPrompts: SharedFolderPrompts;
additionalShareUserChat: Chat;
additionalShareUserConversationSettings: ConversationSettings;
additionalShareUserEntitySettings: EntitySettings;
additionalShareUserTalkToSelector: EntitySelector;
additionalShareUserRecentEntities: RecentEntities;
additionalShareUserChatHeader: ChatHeader;
Expand Down Expand Up @@ -91,6 +95,9 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserConfirmationDialogAssertion: ConfirmationDialogAssertion;
additionalShareUserPromptAssertion: PromptAssertion;
additionalShareUserPromptModalAssertion: PromptModalAssertion;
additionalShareUserPromptBarFolderAssertion: FolderAssertion;
additionalShareUserSystemPromptListAssertion: PromptListAssertion;
additionalShareUserEntitySettingAssertion: EntitySettingAssertion;
}>({
additionalShareUserPage: async ({ browser }, use) => {
const context = await browser.newContext({
Expand Down Expand Up @@ -208,6 +215,14 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserAppContainer.getConversationSettings();
await use(additionalShareUserConversationSettings);
},
additionalShareUserEntitySettings: async (
{ additionalShareUserConversationSettings },
use,
) => {
const additionalShareUserEntitySettings =
additionalShareUserConversationSettings.getEntitySettings();
await use(additionalShareUserEntitySettings);
},
additionalShareUserTalkToSelector: async (
{ additionalShareUserConversationSettings },
use,
Expand Down Expand Up @@ -441,6 +456,33 @@ const dialSharedWithMeTest = dialTest.extend<{
);
await use(additionalShareUserPromptModalAssertion);
},
additionalShareUserPromptBarFolderAssertion: async (
{ additionalShareUserFolderPrompts },
use,
) => {
const additionalShareUserPromptBarFolderAssertion = new FolderAssertion(
additionalShareUserFolderPrompts,
);
await use(additionalShareUserPromptBarFolderAssertion);
},
additionalShareUserSystemPromptListAssertion: async (
{ additionalShareUserEntitySettings },
use,
) => {
const additionalShareUserSystemPromptListAssertion =
new PromptListAssertion(
additionalShareUserEntitySettings.getPromptList(),
);
await use(additionalShareUserSystemPromptListAssertion);
},
additionalShareUserEntitySettingAssertion: async (
{ additionalShareUserEntitySettings },
use,
) => {
const additionalShareUserEntitySettingAssertion =
new EntitySettingAssertion(additionalShareUserEntitySettings);
await use(additionalShareUserEntitySettingAssertion);
},
});

export let shareUserBucket: string;
Expand Down
3 changes: 3 additions & 0 deletions apps/chat-e2e/src/testData/expectedMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export enum ExpectedMessages {
chatRequestAddonsAreValid = 'Chat API request addons are valid',
chatRequestMessageIsValid = 'Chat API request message is valid',
chatRequestAttachmentIsValid = 'Chat API request attachment is valid',
promptRequestNameIsValid = 'Prompt API request name is valid',
promptRequestDescriptionIsValid = 'Prompt API request description is valid',
promptRequestContentIsValid = 'Prompt API request content is valid',
sendMessageButtonDisabled = 'Send message button is disabled',
sendMessageButtonEnabled = 'Send message button is enabled',
tooltipContentIsValid = 'Tooltip content is valid',
Expand Down
6 changes: 4 additions & 2 deletions apps/chat-e2e/src/tests/compareMode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ dialTest(
.selectModel(firstUpdatedRandomModel);
const leftEntitySettings = leftConversationSettings.getEntitySettings();
if (firstUpdatedRandomModel.features?.systemPrompt) {
await leftEntitySettings.setSystemPrompt(firstUpdatedPrompt);
await leftEntitySettings.clearAndSetSystemPrompt(firstUpdatedPrompt);
}
await leftEntitySettings
.getTemperatureSlider()
Expand All @@ -734,7 +734,9 @@ dialTest(
const rightEntitySettings =
rightConversationSettings.getEntitySettings();
if (secondUpdatedRandomModel.features?.systemPrompt) {
await rightEntitySettings.setSystemPrompt(secondUpdatedPrompt);
await rightEntitySettings.clearAndSetSystemPrompt(
secondUpdatedPrompt,
);
}
await rightEntitySettings
.getTemperatureSlider()
Expand Down
118 changes: 118 additions & 0 deletions apps/chat-e2e/src/tests/duplicateSharedPrompts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { ShareByLinkResponseModel } from '@/chat/types/share';
import dialSharedWithMeTest from '@/src/core/dialSharedWithMeFixtures';
import { ExpectedConstants, FolderPrompt, MenuOptions } from '@/src/testData';

dialSharedWithMeTest(
'Shared with me. Duplicate prompt.\n' +
'Shared with me. Move duplicated prompt to New folder',
async ({
additionalShareUserDialHomePage,
promptData,
dataInjector,
mainUserShareApiHelper,
additionalUserShareApiHelper,
additionalShareUserSharedFolderPrompts,
additionalShareUserSharedWithMePromptDropdownMenu,
additionalShareUserPrompts,
additionalShareUserPromptBarFolderAssertion,
additionalShareUserPromptDropdownMenu,
additionalShareUserFolderPrompts,
additionalShareUserPromptAssertion,
setTestIds,
}) => {
setTestIds('EPMRTC-1872', 'EPMRTC-2037');
let folderPrompt: FolderPrompt;
let promptName: string;
let shareFolderByLinkResponse: ShareByLinkResponseModel;

await dialSharedWithMeTest.step(
'Prepare folder with prompt and share it',
async () => {
folderPrompt = promptData.prepareDefaultPromptInFolder();
promptName = folderPrompt.prompts[0].name;
await dataInjector.createPrompts(
folderPrompt.prompts,
folderPrompt.folders,
);
shareFolderByLinkResponse =
await mainUserShareApiHelper.shareEntityByLink(
folderPrompt.prompts,
true,
);
await additionalUserShareApiHelper.acceptInvite(
shareFolderByLinkResponse,
);
},
);

await dialSharedWithMeTest.step(
'Select "Duplicate" option in dropdown menu for shared folder prompt and verify prompt is duplicated in Recent section',
async () => {
await additionalShareUserDialHomePage.openHomePage();
await additionalShareUserDialHomePage.waitForPageLoaded({
isNewConversationVisible: true,
});
await additionalShareUserSharedFolderPrompts.expandFolder(
folderPrompt.folders.name,
{ isHttpMethodTriggered: true },
);
await additionalShareUserSharedFolderPrompts.openFolderEntityDropdownMenu(
folderPrompt.folders.name,
promptName,
);
await additionalShareUserSharedWithMePromptDropdownMenu.selectMenuOption(
MenuOptions.duplicate,
{ triggeredHttpMethod: 'POST' },
);
await additionalShareUserPromptAssertion.assertEntityState(
{ name: promptName },
'visible',
);
},
);

await dialSharedWithMeTest.step(
'Verify prompts with incremented names are created on duplication',
async () => {
for (let i = 1; i <= 2; i++) {
await additionalShareUserSharedFolderPrompts.openFolderEntityDropdownMenu(
folderPrompt.folders.name,
promptName,
);
await additionalShareUserSharedWithMePromptDropdownMenu.selectMenuOption(
MenuOptions.duplicate,
{ triggeredHttpMethod: 'POST' },
);
await additionalShareUserPromptAssertion.assertEntityState(
{ name: `${promptName} ${i}` },
'visible',
);
}
},
);

await dialSharedWithMeTest.step(
'Select "Move To -> New folder" option in dropdown menu for duplicated prompt and verify prompt is successfully moved',
async () => {
await additionalShareUserPrompts.openEntityDropdownMenu(
`${promptName} 2`,
);
await additionalShareUserPromptDropdownMenu.selectMenuOption(
MenuOptions.moveTo,
);
await additionalShareUserPromptDropdownMenu.selectMenuOption(
MenuOptions.newFolder,
{ triggeredHttpMethod: 'POST' },
);
await additionalShareUserFolderPrompts.expandFolder(
ExpectedConstants.newFolderWithIndexTitle(1),
);
await additionalShareUserPromptBarFolderAssertion.assertFolderEntityState(
{ name: ExpectedConstants.newFolderWithIndexTitle(1) },
{ name: `${promptName} 2` },
'visible',
);
},
);
},
);
Loading

0 comments on commit 07d26fa

Please sign in to comment.