Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 77 additions & 18 deletions apps/website/e2e/workshop-workspace-switch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Page } from '@playwright/test'
import { expect } from '@playwright/test'

import type {
Expand Down Expand Up @@ -31,10 +32,7 @@ const WORKSPACES: ListWorkspacesResponse = {

const TEAM = WORKSPACES.workspaces[1]

test('switching workspace during a run asks before it throws the run away', async ({
page,
modelsAccount
}) => {
async function mockWorkspaces(page: Page) {
await page.route('**/api/workspaces', (route) =>
route.fulfill({
status: 200,
Expand Down Expand Up @@ -63,46 +61,107 @@ test('switching workspace during a run asks before it throws the run away', asyn
} satisfies ExchangeTokenResponse)
})
})
// The run never answers, so it is still going when the workspace changes.
await page.route('**/v2/models/**', () => {})
}

async function signIn(
page: Page,
account: { email: string; password: string }
) {
await page.goto('/login/')
await page.getByRole('button', { name: 'Use email instead' }).click()
await page.getByLabel('Email').fill(modelsAccount.email)
await page
.getByLabel('Password', { exact: true })
.fill(modelsAccount.password)
await page.getByLabel('Email').fill(account.email)
await page.getByLabel('Password', { exact: true }).fill(account.password)
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
await expect(page).toHaveURL('/')
}

async function startRun(page: Page) {
await page.goto(MODEL_PATH)
await page.getByTestId('field-prompt').fill('A teapot')
await page.getByTestId('run-button').click()
const output = page.getByTestId('playground-output')
await expect(output).toHaveAttribute('data-state', 'running')
return output
}

const account = page
function accountMenu(page: Page) {
const trigger = page
.getByTestId('desktop-nav-cta')
.getByTestId('header-account')
const otherWorkspace = async () => {
await account.click()
await page.getByTestId('account-workspace').click()
await page.getByTestId('account-workspace-ws-team').click()
return {
open: () => trigger.click(),
pickTeam: async () => {
await trigger.click()
await page.getByTestId('account-workspace').click()
await page.getByTestId(`account-workspace-${TEAM.id}`).click()
}
}
}

test('switching workspace during a run asks before it throws the run away', async ({
page,
modelsAccount
}) => {
await mockWorkspaces(page)
// The run never answers, so it is still going when the workspace changes.
await page.route('**/v2/models/**', () => {})

await otherWorkspace()
await signIn(page, modelsAccount)
const output = await startRun(page)
const menu = accountMenu(page)

await menu.pickTeam()
const dialog = page.getByTestId('run-leave-dialog')
await expect(dialog).toBeVisible()

await page.getByTestId('run-leave-stay').click()
await expect(dialog).toBeHidden()
await expect(output).toHaveAttribute('data-state', 'running')

await otherWorkspace()
await menu.pickTeam()
await page.getByTestId('run-leave-confirm').click()
await expect(output).toHaveAttribute('data-state', 'cancelled')

await account.click()
await menu.open()
await expect(page.getByTestId('account-workspace-current')).toContainText(
TEAM.name
)
})

test('a run that ends under the question answers it', async ({
page,
modelsAccount
}) => {
await mockWorkspaces(page)
// The run is held until the dialog is up, then it ends on its own.
let land = () => {}
const held = new Promise<void>((resolve) => {
land = resolve
})
await page.route('**/v2/models/**', async (route) => {
await held
await route.fulfill({
status: 503,
headers: { 'X-Comfy-Error-Type': 'provider_error' },
contentType: 'application/json',
body: JSON.stringify({ detail: 'Temporary provider error' })
})
})

await signIn(page, modelsAccount)
const output = await startRun(page)
const menu = accountMenu(page)

await menu.pickTeam()
const dialog = page.getByTestId('run-leave-dialog')
await expect(dialog).toBeVisible()

land()

await expect(output).toHaveAttribute('data-state', 'failed')
await expect(dialog).toBeHidden()

await menu.open()
await expect(page.getByTestId('account-workspace-current')).toContainText(
TEAM.name
)
Expand Down
42 changes: 42 additions & 0 deletions apps/website/e2e/workshop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,48 @@ test.describe('Model playground', () => {
.poll(() => list.evaluate((el) => el.scrollWidth > el.clientWidth))
.toBe(true)
})

// 320px is the narrowest phone the site supports, and it is where a fixed
// card width ran the next sample off the screen: a strip that scrolls with
// nothing showing past its edge reads as a single card.
test('the next sample shows past the edge at 320px @mobile', async ({
page
}) => {
const width = 320
await page.setViewportSize({ width, height: 720 })
await page.goto('/models/krea--krea-2-medium-turbo--generate-images/')
const cards = page.getByTestId('example-card')
await expect(cards).toHaveCount(3)

await expect
.poll(async () => {
const box = await cards.nth(1).boundingBox()
if (!box) return false
// Far enough in to be seen, and still running off the edge: a card
// that fitted whole would say the strip ends there.
return box.x < width - 24 && box.x + box.width > width
})
.toBe(true)
})

test('a lone sample takes the phone row @mobile', async ({ page }) => {
await page.goto('/models/bfl--flux-2-pro--generate-images/')
const cards = page.getByTestId('example-card')
await expect(cards).toHaveCount(1)

// The strip runs edge to edge behind a gutter of 24px on each side.
const list = page.getByTestId('examples-tab').locator('ul')
await expect
.poll(async () => {
const [listBox, cardBox] = await Promise.all([
list.boundingBox(),
cards.first().boundingBox()
])
if (!listBox || !cardBox) return false
return Math.abs(cardBox.width - (listBox.width - 48)) < 2
})
.toBe(true)
})
})

test.describe('Filter sheet @mobile', () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ const { copy, copied } = useClipboard({ copiedDuring: 2000 })
"
@click="void copy(value)"
>
<component
:is="copied ? Check : Copy"
:class="cn('size-5', iconClass)"
data-testid="copy-text-icon"
/>
<component :is="copied ? Check : Copy" :class="cn('size-5', iconClass)" />
<span v-if="copied" class="text-sm whitespace-nowrap">
{{ copiedLabel }}
</span>
Expand Down
25 changes: 0 additions & 25 deletions apps/website/src/components/workshop/ExamplesTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,3 @@ it('keeps the audio transport separate from the preset action', async () => {
await user.click(preset)
expect(emitted().open).toEqual([[example]])
})

// happy-dom lays nothing out, so the width can only be read off the class here.
// That it comes out to a judgeable size on a real phone is the @mobile spec in
// e2e/workshop.spec.ts; this pins which of the two widths each case picks.
it.for([
[1, 'w-full'],
[3, 'w-72']
] as const)('gives %i sample(s) the %s phone width', ([count, width]) => {
render(ExamplesTab, {
props: {
examples: Array.from({ length: count }, (_, index) => ({
id: `sample-${index}`,
title: `Sample ${index}`,
specs: [],
values: {},
outputUrl: `https://assets.example/sample-${index}.png`,
mediaKind: 'image' as const
}))
}
})

const items = screen.getAllByTestId('example-item')
expect(items).toHaveLength(count)
expect(items.every((item) => item.className.includes(width))).toBe(true)
})
7 changes: 5 additions & 2 deletions apps/website/src/components/workshop/ExamplesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ const samplesOnly = computed(
)
// A sample exists to be judged, and on a phone it was 144px wide: an 81px
// preview of a generated image decides nothing. A lone sample takes the row,
// and several leave the next one peeking so the strip still reads as one.
const phoneWidth = computed(() => (examples.length === 1 ? 'w-full' : 'w-72'))
// and several take four fifths of it, so the next one peeks in at every width
// the phone layout covers, up to the 18rem past which a card gains nothing.
const phoneWidth = computed(() =>
examples.length === 1 ? 'w-full' : 'w-4/5 max-sm:max-w-72'
)
const desktopGridColumns = computed(() =>
examples.length === 3
? 'sm:grid-cols-[repeat(auto-fit,minmax(14rem,1fr))]'
Expand Down
117 changes: 117 additions & 0 deletions apps/website/src/components/workshop/HeaderAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,123 @@ describe('HeaderAccount workspace switcher', () => {
)
})

it('carries the switch through when the run ends under the dialog', async () => {
signIn()
const cancel = vi.fn()
reportWorkshopRun(cancel)
onTestFinished(() => reportWorkshopRun(undefined))
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValue(
new Response(JSON.stringify(listing), { status: 200 })
)
)
const user = userEvent.setup()
render(HeaderAccount)

await openSwitcher(user)
await user.click(await screen.findByTestId('account-workspace-team-1'))
expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy()

reportWorkshopRun(undefined)

await waitFor(() =>
expect(h.remint).toHaveBeenCalledWith(undefined, {
workspaceId: 'team-1',
preserveCredentialOnTransientFailure: true
})
)
expect(cancel).not.toHaveBeenCalled()
await waitFor(() =>
expect(screen.queryByTestId('run-leave-dialog')).toBeNull()
)
})

it('drops a pending switch when the authenticated session changes', async () => {
signIn()
const cancel = vi.fn()
reportWorkshopRun(cancel)
onTestFinished(() => reportWorkshopRun(undefined))
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValue(
new Response(JSON.stringify(listing), { status: 200 })
)
)
const user = userEvent.setup()
render(HeaderAccount)

await openSwitcher(user)
await user.click(await screen.findByTestId('account-workspace-team-1'))
expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy()

const replacement = {
token: 'other-jwt',
uid: 'user-2',
workspace: { id: 'other', name: 'Other', type: 'personal' as const },
role: 'owner'
}
h.user!.value = {
uid: 'user-2',
email: 'other@b.co',
displayName: 'Other'
}
h.session!.value = replacement
reportWorkshopRun(undefined)

await waitFor(() =>
expect(screen.queryByTestId('run-leave-dialog')).toBeNull()
)
expect(h.remint).not.toHaveBeenCalled()
expect(cancel).not.toHaveBeenCalled()
expect(h.session!.value).toEqual(replacement)
})

// The other arm of the same scope check: the reader stays signed in, and only
// the workspace moves under the dialog. ModelDetail watches uid and workspace
// separately, and this is the arm where a stale answer would overwrite the
// newer workspace rather than reach for another account's.
it('drops a pending switch when only the workspace changes', async () => {
signIn()
const cancel = vi.fn()
reportWorkshopRun(cancel)
onTestFinished(() => reportWorkshopRun(undefined))
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValue(
new Response(JSON.stringify(listing), { status: 200 })
)
)
const user = userEvent.setup()
render(HeaderAccount)

await openSwitcher(user)
await user.click(await screen.findByTestId('account-workspace-team-1'))
expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy()

const moved = {
token: 'jwt',
uid: 'user-1',
workspace: { id: 'team-2', name: 'Other team', type: 'team' as const },
role: 'owner'
}
h.session!.value = moved
reportWorkshopRun(undefined)

await waitFor(() =>
expect(screen.queryByTestId('run-leave-dialog')).toBeNull()
)
expect(h.remint).not.toHaveBeenCalled()
expect(cancel).not.toHaveBeenCalled()
expect(h.session!.value).toEqual(moved)
})

it('switches by reminting for the picked workspace', async () => {
signIn()
vi.stubGlobal(
Expand Down
Loading
Loading