|
18 | 18 |
|
19 | 19 | describe('annotate', () => { |
20 | 20 | test('renders annotations', async () => { |
21 | | - // We don't normally use snapshots, |
22 | | - // but in this case its a short and concise example |
23 | | - // that won't change regularly. |
24 | | - // If it fails, study the output and make sure it's correct. |
25 | | - // If it is indeed correct, run `vitest --updateSnapshot` to update it. |
26 | | - expect(await renderContent(example)).toMatchSnapshot() |
| 21 | + const res = await renderContent(example) |
| 22 | + const $ = cheerio.load(res) |
| 23 | + |
| 24 | + // Check that the annotation structure is rendered correctly |
| 25 | + const annotation = $('.annotate') |
| 26 | + expect(annotation.length).toBe(1) |
| 27 | + expect(annotation.hasClass('beside')).toBe(true) |
| 28 | + |
| 29 | + // Check annotation header exists |
| 30 | + const header = $('.annotate-header') |
| 31 | + expect(header.length).toBe(1) |
| 32 | + |
| 33 | + // Check both beside and inline modes are rendered |
| 34 | + const beside = $('.annotate-beside') |
| 35 | + const inline = $('.annotate-inline') |
| 36 | + expect(beside.length).toBe(1) |
| 37 | + expect(inline.length).toBe(1) |
| 38 | + |
| 39 | + // Check that we have the correct number of annotation rows |
| 40 | + const rows = $('.annotate-row') |
| 41 | + expect(rows.length).toBe(2) |
| 42 | + |
| 43 | + // Check that each row has both code and note sections |
| 44 | + rows.each((i, row) => { |
| 45 | + const $row = $(row) |
| 46 | + expect($row.find('.annotate-code').length).toBe(1) |
| 47 | + expect($row.find('.annotate-note').length).toBe(1) |
| 48 | + }) |
| 49 | + |
| 50 | + // Check specific content of the annotations |
| 51 | + const notes = $('.annotate-note p') |
| 52 | + const noteTexts = notes.map((i, el) => $(el).text()).get() |
| 53 | + expect(noteTexts).toEqual([ |
| 54 | + 'The name of the workflow as it will appear in the "Actions" tab of the GitHub repository.', |
| 55 | + 'Add the pull_request event, so that the workflow runs automatically\nevery time a pull request is created.', |
| 56 | + ]) |
| 57 | + |
| 58 | + // Check code content |
| 59 | + const codes = $('.annotate-code pre') |
| 60 | + const codeTexts = codes.map((i, el) => $(el).text()).get() |
| 61 | + expect(codeTexts).toEqual([ |
| 62 | + 'name: Post welcome comment', |
| 63 | + 'on:\n pull_request:\n types: [opened]', |
| 64 | + ]) |
27 | 65 | }) |
28 | 66 |
|
29 | 67 | test('renders bash with hash bang annotations', async () => { |
|
63 | 101 |
|
64 | 102 | \`\`\` |
65 | 103 | `.trim() |
| 104 | + |
66 | 105 | const res = await renderContent(example) |
67 | 106 | const $ = cheerio.load(res) |
68 | 107 |
|
|
79 | 118 | "on:\n push:\n branches: ['release']", |
80 | 119 | ]) |
81 | 120 | }) |
| 121 | + |
| 122 | + test('supports AUTOTITLE links in annotations', async () => { |
| 123 | + const example = ` |
| 124 | +\`\`\`yaml annotate copy |
| 125 | +# For more information about workflow syntax, see [AUTOTITLE](/get-started/start-your-journey/hello-world). |
| 126 | +name: Test workflow |
| 127 | +
|
| 128 | +# This uses the checkout action. See [AUTOTITLE](/get-started/foo) for details. |
| 129 | +on: [push] |
| 130 | +\`\`\` |
| 131 | +` |
| 132 | + |
| 133 | + // Create a mock context with pages for AUTOTITLE resolution |
| 134 | + const mockPages = { |
| 135 | + '/get-started/start-your-journey/hello-world': { |
| 136 | + href: '/get-started/start-your-journey/hello-world', |
| 137 | + rawTitle: 'Hello World', |
| 138 | + }, |
| 139 | + '/get-started/foo': { |
| 140 | + href: '/get-started/foo', |
| 141 | + rawTitle: 'Fooing Around', |
| 142 | + }, |
| 143 | + } |
| 144 | + |
| 145 | + const mockContext = { |
| 146 | + currentLanguage: 'en', |
| 147 | + currentVersion: 'free-pro-team@latest', |
| 148 | + pages: mockPages, |
| 149 | + redirects: {}, |
| 150 | + } |
| 151 | + |
| 152 | + const res = await renderContent(example, mockContext) |
| 153 | + const $ = cheerio.load(res) |
| 154 | + |
| 155 | + const rows = $('.annotate-row') |
| 156 | + const notes = $('.annotate-note', rows) |
| 157 | + |
| 158 | + // Check that AUTOTITLE links were resolved to actual titles |
| 159 | + const firstNote = notes.eq(0).html() |
| 160 | + const secondNote = notes.eq(1).html() |
| 161 | + |
| 162 | + expect(firstNote).toContain('Hello World') |
| 163 | + expect(firstNote).not.toContain('[AUTOTITLE]') |
| 164 | + expect(secondNote).toContain('Fooing Around') |
| 165 | + expect(secondNote).not.toContain('[AUTOTITLE]') |
| 166 | + }) |
82 | 167 | }) |
0 commit comments