Skip to content

Commit ccf7ecc

Browse files
committed
test(mothership): exercise the copy action in the organization chat key regression
1 parent 6d6829d commit ccf7ecc

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/special-tags

‎apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/special-tags.test.tsx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ describe('CredentialDisplay link tag', () => {
385385
act(() => root.unmount())
386386
})
387387

388-
it('reveals a created key in organization chat after the live fill and after persistence', () => {
388+
it('reveals a created key in organization chat after the live fill and after persistence', async () => {
389389
mockParams.mockReturnValue({ organizationId: 'org' } as never)
390390
const tag = (item: Record<string, string>) => `<credential>${JSON.stringify(item)}</credential>`
391391
const tagData = (content: string) =>
@@ -406,16 +406,24 @@ describe('CredentialDisplay link tag', () => {
406406
cache
407407
).content
408408

409+
const writeText = vi.fn(async () => undefined)
410+
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } })
411+
const copyButton = (container: HTMLElement) =>
412+
Array.from(container.querySelectorAll('button')).find(
413+
(button) => button.textContent === 'Copy to clipboard'
414+
)
415+
409416
const liveView = renderCredentialLink(tagData(live))
410-
expect(liveView.container.textContent).not.toContain('explicit workspace target')
411-
expect(liveView.container.textContent).toContain('sk-sim-live')
417+
await act(async () => copyButton(liveView.container)?.click())
418+
expect(writeText).toHaveBeenCalledWith('sk-sim-live')
412419
act(() => liveView.root.unmount())
413420

414421
const persisted = redactSensitiveContent(
415422
tag({ type: 'sim_key', workspaceId: 'ws-1', value: 'sk-sim-live' })
416423
)
417424
const persistedView = renderCredentialLink(tagData(persisted))
418-
expect(persistedView.container.textContent).not.toContain('explicit workspace target')
425+
expect(persistedView.container.querySelector('code')).not.toBeNull()
426+
expect(copyButton(persistedView.container)).toBeUndefined()
419427
expect(persistedView.container.textContent).not.toContain('sk-sim-live')
420428
act(() => persistedView.root.unmount())
421429
})

0 commit comments

Comments
 (0)