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
40 changes: 33 additions & 7 deletions frontend/src/app/AppShell.creationNote.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/rea
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { creationNoteStorageKey } from '../hooks/useRememberedVisible'
import { draftFixture, entryFixture, findingFixture } from '../test/fixtures'
import { creationMode } from '../test/creationModes'
import { cleanupControllerTest, getTauriMock, setupControllerTest, useAppController } from './useAppController.testHarness'

const { AppShell } = await import('./AppShell')
Expand Down Expand Up @@ -37,15 +38,16 @@ it('shows the Note read-only beside a new draft in place of the record list, whi
expect(screen.queryByRole('button', { name: 'Hide list' })).not.toBeInTheDocument()
expect(screen.queryByRole('textbox', { name: 'Search Findings' })).not.toBeInTheDocument()
expect(screen.queryByRole('combobox', { name: 'Sort' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Show Note' })).not.toBeInTheDocument()
// One toggle in the draft header, named for what shows, says the panel is open.
expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' })).toHaveAttribute('aria-expanded', 'true')

fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
await waitFor(() => expect(screen.queryByRole('complementary', { name: 'Note' })).not.toBeInTheDocument())
expect(screen.getByRole('complementary', { name: 'Findings records' })).toBeInTheDocument()
expect(screen.getByRole('textbox', { name: 'Search Findings' })).toBeInTheDocument()
})

it('remembers that the Note was closed for the next draft, and brings it back from the draft header', async () => {
it('remembers that the Note was closed for the next draft, and brings it back from the toggle in the draft header', async () => {
render(<Subject />)
await createFinding()
fireEvent.click(within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('button', { name: 'Close Note' }))
Expand All @@ -57,7 +59,9 @@ it('remembers that the Note was closed for the next draft, and brings it back fr
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
await createFinding()
expect(screen.queryByRole('complementary', { name: 'Note' })).not.toBeInTheDocument()
fireEvent.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Show Note' }))
const toggle = within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' })
expect(toggle).toHaveAttribute('aria-expanded', 'false')
fireEvent.click(toggle)
expect(await screen.findByRole('complementary', { name: 'Note' })).toHaveTextContent('Pay with a saved card.')
expect(window.localStorage.getItem(creationNoteStorageKey)).toBe('shown')
})
Expand All @@ -76,19 +80,20 @@ it('says so in the panel when the Session has no Note, and the draft still saves
it('shows a saved test case or Finding beside the draft in place of the Note, chosen per draft', async () => {
render(<Subject />)
await createFinding()
const choice = within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Show beside the draft' })
const choice = within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Showing' })
// The draft's own kind is listed first.
expect(within(choice).getAllByRole('group').map(group => group.getAttribute('label'))).toEqual(['Findings', 'Test cases'])
expect(within(choice).getAllByRole('group').map(group => group.getAttribute('label'))).toEqual(['Findings (1)', 'Test cases (1)'])

fireEvent.change(choice, { target: { value: 'testware:draft-saved' } })
const testCase = await screen.findByRole('complementary', { name: 'Checkout test cases' })
await waitFor(() => expect(testCase).toHaveTextContent('Pay with an expired card.'))
expect(within(testCase).getByRole('textbox', { name: 'Checkout test cases content' })).toHaveAttribute('aria-readonly', 'true')
expect(testCase).not.toHaveTextContent('Pay with a saved card.')

// Closed, the panel is brought back by what it shows.
// The toggle is named for what shows, open or closed.
expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Test case' })).toHaveAttribute('aria-expanded', 'true')
fireEvent.click(within(testCase).getByRole('button', { name: 'Close test case' }))
fireEvent.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Show test case' }))
fireEvent.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Test case' }))
fireEvent.change(within(await screen.findByRole('complementary', { name: 'Checkout test cases' })).getByRole('combobox'), { target: { value: 'finding:finding-saved' } })
await waitFor(() => expect(screen.getByRole('complementary', { name: 'Saved finding' })).toHaveTextContent('Card payment fails at checkout.'))

Expand All @@ -97,3 +102,24 @@ it('shows a saved test case or Finding beside the draft in place of the Note, ch
await createFinding()
expect(await screen.findByRole('complementary', { name: 'Note' })).toHaveTextContent('Pay with a saved card.')
})

it('shows only the Note under Generate, the source it uses, and the chosen record again under Write', async () => {
render(<Subject />)
await createFinding()
fireEvent.change(within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Showing' }), { target: { value: 'testware:draft-saved' } })
await screen.findByRole('complementary', { name: 'Checkout test cases' })

fireEvent.click(await waitFor(() => creationMode('Generate')))
const note = await screen.findByRole('complementary', { name: 'Note' })
expect(within(note).getByRole('heading', { name: 'Note' })).toBeInTheDocument()
expect(within(note).queryByRole('combobox')).not.toBeInTheDocument()
expect(note).toHaveTextContent('Generate uses this Note.')
await waitFor(() => expect(note).toHaveTextContent('Pay with a saved card.'))
expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' })).toHaveAttribute('aria-expanded', 'true')
expect(screen.getByRole('article', { name: 'New finding' })).toHaveTextContent('Generates from: Note (5 words, 0 screenshots)')

fireEvent.click(creationMode('Write'))
const testCase = await screen.findByRole('complementary', { name: 'Checkout test cases' })
expect(within(testCase).getByRole('combobox', { name: 'Showing' })).toHaveValue('testware:draft-saved')
expect(testCase).not.toHaveTextContent('Generate uses this Note.')
})
7 changes: 5 additions & 2 deletions frontend/src/app/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActionButton } from '../components/ActionButton'
import { CreationWorkspace } from '../views/CreationTools'
import { CreationNotePanel } from '../views/CreationNotePanel'
import { referenceLabel, useCreationReference } from './creationReference'
import { creationAiActive, shownCreationMode } from './creationMode'
import { useCreationNoteVisible } from '../hooks/useCreationNoteVisible'
import { useEffect, useRef, useState, type KeyboardEvent } from 'react'
import { catalogSelectorEnabled } from '../settings/catalog'
Expand Down Expand Up @@ -58,8 +59,10 @@ export function AppShell(c: AppController) {
const [reference, setReference] = useCreationReference(shownDraft?.id ?? null)
const referenceRecords = { testware: c.testwareDrafts, finding: c.findings }
const askAiVisible = c.askAi.visible && !shownDraft
// Under Generate the panel shows only the Note, the source Generate uses; the choice of record comes back under Write.
const generatingFromNote = shownDraft ? shownCreationMode(shownDraft, creationAiActive(c)) === 'generate' : false
const composer = c.creationIntent && !creationResultReady ? <CreationWorkspace c={c}
showPanel={noteVisible ? undefined : { label: referenceLabel(reference, referenceRecords), onShow: toggleNote }} /> : null
panel={shownDraft ? { label: generatingFromNote ? 'Note' : referenceLabel(reference, referenceRecords), open: noteVisible, onToggle: toggleNote } : undefined} /> : null

// The panel lists both kinds of saved record, and each kind loads with its own tab, so load the other one here.
const { loadDraftsForSession, loadFindingsForSession } = c
Expand Down Expand Up @@ -286,7 +289,7 @@ export function AppShell(c: AppController) {
/>
) : null}
</div>
{shownDraft && noteVisible ? <CreationNotePanel intent={shownDraft} records={referenceRecords} reference={reference} onReferenceChange={setReference} noteReadOnly={c.noteReadOnly} onReadNote={() => void c.creation.reviewSource()} onClose={toggleNote} /> : null}
{shownDraft && noteVisible ? <CreationNotePanel intent={shownDraft} records={referenceRecords} reference={reference} onReferenceChange={setReference} generating={generatingFromNote} noteReadOnly={c.noteReadOnly} onReadNote={() => void c.creation.reviewSource()} onClose={toggleNote} /> : null}
<AppChat c={c} recordVisible={askAiVisible} modelSelectionControl={modelSelectionControl} onConfigureAi={() => runCommand('ai.configure')} />
</div>
</section>
Expand Down
25 changes: 7 additions & 18 deletions frontend/src/styles/collections.css
Original file line number Diff line number Diff line change
Expand Up @@ -1074,28 +1074,17 @@
overflow-wrap: anywhere;
}

/* Show Note sits right of Copy, level with it, while the Note beside the draft is closed. */
/* The toggle for the panel beside the draft sits right of Copy, level with it. */
.creation-composer > .record-title-row:has(> .creation-note-toggle) { grid-template-columns: minmax(0, 1fr) auto auto; }
.creation-composer > .record-title-row > .creation-note-toggle { grid-column: 3; grid-row: 1; margin-block: calc((23px * 1.2 - var(--control-lg)) / 2); }

/* The panel beside a new draft (CreationNotePanel, a side-panel): the Note or a saved record, read-only, scrolling on its own. */
/* The choice of what shows reads as the panel's heading: quiet until pointed at. The panel's colour behind it, for WebKitGTK. */
.creation-reference-select {
flex: 1;
min-width: 0;
height: var(--control-lg);
margin-left: calc(-1 * var(--space-2));
padding-left: var(--space-2);
color: var(--text-primary);
font-family: var(--font-display);
font-size: var(--font-size-lg);
font-weight: 650;
text-overflow: ellipsis;
background-color: var(--surface-panel);
border: 1px solid transparent;
border-radius: var(--radius-md);
}
.creation-reference-select:hover { border-color: var(--border-default); }
/* Under Write its header is the labelled choice of what shows, a field like any other; Close lines up with the field. */
.side-panel-header:has(> .creation-reference-field) { align-items: end; }
.creation-reference-field { flex: 1; min-width: 0; }
.creation-reference-field select { width: 100%; text-overflow: ellipsis; }
.creation-note-source { margin: 0; color: var(--text-secondary); }
.creation-generate-source { margin: 0; }

.creation-note-body {
display: grid;
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/views/CreationGenerate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function useCreationGenerate(intent: CreationIntent, c: AppController) {
selectionAdvisories: [...execution.advisories.map((warning) => warning.message), ...(customAdvisory ? [customAdvisory] : [])],
}
const authored = creationIsAuthored(intent)
const screenshots = `${setup.noteScreenshotCount} screenshot${setup.noteScreenshotCount === 1 ? '' : 's'}`
const withCriteria = intent.kind === 'testware' && Boolean(sessionCriteria(intent, c))
function confirm() {
if (busy || !ready) return
setConfirming(true)
Expand All @@ -60,6 +62,7 @@ export function useCreationGenerate(intent: CreationIntent, c: AppController) {
}
return {
form: <>
<p className="creation-generate-source">Generates from: <strong>Note</strong> ({setup.noteWordCount} words, {screenshots}){withCriteria ? ' and the acceptance criteria' : ''}</p>
<p className="field-description">The AI result is saved as {intent.kind === 'finding' ? 'a new finding' : 'new test cases'} and opens for you to review.{authored
? ' What you wrote under Write is discarded when that succeeds, and kept if it fails or you cancel.' : ''}</p>
<GenerationSetup {...setup} testwarePreferences={preferences} onTestwarePreferencesChange={setPreferences} modelSelectionControl={<>
Expand Down Expand Up @@ -96,11 +99,16 @@ function creationSourceWarning(intent: CreationIntent, c: AppController): string
if (Object.keys(intent.imageOperations).length) return 'Finish adding images under Write, or continue without the failed ones there, before generating.'
if (c.noteReadOnly) return 'Recover the Session Note before using it as a source.'
if (intent.sourceNoteId && !intent.source) return 'Wait for the Note to show beside the draft before generating.'
const criteria = c.activeSession?.id === intent.sessionId ? c.activeSession.acceptanceCriteria?.trim() : null
const criteria = sessionCriteria(intent, c)
const material = intent.source && (htmlHasContent(intent.source.entry.body) || (intent.kind === 'testware' && Boolean(criteria)))
return material ? null : 'Write a Note first. There is nothing to generate from yet.'
}

/** The draft's Session acceptance criteria, which Generate sends for test cases, when that Session is open. */
function sessionCriteria(intent: CreationIntent, c: AppController): string | null {
return c.activeSession?.id === intent.sessionId ? c.activeSession.acceptanceCriteria?.trim() || null : null
}

function withDraftFormat(preferences: TestwareGenerationPreferences, intent: CreationIntent): TestwareGenerationPreferences {
return intent.format.kind === 'testware' ? { ...preferences, outputFormat: intent.format.outputFormat } : preferences
}
50 changes: 31 additions & 19 deletions frontend/src/views/CreationNotePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { FileText, PanelRightClose, PanelRightOpen } from 'lucide-react'
import { createLucideIcon, FileText, PanelRight, X } from 'lucide-react'
import { ActionButton } from '../components/ActionButton'
import { StatePanel } from '../components/Common'
import { RichTextEditor } from '../editor/RichTextEditor'
Expand All @@ -10,44 +10,56 @@ import type { CreationIntent } from '../app/creationIntent'
import type { CreationKind } from '../tauri'
import { kindLabels, noteReference, referencedRecord, referenceLabel, referenceValue, type CreationReference, type ReferenceRecord, type ReferenceRecords } from '../app/creationReference'

export function ShowNoteButton({ label, onShow }: { label: string; onShow: () => void }) {
const tooltip = `Show ${label}`
return <ActionButton variant="quiet" iconOnly icon={PanelRightOpen} className="creation-note-toggle" aria-label={tooltip}
tooltip={tooltip} tooltipAlign="end" aria-expanded={false} aria-controls={creationNotePanelId} onClick={onShow} />
/** The side-panel icon with its right pane filled: the panel beside the draft is open. */
const PanelRightShown = createLucideIcon('panel-right-shown', [
['rect', { width: '18', height: '18', x: '3', y: '3', rx: '2', key: 'frame' }],
['path', { d: 'M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4z', fill: 'currentColor', key: 'pane' }],
])

/** One toggle in the draft header for the panel beside the draft, named for what the panel shows. Its right pane fills while open. */
export function CreationPanelToggle({ label, open, onToggle }: { label: string; open: boolean; onToggle: () => void }) {
return <ActionButton variant="quiet" icon={open ? PanelRightShown : PanelRight} className="creation-note-toggle" aria-expanded={open}
aria-controls={creationNotePanelId} tooltip={`${open ? 'Hide' : 'Show'} ${label}`} tooltipAlign="end" onClick={onToggle}>{label.charAt(0).toUpperCase() + label.slice(1)}</ActionButton>
}

/**
* Read-only on the right of a new draft: the Session's Note, the source Generate uses, or a saved test case or
* Finding of this Session to write from. Records of the draft's own kind are listed first.
* Read-only on the right of a new draft. Under Write: the Session's Note or a saved test case or Finding of this
* Session to write from, records of the draft's own kind listed first. Under Generate: only the Note, which Generate uses.
*/
export function CreationNotePanel({ intent, records, reference, onReferenceChange, noteReadOnly, onReadNote, onClose }: {
export function CreationNotePanel({ intent, records, reference, onReferenceChange, generating, noteReadOnly, onReadNote, onClose }: {
intent: CreationIntent
records: ReferenceRecords
reference: CreationReference
onReferenceChange: (reference: CreationReference) => void
/** Generate mode: the Note shows, without the choice. The choice comes back under Write. */
generating: boolean
noteReadOnly: boolean
onReadNote: () => void
onClose: () => void
}) {
// A record deleted while it is shown leaves the Note in its place.
const record = referencedRecord(reference, records)
const record = generating ? null : referencedRecord(reference, records)
const shown = record ? reference : noteReference
const label = referenceLabel(shown, records)
const kinds: CreationKind[] = intent.kind === 'finding' ? ['finding', 'testware'] : ['testware', 'finding']
return <aside id={creationNotePanelId} className="side-panel" aria-label={record?.title ?? 'Note'}>
<header className="side-panel-header">
<select className="creation-reference-select" aria-label="Show beside the draft" value={referenceValue(shown)} onChange={event => {
const [kind, id] = event.target.value.split(/:(.*)/s)
onReferenceChange(kind === 'testware' || kind === 'finding' ? { kind, id } : noteReference)
}}>
<option value="note">Note</option>
{kinds.filter(kind => records[kind].length > 0).map(kind => <optgroup key={kind} label={kindLabels[kind].group}>
{records[kind].map(item => <option key={item.id} value={referenceValue({ kind, id: item.id })}>{item.title.trim() || 'Untitled'}</option>)}
</optgroup>)}
</select>
<ActionButton variant="quiet" iconOnly icon={PanelRightClose} aria-label={`Close ${label}`} tooltip={`Close ${label}`} tooltipAlign="end" onClick={onClose} />
{generating ? <h2>Note</h2> : <label className="field creation-reference-field">
<span className="field-label">Showing</span>
<select value={referenceValue(shown)} onChange={event => {
const [kind, id] = event.target.value.split(/:(.*)/s)
onReferenceChange(kind === 'testware' || kind === 'finding' ? { kind, id } : noteReference)
}}>
<option value="note">Note</option>
{kinds.filter(kind => records[kind].length > 0).map(kind => <optgroup key={kind} label={`${kindLabels[kind].group} (${records[kind].length})`}>
{records[kind].map(item => <option key={item.id} value={referenceValue({ kind, id: item.id })}>{item.title.trim() || 'Untitled'}</option>)}
</optgroup>)}
</select>
</label>}
<ActionButton variant="quiet" iconOnly icon={X} aria-label={`Close ${label}`} tooltip={`Close ${label}`} tooltipAlign="end" onClick={onClose} />
</header>
<div className="creation-note-body">
{generating ? <p className="creation-note-source">Generate uses this Note.</p> : null}
{record ? <ReferenceRecordBody record={record} /> : <NoteBody intent={intent} noteReadOnly={noteReadOnly} onReadNote={onReadNote} />}
</div>
</aside>
Expand Down
Loading
Loading