Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const ManageWorkspace = () => {
{ id: 'remove', label: 'Remove', onClick: () => handleCloseClick(workspace) }
]}
>
<button className="more-actions-btn">
<button data-testid="more-actions-btn" className="more-actions-btn">
<IconDots size={14} strokeWidth={1.5} />
</button>
</MenuDropdown>
Expand Down
102 changes: 68 additions & 34 deletions tests/workspace/manage-workspace/manage-workspace.spec.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests are passing when run in parallel with multiple workers. But when run using single worker (npm run test:e2e tests/workspace/manage-workspace/manage-workspace.spec.ts -- --workers=1) it fails due to stale state from the previous test case is not cleaned up.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import path from 'path';
import fs from 'fs';
import { test, expect, closeElectronApp } from '../../../playwright';

const initUserDataPath = path.join(__dirname, '../create-workspace/init-user-data');
import { test, expect } from '../../../playwright';
import { createWorkspace } from '../../utils/page/actions';

function findCreatedWorkspaceDirs(location: string): string[] {
return fs.readdirSync(location).filter((e) => {
Expand All @@ -16,53 +15,88 @@
}

test.describe('Manage Workspace', () => {
test('should open terminal from the workspace actions menu', async ({ launchElectronApp, createTmpDir }) => {
test.beforeEach(async ({ page, createTmpDir }) => {
const wsLocation = await createTmpDir('ws-location-terminal');
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const app = await launchElectronApp({ initUserDataPath, templateVars: { wsLocation } });
const page = await app.firstWindow();

try {
await page.locator('[data-app-state="loaded"]').waitFor({ timeout: 30000 });

await test.step('Create a workspace', async () => {
await page.locator('.workspace-name-container').click();
await page.locator('.dropdown-item').filter({ hasText: 'Create workspace' }).click();
const renameInput = page.locator('.workspace-name-input');
await expect(renameInput).toBeVisible({ timeout: 5000 });
await renameInput.fill('Terminal Workspace');
await renameInput.press('Enter');
await expect(page.getByText('Workspace created!')).toBeVisible({ timeout: 10000 });
});
await test.step('Create a workspace', async () => {
await createWorkspace(page, 'Custom Workspace');
});

const wsDirs = findCreatedWorkspaceDirs(wsLocation);
expect(wsDirs).toHaveLength(1);

await test.step('Open Manage Workspaces', async () => {
await page.locator('.workspace-name-container').click();
await page.locator('.dropdown-item').filter({ hasText: 'Manage workspaces' }).click();
await expect(page.getByText('Manage Workspace')).toBeVisible({ timeout: 5000 });
});
await test.step('Open Manage Workspaces', async () => {
await page.locator('.workspace-name-container').click();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use data-testid

await page.locator('.dropdown-item').filter({ hasText: 'Manage workspaces' }).click();
await expect(page.getByText('Manage Workspace', { exact: true })).toBeVisible();
});
});

test.describe('Manage Workspace Actions - Open in Terminal', () => {
test('should open terminal from the workspace actions menu', async ({ page }) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity tag is not added here. Do we not need it?

await test.step('Verify default workspace has no actions menu', async () => {
const defaultWorkspaceItem = page.locator('.workspace-item').filter({ hasText: 'My Workspace' });
await expect(defaultWorkspaceItem.locator('.more-actions-btn')).toHaveCount(0);
});

await test.step('Open terminal from workspace actions', async () => {
const workspaceItem = page.locator('.workspace-item').filter({ hasText: 'Terminal Workspace' });
await expect(workspaceItem).toBeVisible({ timeout: 5000 });
const workspaceItem = page.locator('.workspace-item').filter({ hasText: 'Custom Workspace' });
await expect(workspaceItem).toBeVisible();
await workspaceItem.locator('.more-actions-btn').click();
await page.locator('.dropdown-item').filter({ hasText: 'Open in Terminal' }).click();
});

await test.step('Verify terminal session opens at the workspace folder', async () => {
const terminalSession = page.getByTestId('session-list-0');
await expect(terminalSession).toBeVisible({ timeout: 5000 });
await expect(terminalSession).toContainText(wsDirs[0]);
await expect(terminalSession).toBeVisible();
await expect(terminalSession).toContainText('Custom Workspace');
});
});
});

test.describe('Manage Workspace Actions - Rename Workspace', () => {
test('Click on the 3 dots icon on the workspace you want to rename.', async ({ page }) => {
const workspaceItem = page.locator('.workspace-item').filter({
has: page.locator('.workspace-name', { hasText: 'Custom Workspace' })
});

await workspaceItem.locator('.more-actions-btn').click();

Check failure on line 60 in tests/workspace/manage-workspace/manage-workspace.spec.ts

View workflow job for this annotation

GitHub Actions / Detect Flaky Tests

[default] › tests/workspace/manage-workspace/manage-workspace.spec.ts:55:9 › Manage Workspace › Manage Workspace Actions - Rename Workspace › Click on the 3 dots icon on the workspace you want to rename.

5) [default] › tests/workspace/manage-workspace/manage-workspace.spec.ts:55:9 › Manage Workspace › Manage Workspace Actions - Rename Workspace › Click on the 3 dots icon on the workspace you want to rename. Error: locator.click: Error: strict mode violation: locator('.workspace-item').filter({ has: locator('.workspace-name').filter({ hasText: 'Custom Workspace' }) }).locator('.more-actions-btn') resolved to 2 elements: 1) <button aria-expanded="false" class="more-actions-btn" data-testid="menu-dropdown">…</button> aka locator('div').filter({ hasText: /^Custom Workspace\/home\/runner\/bruno\/Custom WorkspaceOpenReveal in File Manager$/ }).getByTestId('menu-dropdown') 2) <button aria-expanded="false" class="more-actions-btn" data-testid="menu-dropdown">…</button> aka getByTestId('menu-dropdown').nth(2) Call log: - waiting for locator('.workspace-item').filter({ has: locator('.workspace-name').filter({ hasText: 'Custom Workspace' }) }).locator('.more-actions-btn') 58 | }); 59 | > 60 | await workspaceItem.locator('.more-actions-btn').click(); | ^ 61 | await page.locator('.dropdown-item').filter({ hasText: 'Rename' }).click(); 62 | await expect(page.locator('.bruno-modal-card')).toBeVisible(); 63 | at /home/runner/work/bruno/bruno/tests/workspace/manage-workspace/manage-workspace.spec.ts:60:56

Check failure on line 60 in tests/workspace/manage-workspace/manage-workspace.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (macOS)

[default] › tests/workspace/manage-workspace/manage-workspace.spec.ts:55:9 › Manage Workspace › Manage Workspace Actions - Rename Workspace › Click on the 3 dots icon on the workspace you want to rename.

7) [default] › tests/workspace/manage-workspace/manage-workspace.spec.ts:55:9 › Manage Workspace › Manage Workspace Actions - Rename Workspace › Click on the 3 dots icon on the workspace you want to rename. Error: locator.click: Error: strict mode violation: locator('.workspace-item').filter({ has: locator('.workspace-name').filter({ hasText: 'Custom Workspace' }) }).locator('.more-actions-btn') resolved to 2 elements: 1) <button aria-expanded="false" class="more-actions-btn" data-testid="menu-dropdown">…</button> aka getByTestId('menu-dropdown').first() 2) <button aria-expanded="false" class="more-actions-btn" data-testid="menu-dropdown">…</button> aka getByTestId('menu-dropdown').nth(1) Call log: - waiting for locator('.workspace-item').filter({ has: locator('.workspace-name').filter({ hasText: 'Custom Workspace' }) }).locator('.more-actions-btn') 58 | }); 59 | > 60 | await workspaceItem.locator('.more-actions-btn').click(); | ^ 61 | await page.locator('.dropdown-item').filter({ hasText: 'Rename' }).click(); 62 | await expect(page.locator('.bruno-modal-card')).toBeVisible(); 63 | at /Users/admin/actions-runner/_work/bruno/bruno/tests/workspace/manage-workspace/manage-workspace.spec.ts:60:56
await page.locator('.dropdown-item').filter({ hasText: 'Rename' }).click();
await expect(page.locator('.bruno-modal-card')).toBeVisible();

await test.step('Enter a new name for the workspace in the editing field.', async () => {
const workspaceNameInput = page.locator('#workspace-name');
await expect(workspaceNameInput).toBeVisible();
await workspaceNameInput.fill('New Workspace Name');
await page.getByTestId('modal-submit-btn').filter({ hasText: 'Rename' }).click();
});

await test.step('Verify the workspace name is updated in the workspace list.', async () => {
const workspaceItem = page.getByTestId('workspace-name');
await expect(workspaceItem).toHaveText('New Workspace Name');
const manageWorkspaceItem = page.locator('.workspace-item').filter({
has: page.locator('.workspace-name', { hasText: 'New Workspace Name' })
});
await expect(manageWorkspaceItem).toBeVisible();
});
});
});

test.describe('Manage Workspace Actions - Remove Workspace', () => {
test('Should be able to remove a Workspace from manage workspace section', async ({ page }) => {
const workspaceItem = page.locator('.workspace-item').filter({
has: page.locator('.workspace-name', { hasText: 'Custom Workspace' })
});

await test.step('Open Manage Workspaces', async () => {
await workspaceItem.locator('.more-actions-btn').click();
await expect(page.getByTestId('menu-dropdown-dropdown')).toBeVisible();
await page.getByTestId('menu-dropdown-remove').click();
await expect(page.locator('.bruno-modal-card')).toBeVisible();
await expect(page.locator('.bruno-modal-content span').first()).toHaveText('Custom Workspace');
});

await test.step('Click on the Remove button in the modal.', async () => {
await page.getByTestId('modal-submit-btn').click();
await expect(page.locator('.workspace-item').filter({ hasText: 'Custom Workspace' })).not.toBeVisible({ timeout: 10000 });
});
} finally {
await closeElectronApp(app);
}
});
});
});
Loading