|
| 1 | +import { expect } from '@playwright/test' |
| 2 | + |
| 3 | +import { |
| 4 | + PERSONAL_WORKSPACE_NAME, |
| 5 | + TEAM_WORKSPACE_NAME |
| 6 | +} from '@e2e/fixtures/data/workspaceSwitcher' |
| 7 | +import { workspaceSwitcherTest as test } from '@e2e/fixtures/workspaceSwitcherFixture' |
| 8 | + |
| 9 | +test.describe('Local workspace switcher', { tag: '@auth' }, () => { |
| 10 | + test.describe.configure({ timeout: 60_000 }) |
| 11 | + |
| 12 | + test('switches the active workspace without reloading or losing the workflow', async ({ |
| 13 | + comfyPage |
| 14 | + }) => { |
| 15 | + const page = comfyPage.page |
| 16 | + const localOrigin = new URL(page.url()).origin |
| 17 | + const billingRequestUrls: string[] = [] |
| 18 | + const localBillingRequestUrls: string[] = [] |
| 19 | + const billingAuthorizationHeaders: string[] = [] |
| 20 | + let tokenRequestBody: unknown |
| 21 | + |
| 22 | + page.on('request', (request) => { |
| 23 | + if (!request.url().includes('/api/billing/')) return |
| 24 | + billingRequestUrls.push(request.url()) |
| 25 | + billingAuthorizationHeaders.push(request.headers().authorization ?? '') |
| 26 | + if (new URL(request.url()).origin === localOrigin) { |
| 27 | + localBillingRequestUrls.push(request.url()) |
| 28 | + } |
| 29 | + }) |
| 30 | + page.on('request', (request) => { |
| 31 | + if ( |
| 32 | + request.method() === 'POST' && |
| 33 | + request.url().endsWith('/api/auth/token') |
| 34 | + ) { |
| 35 | + tokenRequestBody = request.postDataJSON() |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Top') |
| 40 | + await comfyPage.settings.setSetting( |
| 41 | + 'Comfy.Workflow.WorkflowTabsPosition', |
| 42 | + 'Topbar' |
| 43 | + ) |
| 44 | + const workflowName = `local-workspace-${Date.now().toString(36)}` |
| 45 | + await comfyPage.menu.topbar.saveWorkflow(workflowName) |
| 46 | + await page.evaluate(() => { |
| 47 | + document.body.dataset.workspaceSwitchDocument = 'original' |
| 48 | + }) |
| 49 | + |
| 50 | + await page.getByRole('button', { name: 'Current user' }).click() |
| 51 | + await expect(page.getByTestId('workspace-switcher-trigger')).toContainText( |
| 52 | + PERSONAL_WORKSPACE_NAME |
| 53 | + ) |
| 54 | + await page.getByTestId('workspace-switcher-trigger').click() |
| 55 | + |
| 56 | + const panel = page.getByTestId('workspace-switcher-panel') |
| 57 | + await expect(panel.getByText(PERSONAL_WORKSPACE_NAME)).toBeVisible() |
| 58 | + await expect(panel.getByText(TEAM_WORKSPACE_NAME)).toBeVisible() |
| 59 | + await expect(panel.getByText('Owner')).toHaveCount(2) |
| 60 | + await expect(panel.getByText('Member')).toHaveCount(1) |
| 61 | + const scopeCaption = panel.getByText( |
| 62 | + 'Workspaces only affect which credits you use.' |
| 63 | + ) |
| 64 | + await expect(scopeCaption).toBeVisible() |
| 65 | + await scopeCaption.locator('..').locator('.pi-info-circle').hover() |
| 66 | + await expect(page.getByRole('tooltip')).toHaveText( |
| 67 | + 'Runs that use partner nodes spend credits from this workspace. Unlike on Cloud, every workspace saves to your usual output folder.' |
| 68 | + ) |
| 69 | + |
| 70 | + await panel.getByText(TEAM_WORKSPACE_NAME, { exact: true }).click() |
| 71 | + |
| 72 | + await expect(page.getByTestId('workspace-switcher-trigger')).toContainText( |
| 73 | + TEAM_WORKSPACE_NAME |
| 74 | + ) |
| 75 | + await expect.poll(() => billingRequestUrls.length).toBeGreaterThan(0) |
| 76 | + expect(tokenRequestBody).toEqual({ workspace_id: 'ws-team' }) |
| 77 | + expect(billingRequestUrls).toEqual( |
| 78 | + expect.arrayContaining([ |
| 79 | + expect.stringMatching( |
| 80 | + /^https:\/\/testcloud\.comfy\.org\/api\/billing\// |
| 81 | + ) |
| 82 | + ]) |
| 83 | + ) |
| 84 | + expect(localBillingRequestUrls).toEqual([]) |
| 85 | + await expect |
| 86 | + .poll(() => billingAuthorizationHeaders) |
| 87 | + .toContain('Bearer mock-workspace-token-ws-team') |
| 88 | + await expect |
| 89 | + .poll(() => comfyPage.menu.topbar.getTabNames()) |
| 90 | + .toContain(workflowName) |
| 91 | + expect( |
| 92 | + await page.evaluate(() => document.body.dataset.workspaceSwitchDocument) |
| 93 | + ).toBe('original') |
| 94 | + }) |
| 95 | +}) |
0 commit comments