Skip to content

Commit

Permalink
[MS] Added workspace history tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Oct 25, 2024
1 parent a999559 commit 48ea031
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
64 changes: 64 additions & 0 deletions client/tests/pw/e2e/workspace_history.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

import { Page } from '@playwright/test';
import { expect } from '@tests/pw/helpers/assertions';
import { msTest } from '@tests/pw/helpers/fixtures';
import { answerQuestion } from '@tests/pw/helpers/utils';

async function isInGridMode(page: Page): Promise<boolean> {
return (await page.locator('#workspaces-ms-action-bar').locator('#grid-view').getAttribute('disabled')) !== null;
}

async function toggleViewMode(page: Page): Promise<void> {
if (await isInGridMode(page)) {
await page.locator('#workspaces-ms-action-bar').locator('#list-view').click();
} else {
await page.locator('#workspaces-ms-action-bar').locator('#grid-view').click();
}
}

for (const mode of ['grid', 'list']) {
msTest(`Open workspace history in ${mode} mode`, async ({ connected }) => {
if (mode === 'list') {
await toggleViewMode(connected);
await expect(connected.locator('.workspace-list-item')).toHaveCount(3);
await connected.locator('.workspace-list-item').nth(1).locator('.workspace-options').click();
} else {
await expect(connected.locator('.workspaces-grid-item')).toHaveCount(3);
await connected.locator('.workspaces-grid-item').nth(1).locator('.card-option').click();
}
const contextMenu = connected.locator('.workspace-context-menu');
await contextMenu.locator('.menu-list').locator('ion-item-group').nth(1).locator('ion-item').nth(3).click();
await expect(connected).toBeWorkspaceHistoryPage();
});
}

msTest('Test workspace history page', async ({ connected }) => {
await connected.locator('.workspaces-grid-item').nth(1).locator('.card-option').click();
const contextMenu = connected.locator('.workspace-context-menu');
await contextMenu.locator('.menu-list').locator('ion-item-group').nth(1).locator('ion-item').nth(3).click();
await expect(connected.locator('.topbar-left').locator('.topbar-left__title')).toHaveText('History');
const container = connected.locator('.history-container');
await expect(container.locator('.head-content__title')).toHaveText('Workspace: Trademeet');
const header = container.locator('.folder-container-header');
const breadcrumbs = header.locator('ion-breadcrumb');
await expect(breadcrumbs).toHaveCount(1);
await expect(breadcrumbs).toHaveText(['Trademeet']);
const restoreButton = header.locator('.folder-container-header__actions').locator('ion-button');
await expect(restoreButton).toHaveText('Restore');
await expect(restoreButton).toBeTrulyDisabled();
const folderList = container.locator('.folder-list-main');
await expect(folderList.locator('.file-list-item')).toHaveCount(4);
await folderList.locator('.file-list-item').nth(0).dblclick();
await expect(breadcrumbs).toHaveText([' Trademeet /', /^ Dir_.+$/]);

await folderList.locator('.file-list-item').nth(2).locator('ion-checkbox').click();
await expect(restoreButton).toBeTrulyEnabled();
await restoreButton.click();
await answerQuestion(connected, true, {
expectedTitleText: 'Restore files',
expectedQuestionText: 'This will restore one file or folder. It will overwrite your current files if present. Are you sure?',
expectedPositiveText: 'Restore',
expectedNegativeText: 'Cancel',
});
});
17 changes: 16 additions & 1 deletion client/tests/pw/helpers/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,22 @@ export const expect = baseExpect.extend({
await expect(page).toHaveURL(/\/\d+\/myProfile\??.*$/);
} catch (error: any) {
return {
message: () => `Page is not users page (url is '${error.matcherResult.actual}')`,
message: () => `Page is not profile page (url is '${error.matcherResult.actual}')`,
pass: false,
};
}
return {
message: () => '',
pass: true,
};
},

async toBeWorkspaceHistoryPage(page: Page): Promise<AssertReturnType> {
try {
await expect(page).toHaveURL(/\/\d+\/history\??.*$/);
} catch (error: any) {
return {
message: () => `Page is not workspace history page (url is '${error.matcherResult.actual}')`,
pass: false,
};
}
Expand Down

0 comments on commit 48ea031

Please sign in to comment.