p = 'src/components/MarkdownToolbar.test.jsx'
s = open(p).read()
s = s.replace('''  it('turns the selected words into a tip, waiting where the tip goes', async () => {
    render(<Harness initial="A child has stridor at rest." />)
    select(12, 19)
    await userEvent.click(screen.getByRole('button', { name: 'Turn the selected words into a tip' }))
    expect(box()).toHaveValue('A child has {{stridor|}} at rest.')
    // The caret sits after the bar, so the next thing typed is the tip itself.
    await waitFor(() => expect(box().selectionStart).toBe('A child has {{stridor|'.length))
  })

  it('with nothing selected, offers a placeholder to type over', async () => {
    render(<Harness initial="" />)
    select(0, 0)
    await userEvent.click(screen.getByRole('button', { name: 'Turn the selected words into a tip' }))
    expect(box()).toHaveValue('{{phrase|the teaching point}}')
    // "phrase" is selected, so the first keystroke replaces it.
    await waitFor(() => {
      expect(box().selectionStart).toBe(2)
      expect(box().selectionEnd).toBe(8)
    })
  })''',
'''  const pickTip = async (name) => {
    await userEvent.click(screen.getByRole('button', { name: 'Add a tip' }))
    await userEvent.click(screen.getByRole('menuitem', { name }))
  }

  it('turns the selected words into a tip, waiting where the tip goes', async () => {
    render(<Harness initial="A child has stridor at rest." />)
    select(12, 19)
    await pickTip('ⓘ Definition')
    expect(box()).toHaveValue('A child has {{stridor|}} at rest.')
    // The caret sits after the bar, so the next thing typed is the tip itself.
    await waitFor(() => expect(box().selectionStart).toBe('A child has {{stridor|'.length))
  })

  it('with nothing selected, offers a placeholder to type over', async () => {
    render(<Harness initial="" />)
    select(0, 0)
    await pickTip('ⓘ Definition')
    expect(box()).toHaveValue('{{phrase|the teaching point}}')
    // "phrase" is selected, so the first keystroke replaces it.
    await waitFor(() => {
      expect(box().selectionStart).toBe(2)
      expect(box().selectionEnd).toBe(8)
    })
  })

  it('a kind other than a definition is written as the third field', async () => {
    render(<Harness initial="Stridor at rest is never normal." />)
    select(0, 7)
    await pickTip('! Catches people out')
    expect(box()).toHaveValue('{{Stridor||caution}} at rest is never normal.')
  })

  it('an end-of-sentence tip has no phrase at all', async () => {
    // The chip form: an aside that is not about any one word in the sentence.
    render(<Harness initial="The child recovered." />)
    select(20, 20)
    await pickTip('◦ At the end of a sentence')
    expect(box()).toHaveValue('The child recovered.{{|the teaching point|fact}}')
    // The placeholder is selected, so the first keystroke replaces it.
    await waitFor(() => {
      expect(box().selectionStart).toBe(23)
      expect(box().selectionEnd).toBe(23 + 'the teaching point'.length)
    })
  })''')
open(p, 'w').write(s)

p2 = 'src/pages/QuestionEditPage.test.jsx'
t = open(p2).read()
t = t.replace('''  await userEvent.click(bar.getByRole('button', { name: 'Turn the selected words into a tip' }))''',
'''  await userEvent.click(bar.getByRole('button', { name: 'Add a tip' }))
  await userEvent.click(bar.getByRole('menuitem', { name: 'ⓘ Definition' }))''')
open(p2, 'w').write(t)
print('written')
