Skip to content

Commit

Permalink
feat(chat): shared with me attachmeents e2e tests (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
nartovm authored Nov 18, 2024
1 parent 5904018 commit 2087055
Show file tree
Hide file tree
Showing 19 changed files with 854 additions and 71 deletions.
45 changes: 34 additions & 11 deletions apps/chat-e2e/src/assertions/downloadAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ import { UploadDownloadData } from '@/src/ui/pages';
import { FileUtil } from '@/src/utils';
import { expect } from '@playwright/test';

enum FileType {
JSON = 'json',
PLAIN = 'plain',
// JPG = 'jpg',
}
type FileReader = (path: string) => string | Buffer | object | undefined;

export class DownloadAssertion {
private static fileReaders: Record<FileType, FileReader> = {
[FileType.JSON]: FileUtil.readJsonFileData,
[FileType.PLAIN]: FileUtil.readPlainFileData,
// [FileType.JPG]: FileUtil.readJpgFileData, //class can be extended to use with different file types
};

public async assertDownloadFileExtension(
downloadedData: UploadDownloadData,
expectedExtension: string,
Expand All @@ -12,17 +25,27 @@ export class DownloadAssertion {
expect(downloadedData.path).toMatch(new RegExp(`${expectedExtension}$`));
}

public async assertFileIsDownloaded(downloadedData: UploadDownloadData) {
public async assertFileIsDownloaded(
downloadedData: UploadDownloadData,
fileType: FileType,
) {
const downloadedFiles = FileUtil.getExportedFiles();
expect
.soft(
downloadedFiles?.find(
(f) =>
f.includes(downloadedData.path) &&
FileUtil.readFileData(downloadedData.path) !== undefined,
),
ExpectedMessages.dataIsExported,
)
.toBeDefined();
const fileExists = downloadedFiles?.some((file) =>
file.includes(downloadedData.path),
);
expect.soft(fileExists, ExpectedMessages.dataIsExported).toBeTruthy();
if (fileExists) {
const fileReader = DownloadAssertion.fileReaders[fileType];
const fileContent = fileReader(downloadedData.path);
expect.soft(fileContent, ExpectedMessages.dataIsExported).toBeDefined();
}
}

public async assertJsonFileIsDownloaded(downloadedData: UploadDownloadData) {
await this.assertFileIsDownloaded(downloadedData, FileType.JSON);
}

public async assertPlainFileIsDownloaded(downloadedData: UploadDownloadData) {
await this.assertFileIsDownloaded(downloadedData, FileType.PLAIN);
}
}
53 changes: 51 additions & 2 deletions apps/chat-e2e/src/assertions/manageAttachmentsAssertion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ElementState, ExpectedMessages, TreeEntity } from '@/src/testData';
import { AttachFilesModal } from '@/src/ui/webElements';
import {
ElementCaretState,
ElementState,
ExpectedMessages,
TreeEntity,
} from '@/src/testData';
import { AttachFilesModal, FileModalSection } from '@/src/ui/webElements';
import { AttachFilesTree } from '@/src/ui/webElements/entityTree';
import { expect } from '@playwright/test';

export class ManageAttachmentsAssertion {
Expand Down Expand Up @@ -36,4 +42,47 @@ export class ManageAttachmentsAssertion {
.soft(arrowIconColor[0], ExpectedMessages.sharedIconColorIsValid)
.toBe(expectedColor);
}

public async assertEntityState(
entity: TreeEntity,
fileModalSection: FileModalSection,
expectedState: ElementState,
) {
let entityTree: AttachFilesTree;
switch (fileModalSection) {
case FileModalSection.AllFiles:
entityTree = this.attachFilesModal.getAllFilesTree();
break;
case FileModalSection.SharedWithMe:
entityTree = this.attachFilesModal.getSharedWithMeTree();
break;
case FileModalSection.Organization:
entityTree = this.attachFilesModal.getOrganizationTree();
break;
}

const entityLocator = entityTree!.getEntityByName(
entity.name,
entity.index,
);
expectedState === 'visible'
? await expect
.soft(entityLocator, ExpectedMessages.entityIsVisible)
.toBeVisible()
: await expect
.soft(entityLocator, ExpectedMessages.entityIsNotVisible)
.toBeHidden();
}

public async assertSectionState(
section: FileModalSection,
state: ElementCaretState,
) {
const sectionElement = this.attachFilesModal.getSectionElement(section);
const isExpanded =
await this.attachFilesModal.isSectionExpanded(sectionElement);
state === 'expanded'
? expect(isExpanded, `Section "${section}" is ${state}`).toBeTruthy()
: expect(isExpanded, `Section "${section}" is ${state}`).toBeFalsy();
}
}
8 changes: 4 additions & 4 deletions apps/chat-e2e/src/core/dialFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const dialTest = test.extend<
selectFolderModal: SelectFolderModal;
selectFolders: Folders;
attachedAllFiles: Folders;
attachedFilesAssertion: ManageAttachmentsAssertion;
manageAttachmentsAssertion: ManageAttachmentsAssertion;
settingsModal: SettingsModal;
publishingRequestModal: PublishingRequestModal;
conversationsToPublish: ConversationsToPublishTree;
Expand Down Expand Up @@ -730,11 +730,11 @@ const dialTest = test.extend<
const conversationAssertion = new ConversationAssertion(conversations);
await use(conversationAssertion);
},
attachedFilesAssertion: async ({ attachFilesModal }, use) => {
const attachedFilesAssertion = new ManageAttachmentsAssertion(
manageAttachmentsAssertion: async ({ attachFilesModal }, use) => {
const manageAttachmentsAssertion = new ManageAttachmentsAssertion(
attachFilesModal,
);
await use(attachedFilesAssertion);
await use(manageAttachmentsAssertion);
},
organizationConversationAssertion: async (
{ organizationConversations },
Expand Down
17 changes: 17 additions & 0 deletions apps/chat-e2e/src/core/dialSharedWithMeFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import config from '@/config/chat.playwright.config';
import {
ChatAssertion,
ConversationAssertion,
DownloadAssertion,
ErrorToastAssertion,
ManageAttachmentsAssertion,
} from '@/src/assertions';
import { ConfirmationDialogAssertion } from '@/src/assertions/confirmationDialogAssertion';
import { EntitySettingAssertion } from '@/src/assertions/entitySettingAssertion';
Expand Down Expand Up @@ -120,9 +122,24 @@ const dialSharedWithMeTest = dialTest.extend<{
additionalShareUserEntitySettingAssertion: EntitySettingAssertion;
additionalShareUserAttachFilesModal: AttachFilesModal;
additionalShareUserErrorToastAssertion: ErrorToastAssertion;
additionalShareUserManageAttachmentsAssertion: ManageAttachmentsAssertion;
additionalShareUserDownloadAssertion: DownloadAssertion;
additionalShareUserChatAssertion: ChatAssertion;
additionalShareUserConversationAssertion: ConversationAssertion;
}>({
// eslint-disable-next-line no-empty-pattern
additionalShareUserDownloadAssertion: async ({}, use) => {
const additionalShareUserDownloadAssertion = new DownloadAssertion();
await use(additionalShareUserDownloadAssertion);
},
additionalShareUserManageAttachmentsAssertion: async (
{ additionalShareUserAttachFilesModal },
use,
) => {
const additionalShareUserManageAttachmentsAssertion =
new ManageAttachmentsAssertion(additionalShareUserAttachFilesModal);
await use(additionalShareUserManageAttachmentsAssertion);
},
additionalShareUserErrorToastAssertion: async (
{ additionalShareUserErrorToast },
use,
Expand Down
2 changes: 1 addition & 1 deletion apps/chat-e2e/src/tests/chatExportImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ dialTest(
'Update id and name of exported conversations and import them again',
async () => {
for (const exportedData of exportedConversations) {
const exportedContent = FileUtil.readFileData(exportedData.path);
const exportedContent = FileUtil.readJsonFileData(exportedData.path);
const conversation = exportedContent.history[0];
conversation.id = GeneratorUtil.randomString(10);
conversation.name = GeneratorUtil.randomString(10);
Expand Down
4 changes: 2 additions & 2 deletions apps/chat-e2e/src/tests/importSpecific.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dialTest(
});

await dialTest.step('Update exported json', async () => {
const exportedData = FileUtil.readFileData(downloadedDataPath);
const exportedData = FileUtil.readJsonFileData(downloadedDataPath);
exportedData.folders.map((f: FolderInterface) => {
f.id = f.id.replace(folderToExport, updatedFolderName);
f.name = f.name.replace(folderToExport, updatedFolderName);
Expand Down Expand Up @@ -190,7 +190,7 @@ dialTest(
});

await dialTest.step('Update exported json', async () => {
const exportedData = FileUtil.readFileData(downloadedDataPath);
const exportedData = FileUtil.readJsonFileData(downloadedDataPath);
exportedData.folders.map((f: FolderInterface) => {
f.id = f.id.replace(promptFolderToExport, updatedPromptFolderName);
f.name = f.name.replace(promptFolderToExport, updatedPromptFolderName);
Expand Down
11 changes: 9 additions & 2 deletions apps/chat-e2e/src/tests/manageAttachment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ dialTest(
await dialTest.step(
'Hover over attached file, open file dropdown menu and select Delete option',
async () => {
await attachFilesModal.openFileDropdownMenu(Attachment.sunImageName);
await attachFilesModal.openFileDropdownMenu(
Attachment.sunImageName,
FileModalSection.AllFiles,
);
await attachFilesModal
.getFileDropdownMenu()
.selectMenuOption(MenuOptions.delete);
Expand Down Expand Up @@ -90,7 +93,10 @@ dialTest(
await dialTest.step(
'Proceed again to "Confirm deleting file" modal, confirm file delete and verify it disappears from files list',
async () => {
await attachFilesModal.openFileDropdownMenu(Attachment.sunImageName);
await attachFilesModal.openFileDropdownMenu(
Attachment.sunImageName,
FileModalSection.AllFiles,
);
await attachFilesModal
.getFileDropdownMenu()
.selectMenuOption(MenuOptions.delete);
Expand Down Expand Up @@ -484,6 +490,7 @@ dialTest(
async () => {
await attachFilesModal.openFileDropdownMenu(
ExpectedConstants.allowedSpecialSymbolsInName(),
FileModalSection.AllFiles,
);
const downloadedData = await dialHomePage.downloadData(() =>
attachFilesModal
Expand Down
2 changes: 1 addition & 1 deletion apps/chat-e2e/src/tests/promptExportImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ dialTest(
'Update id and name of exported prompts and import them again',
async () => {
for (const exportedData of exportedPrompts) {
const exportedContent = FileUtil.readFileData(exportedData.path);
const exportedContent = FileUtil.readJsonFileData(exportedData.path);
const prompt = exportedContent.prompts[0];
prompt.id = GeneratorUtil.randomString(10);
prompt.name = GeneratorUtil.randomString(10);
Expand Down
12 changes: 6 additions & 6 deletions apps/chat-e2e/src/tests/shareConversationWithContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ dialTest(
additionalUserShareApiHelper,
shareApiAssertion,
confirmationDialog,
attachedFilesAssertion,
manageAttachmentsAssertion,
setTestIds,
}) => {
setTestIds('EPMRTC-3518', 'EPMRTC-3102');
Expand Down Expand Up @@ -563,11 +563,11 @@ dialTest(
.getBottomDropdownMenu()
.selectMenuOption(MenuOptions.attachments);

await attachedFilesAssertion.assertSharedFileArrowIconState(
await manageAttachmentsAssertion.assertSharedFileArrowIconState(
{ name: Attachment.sunImageName },
'visible',
);
await attachedFilesAssertion.assertEntityArrowIconColor(
await manageAttachmentsAssertion.assertEntityArrowIconColor(
{ name: Attachment.sunImageName },
Colors.controlsBackgroundAccent,
);
Expand All @@ -579,11 +579,11 @@ dialTest(
}
await attachFilesModal.closeButton.hoverOver();

await attachedFilesAssertion.assertSharedFileArrowIconState(
await manageAttachmentsAssertion.assertSharedFileArrowIconState(
{ name: Attachment.cloudImageName },
'visible',
);
await attachedFilesAssertion.assertEntityArrowIconColor(
await manageAttachmentsAssertion.assertEntityArrowIconColor(
{ name: Attachment.cloudImageName },
Colors.controlsBackgroundAccent,
);
Expand All @@ -601,7 +601,7 @@ dialTest(
.getFileDropdownMenu()
.selectMenuOption(MenuOptions.unshare);
await confirmationDialog.confirm({ triggeredHttpMethod: 'POST' });
await attachedFilesAssertion.assertSharedFileArrowIconState(
await manageAttachmentsAssertion.assertSharedFileArrowIconState(
{ name: Attachment.cloudImageName },
'hidden',
);
Expand Down
Loading

0 comments on commit 2087055

Please sign in to comment.