|
1 | 1 | import { afterEach, describe, expect, it } from 'vitest'; |
2 | 2 | import type { CustomError, CustomWarning, StateRefinementError } from '../../../types/diagnostics'; |
3 | 3 | import { renderLocation } from '../sections'; |
4 | | -import { renderDiagnosticsView } from './diagnostics'; |
| 4 | +import { formatDiagnosticForClipboard, renderDiagnosticsView } from './diagnostics'; |
5 | 5 |
|
6 | 6 | const currentFile = 'file:///workspace/Current.java'; |
7 | 7 | const otherFile = 'file:///workspace/Other.java'; |
@@ -90,17 +90,21 @@ describe('diagnostics view', () => { |
90 | 90 | it('shows every declaration of a refinement with their notes under them', () => { |
91 | 91 | const declaredAt = (lineStart: number) => |
92 | 92 | ({ file: '/workspace/DoorRefinements.java', lineStart, colStart: 29, lineEnd: lineStart, colEnd: 58 }); |
93 | | - document.body.innerHTML = renderLocation({ |
| 93 | + const stateError = { |
94 | 94 | ...error(), type: 'state-refinement-error', declarationPosition: declaredAt(12), |
95 | 95 | declarationPositions: [declaredAt(12), declaredAt(13)], |
96 | 96 | declarationNotes: ['where closed(this) means doorState(this) == closed', 'where ajar(this) means doorState(this) == ajar'], |
97 | | - } as unknown as StateRefinementError); |
| 97 | + } as unknown as StateRefinementError; |
| 98 | + document.body.innerHTML = renderLocation(stateError); |
98 | 99 |
|
99 | 100 | expect(Array.from(document.querySelectorAll('pre > *')).map(element => element.textContent)).toEqual([ |
100 | 101 | 'DoorRefinements.java:13', 'DoorRefinements.java:14', |
101 | 102 | 'where closed(this) means doorState(this) == closed', 'where ajar(this) means doorState(this) == ajar', |
102 | 103 | ]); |
103 | 104 | expect(document.querySelector('pre > :last-child')?.className).toBe('location-note'); |
| 105 | + // the copied error keeps the notes but not the raw positions |
| 106 | + expect(formatDiagnosticForClipboard(stateError)).toContain('Declaration Notes: where closed(this) means'); |
| 107 | + expect(formatDiagnosticForClipboard(stateError)).not.toContain('Declaration Positions'); |
104 | 108 | }); |
105 | 109 |
|
106 | 110 | it.each([false, true])('keeps warnings in the passed state (showAll=%s)', showAll => { |
|
0 commit comments