mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
## Problem Primary colour serves readable text and selected controls, but those uses need different shades. Light mode needs darker text, while dark mode needs a deeper button fill. Fixed brand green on interactive chrome also prevents a custom primary hue from carrying through the interface. Some slider tracks and selected text are hard to read. ## Solution - Keep `--primary` for accessible text and small selected indicators. Use `--primary-solid` for button fills, which need a deeper shade in dark mode. - Add `--primary-bright` for focus rings, selected control chrome, chart accents, and other interactive highlights. It follows `--primary-hue`; `brand-*` stays fixed for Supabase identity. - Make slider troughs clearer and text selection translucent with theme foreground text. - Document the split in the design-system colour guide. | Before | After | | --- | --- | | <img width="980" height="244" alt="Before: light mode primary controls" src="https://github.com/user-attachments/assets/dfae325d-0dfe-4231-8bcd-3f89c4b9d793" /> | <img width="982" height="204" alt="After: light mode primary controls" src="https://github.com/user-attachments/assets/5fdcb531-a6e3-4549-8a13-9d9a5ebe6e20" /> | | <img width="610" height="120" alt="Before: slider track" src="https://github.com/user-attachments/assets/04f768e0-51e8-4d06-9b97-c52f4a34f122" /> | <img width="622" height="126" alt="After: slider track" src="https://github.com/user-attachments/assets/95127f4e-13dc-4f0f-b63c-cf5d70a28b42" /> | | <img width="652" height="512" alt="Before: dark mode controls" src="https://github.com/user-attachments/assets/3f88de66-90cc-40ee-8cf1-b5f4eb87b09a" /> | <img width="658" height="498" alt="After: dark mode controls" src="https://github.com/user-attachments/assets/906bec30-6ca1-4614-9fb3-6cf5e5feec22" /> | ## Review instructions 1. Compare light and dark mode in the [colour usage guide](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#primary-and-brand-colors). Check primary ink, primary-solid, primary-bright, and fixed brand swatches. 2. In Studio, open the ‘new table’ sheet in [Table Editor](https://studio-staging-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/dashboard/project/_/editor). Tab through the new table sheet's fields and toggles. Check the focus rings, selected controls, and the sheet's edges in both themes. You do not need to save a table. 3. Select text in Studio in both themes, including a link or primary-coloured label. The selection and text should remain legible. 4. Check the [Field](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/field) Price Range slider: the unused track should remain visible in both themes. The selected field card border should follow primary-bright. 5. Check the [Button](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/button) and [Radio Group](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/radio-group) previews. In dark mode, `primary` button fill should be deeper than primary [text](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#text); selected radios should remain readable.
334 lines
11 KiB
TypeScript
334 lines
11 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query'
|
|
import { screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { components } from 'api-types'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { HttpResponse } from 'msw'
|
|
import { ReactNode, useRef, type AnchorHTMLAttributes } from 'react'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { ReplicationPipelineLayout } from './ReplicationPipelineLayout'
|
|
import { ReplicationPipelineStatus } from './ReplicationPipelineStatus/ReplicationPipelineStatus'
|
|
import { replicationKeys } from '@/data/replication/keys'
|
|
import {
|
|
PipelineRequestStatusProvider,
|
|
PipelineStatusRequestStatus,
|
|
usePipelineRequestStatus,
|
|
} from '@/state/replication-pipeline-request-status'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
mockAnimationsApi()
|
|
|
|
// The global setup pins useParams to { ref: 'default' }; this layout also needs a pipeline id
|
|
vi.mock('common', async (importOriginal) => ({
|
|
...(await importOriginal<typeof import('common')>()),
|
|
useParams: () => ({ ref: 'default', pipelineId: '42' }),
|
|
}))
|
|
|
|
vi.mock('next/router', () => ({
|
|
useRouter: () => ({ push: vi.fn() }),
|
|
}))
|
|
|
|
vi.mock('next/link', () => ({
|
|
default: ({
|
|
href,
|
|
children,
|
|
...props
|
|
}: AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) => (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}))
|
|
|
|
const renderLayout = (children?: ReactNode) =>
|
|
customRender(
|
|
<PipelineRequestStatusProvider>
|
|
<ReplicationPipelineLayout>{children}</ReplicationPipelineLayout>
|
|
</PipelineRequestStatusProvider>
|
|
)
|
|
|
|
const TableResetFixture = () => {
|
|
const queryClient = useQueryClient()
|
|
const { runWithRequestStatus } = usePipelineRequestStatus()
|
|
const finishReset = useRef<() => void>(() => {})
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
tabIndex={0}
|
|
onClick={() =>
|
|
void runWithRequestStatus(
|
|
42,
|
|
PipelineStatusRequestStatus.StopRequested,
|
|
() =>
|
|
new Promise<void>((resolve) => {
|
|
finishReset.current = resolve
|
|
})
|
|
)
|
|
}
|
|
>
|
|
Begin table reset
|
|
</button>
|
|
<button
|
|
tabIndex={0}
|
|
onClick={async () => {
|
|
finishReset.current()
|
|
await queryClient.invalidateQueries({
|
|
queryKey: replicationKeys.pipelinesStatus('default', 42),
|
|
})
|
|
}}
|
|
>
|
|
Finish table reset
|
|
</button>
|
|
</>
|
|
)
|
|
}
|
|
|
|
type PipelineResponse = components['schemas']['PipelineResponse_Output']
|
|
type PipelineStatusResponse = components['schemas']['PipelineStatusResponse_Output']
|
|
type PipelineReplicationStatusResponse =
|
|
components['schemas']['PipelineReplicationStatusResponse_Output']
|
|
type PipelineVersionResponse = components['schemas']['PipelineVersionResponse_Output']
|
|
type DestinationResponse = components['schemas']['DestinationResponse_Output']
|
|
type DestinationsResponse = components['schemas']['DestinationsResponse_Output']
|
|
type PipelinesResponse = components['schemas']['PipelinesResponse_Output']
|
|
type SourcesResponse = components['schemas']['SourcesResponse_Output']
|
|
|
|
const PIPELINE: PipelineResponse = {
|
|
id: 42,
|
|
config: { publication_name: 'analytics_publication' },
|
|
destination_id: 7,
|
|
destination_name: 'Analytics warehouse',
|
|
replicator_id: 1,
|
|
source_id: 2,
|
|
source_name: 'main-db',
|
|
tenant_id: 'default',
|
|
}
|
|
|
|
const DESTINATION: DestinationResponse = {
|
|
id: 7,
|
|
name: 'Analytics warehouse',
|
|
tenant_id: 'default',
|
|
config: {
|
|
big_query: {
|
|
connection_pool_size: 8,
|
|
dataset_id: 'analytics',
|
|
project_id: 'acme-analytics',
|
|
},
|
|
},
|
|
}
|
|
|
|
const mockPipeline = () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id',
|
|
response: () => HttpResponse.json<PipelineResponse>(PIPELINE),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/destinations/:destination_id',
|
|
response: () => HttpResponse.json<DestinationResponse>(DESTINATION),
|
|
})
|
|
|
|
// The header renders DestinationPanel so Edit destination can open in place
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/destinations',
|
|
response: () => HttpResponse.json<DestinationsResponse>({ destinations: [DESTINATION] }),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines',
|
|
response: () => HttpResponse.json<PipelinesResponse>({ pipelines: [PIPELINE] }),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/sources',
|
|
response: () =>
|
|
HttpResponse.json<SourcesResponse>({
|
|
sources: [
|
|
{
|
|
tenant_id: 'default',
|
|
id: 2,
|
|
name: 'default',
|
|
config: { host: 'db.internal', port: 5432, name: 'main-db', username: 'etl_user' },
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
}
|
|
|
|
const mockStatus = (name: PipelineStatusResponse['status']['name']) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/status',
|
|
response: () =>
|
|
HttpResponse.json<PipelineStatusResponse>({ pipeline_id: 42, status: { name } }),
|
|
})
|
|
|
|
const mockVersion = (hasUpdate: boolean) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/version',
|
|
response: () =>
|
|
HttpResponse.json<PipelineVersionResponse>({
|
|
pipeline_id: 42,
|
|
version: { id: 1, name: 'v0.2.0' },
|
|
...(hasUpdate ? { new_version: { id: 2, name: 'v0.3.0' } } : {}),
|
|
}),
|
|
})
|
|
|
|
const mockReplicationStatus = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/replication-status',
|
|
response: () =>
|
|
HttpResponse.json<PipelineReplicationStatusResponse>({
|
|
pipeline_id: 42,
|
|
table_statuses: [],
|
|
}),
|
|
})
|
|
|
|
describe('ReplicationPipelineLayout', () => {
|
|
beforeEach(() => {
|
|
mockPipeline()
|
|
mockVersion(false)
|
|
})
|
|
|
|
test('renders pipeline identity, chrome actions and the lifecycle action', async () => {
|
|
mockStatus('started')
|
|
|
|
renderLayout(<div>Overview content</div>)
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
|
|
expect(screen.getByRole('link', { name: 'Pipelines' })).toHaveAttribute(
|
|
'href',
|
|
'/project/default/database/pipelines'
|
|
)
|
|
expect(screen.getByRole('link', { name: 'View logs' }).getAttribute('href')).toContain(
|
|
'pipeline_id'
|
|
)
|
|
expect(screen.getByText('Running')).toBeVisible()
|
|
expect(screen.getByText('Primary database')).toBeVisible()
|
|
expect(await screen.findByText('BigQuery')).toBeVisible()
|
|
expect(await screen.findByRole('button', { name: 'Stop' })).toBeVisible()
|
|
expect(screen.getByText('Overview content')).toBeVisible()
|
|
})
|
|
|
|
test('keeps the pipeline identity structure in place while it loads', async () => {
|
|
let resolvePipeline: (pipeline: PipelineResponse) => void = () => {}
|
|
const pipelineResponse = new Promise<PipelineResponse>((resolve) => {
|
|
resolvePipeline = resolve
|
|
})
|
|
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id',
|
|
response: async () => HttpResponse.json<PipelineResponse>(await pipelineResponse),
|
|
})
|
|
mockStatus('started')
|
|
|
|
renderLayout()
|
|
|
|
expect(screen.getByText('Primary database')).toBeVisible()
|
|
expect(screen.getByText('Loading destination')).toBeInTheDocument()
|
|
expect(screen.getAllByText('Loading pipeline')).toHaveLength(2)
|
|
expect(screen.queryByText('Running')).not.toBeInTheDocument()
|
|
|
|
resolvePipeline(PIPELINE)
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
|
|
expect(await screen.findByText('BigQuery')).toBeVisible()
|
|
expect(await screen.findByText('Running')).toBeVisible()
|
|
})
|
|
|
|
test('composes the legacy overview without duplicating the detail header', async () => {
|
|
mockStatus('stopped')
|
|
mockReplicationStatus()
|
|
|
|
renderLayout(<ReplicationPipelineStatus />)
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
|
|
expect(screen.getAllByRole('link', { name: 'View logs' })).toHaveLength(1)
|
|
expect(screen.getAllByRole('button', { name: 'Start' })).toHaveLength(1)
|
|
expect(await screen.findByRole('heading', { name: 'Pipeline stopped' })).toBeVisible()
|
|
})
|
|
|
|
test('explains the state in a tooltip when the dot is hovered', async () => {
|
|
// The dotted underline promises a tooltip; this guards the asChild ref binding that makes it work
|
|
mockStatus('failed')
|
|
renderLayout()
|
|
|
|
await userEvent.hover(await screen.findByText('Failed'))
|
|
|
|
expect(await screen.findByRole('tooltip')).toHaveTextContent(
|
|
'Replication has encountered an error. Check the logs for more information.'
|
|
)
|
|
expect(screen.queryByRole('link', { name: 'logs' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
test('offers the pipeline actions the primary button does not', async () => {
|
|
mockStatus('started')
|
|
renderLayout()
|
|
|
|
await screen.findByRole('heading', { name: 'Analytics warehouse' })
|
|
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
|
|
|
|
// Primary button is Stop while running, so the menu carries Restart instead
|
|
expect(await screen.findByRole('menuitem', { name: 'Restart pipeline' })).toBeVisible()
|
|
expect(screen.queryByRole('menuitem', { name: 'Stop pipeline' })).not.toBeInTheDocument()
|
|
expect(screen.getByRole('menuitem', { name: 'Edit pipeline' })).toBeVisible()
|
|
expect(screen.getByRole('menuitem', { name: 'Delete pipeline' })).toBeVisible()
|
|
})
|
|
|
|
test('blocks pipeline actions while a table reset is running', async () => {
|
|
mockStatus('started')
|
|
mockVersion(true)
|
|
renderLayout(<TableResetFixture />)
|
|
|
|
const lifecycleAction = await screen.findByRole('button', { name: 'Stop' })
|
|
const options = screen.getByRole('button', { name: 'Pipeline options' })
|
|
const update = await screen.findByRole('button', { name: 'Update available' })
|
|
expect(lifecycleAction).toBeEnabled()
|
|
expect(options).toBeEnabled()
|
|
expect(update).toBeEnabled()
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Begin table reset' }))
|
|
expect(lifecycleAction).toBeDisabled()
|
|
expect(options).toBeDisabled()
|
|
expect(update).toBeDisabled()
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Finish table reset' }))
|
|
expect(lifecycleAction).toBeEnabled()
|
|
expect(options).toBeEnabled()
|
|
expect(update).toBeEnabled()
|
|
})
|
|
|
|
test('offers Stop from the menu when the primary button is Restart', async () => {
|
|
mockStatus('failed')
|
|
renderLayout()
|
|
|
|
await screen.findByRole('heading', { name: 'Analytics warehouse' })
|
|
await waitFor(() => expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled())
|
|
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Stop pipeline' })).toBeVisible()
|
|
expect(screen.queryByRole('menuitem', { name: 'Restart pipeline' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
test('keeps an available update visible and opens its modal', async () => {
|
|
mockStatus('started')
|
|
mockVersion(true)
|
|
|
|
renderLayout()
|
|
|
|
const updateButton = await screen.findByRole('button', { name: 'Update available' })
|
|
expect(updateButton).toHaveClass('bg-primary-solid')
|
|
await userEvent.click(updateButton)
|
|
// The trigger button shares this name, so match the dialog's heading specifically
|
|
expect(await screen.findByRole('heading', { name: 'Update available' })).toBeVisible()
|
|
})
|
|
})
|