|
| 1 | +import type { Test } from '@lvce-editor/test-with-playwright' |
| 2 | + |
| 3 | +export const name = 'typescript.quick-fix' |
| 4 | + |
| 5 | +export const test: Test = async ({ Command, Editor, expect, FileSystem, Locator, Main, Settings, Workspace }) => { |
| 6 | + // arrange |
| 7 | + const workspaceUrl = await FileSystem.getTmpDir({ scheme: 'file' }) |
| 8 | + await FileSystem.mkdir(`${workspaceUrl}/src`) |
| 9 | + const uri = `${workspaceUrl}/src/test.ts` |
| 10 | + await FileSystem.writeFile( |
| 11 | + uri, |
| 12 | + `interface DragDataItem { |
| 13 | + data: string |
| 14 | + type: string |
| 15 | +} |
| 16 | +
|
| 17 | +const items: DragDataItem[] = [ |
| 18 | + {}, |
| 19 | +] |
| 20 | +`, |
| 21 | + ) |
| 22 | + await Workspace.setUri(workspaceUrl) |
| 23 | + await Settings.update({ 'editor.diagnostics': true }) |
| 24 | + await Main.openUri(uri) |
| 25 | + await Command.execute('Editor.waitForDiagnostics') |
| 26 | + const expectedDiagnostics = [ |
| 27 | + { |
| 28 | + code: 2739, |
| 29 | + columnIndex: 2, |
| 30 | + endColumnIndex: 4, |
| 31 | + endRowIndex: 6, |
| 32 | + message: "Type '{}' is missing the following properties from type 'DragDataItem': data, type", |
| 33 | + rowIndex: 6, |
| 34 | + source: 'ts', |
| 35 | + type: 'error', |
| 36 | + uri, |
| 37 | + }, |
| 38 | + ] as const |
| 39 | + await expect(Locator('.Diagnostic')).toHaveCount(expectedDiagnostics.length) |
| 40 | + await Editor.shouldHaveDiagnostics(expectedDiagnostics) |
| 41 | + await Editor.setCursor(6, 4) |
| 42 | + |
| 43 | + // act |
| 44 | + await Editor.openSourceActions() |
| 45 | + |
| 46 | + // assert |
| 47 | + const action = Locator('.SourceActionItem', { hasText: 'Add missing properties' }) |
| 48 | + await expect(action).toBeVisible() |
| 49 | + await expect(Locator('.SourceActionItem', { hasText: 'Organize Imports' })).toBeVisible() |
| 50 | + await expect(Locator('.SourceActionItem', { hasText: 'Add All Missing Imports' })).toBeVisible() |
| 51 | + await Command.execute('EditorSourceAction.selectItem', 'Add missing properties') |
| 52 | + |
| 53 | + // assert |
| 54 | + await expect(Locator('.SourceActionItem')).toBeHidden() |
| 55 | + await Editor.shouldHaveText(`interface DragDataItem { |
| 56 | + data: string |
| 57 | + type: string |
| 58 | +} |
| 59 | +
|
| 60 | +const items: DragDataItem[] = [ |
| 61 | + { |
| 62 | +data: "", |
| 63 | +type: "" |
| 64 | +}, |
| 65 | +] |
| 66 | +`) |
| 67 | + await Editor.shouldHaveDiagnostics([]) |
| 68 | +} |
0 commit comments