Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/MarkdownSourceComparison.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ const SourceRow = defineComponent({
return h('div', {
class: ['text-source-comparison__line', operation && `text-source-comparison__line--${operation}`],
hidden: rowProps.layoutMode === 'single' && rowProps.activeSide !== side,
'aria-label': operation && t('text', operation === 'removed' ? 'Removed line {line}' : 'Added line {line}', { line: value!.number }),
'aria-label': operation && (operation === 'removed'
? t('text', 'Removed line {line}', { line: value!.number })
: t('text', 'Added line {line}', { line: value!.number })),
'data-source-operation': operation,
}, value
? [
Expand Down
38 changes: 38 additions & 0 deletions src/tests/comparison/MarkdownSourceComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,44 @@ describe('Markdown source component', () => {
}
})

it('labels changed lines with their own source numbers and leaves context unlabelled', async () => {
const contextLines = Array.from({ length: 10 }, (_value, index) => `context ${index}`).join('\n')
const wrapper = mount(MarkdownSourceComparison, {
props: {
beforeContent: `${contextLines}\nold\nlast\n`,
afterContent: `inserted\n${contextLines}\nnew\nlast\n`,
layoutMode: 'paired',
},
})
await vi.waitFor(() => expect(wrapper.find('[data-source-hunk]').exists()).toBe(true))

expect(wrapper.find('[data-source-operation="removed"]').attributes('aria-label')).toBe('Removed line 11')
expect(wrapper.findAll('[data-source-operation="added"]').map((line) => line.attributes('aria-label')))
.toEqual(['Added line 1', 'Added line 12'])
const context = wrapper.findAll('.text-source-comparison__line').filter((line) => line.find('code').exists() && line.find('code').text() === 'last')
expect(context).toHaveLength(2)
for (const line of context) {
expect(line.attributes()).not.toHaveProperty('aria-label')
}
wrapper.unmount()
})

it.each([
['addition', '', 'added\n', 'Added line 1', 0],
['deletion', 'removed\n', '', 'Removed line 1', 1],
] as const)('renders a pure %s without labelling or dereferencing its missing side', async (_name, beforeContent, afterContent, label, missingSide) => {
const wrapper = mount(MarkdownSourceComparison, {
props: { beforeContent, afterContent, layoutMode: 'paired' },
})
await vi.waitFor(() => expect(wrapper.find('[data-source-hunk]').exists()).toBe(true))

expect(wrapper.find('[data-source-operation]').attributes('aria-label')).toBe(label)
const missing = wrapper.findAll('.text-source-comparison__line')[missingSide]!
expect(missing.text()).toBe('')
expect(missing.attributes()).not.toHaveProperty('aria-label')
wrapper.unmount()
})

it('omits per-line badges when paired line endings match', async () => {
const wrapper = mount(MarkdownSourceComparison, {
props: {
Expand Down
Loading