|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import { anything, instance, mock, verify, when } from 'ts-mockito'; |
| 7 | +import { Uri } from 'vscode'; |
| 8 | +import { ApplicationShell } from '../../../client/common/application/applicationShell'; |
| 9 | +import { CommandManager } from '../../../client/common/application/commandManager'; |
| 10 | +import { IApplicationShell, ICommandManager } from '../../../client/common/application/types'; |
| 11 | +import { FileSystem } from '../../../client/common/platform/fileSystem'; |
| 12 | +import { PlatformService } from '../../../client/common/platform/platformService'; |
| 13 | +import { IFileSystem } from '../../../client/common/platform/types'; |
| 14 | +import { ServiceContainer } from '../../../client/ioc/container'; |
| 15 | +import { IServiceContainer } from '../../../client/ioc/types'; |
| 16 | +import { CommandSource } from '../../../client/testing/common/constants'; |
| 17 | +import { TestCollectionStorageService } from '../../../client/testing/common/services/storageService'; |
| 18 | +import { ITestCollectionStorageService, TestFunction, Tests } from '../../../client/testing/common/types'; |
| 19 | +import { TestDisplay } from '../../../client/testing/display/picker'; |
| 20 | +import { createEmptyResults } from '../results'; |
| 21 | + |
| 22 | +// tslint:disable:no-any |
| 23 | + |
| 24 | +// tslint:disable-next-line: max-func-body-length |
| 25 | +suite('Testing - TestDisplay', () => { |
| 26 | + const wkspace = Uri.file(__dirname); |
| 27 | + let mockedCommandManager: ICommandManager; |
| 28 | + let mockedServiceContainer: IServiceContainer; |
| 29 | + let mockedTestCollectionStorage: ITestCollectionStorageService; |
| 30 | + let mockedAppShell: IApplicationShell; |
| 31 | + let testDisplay: TestDisplay; |
| 32 | + |
| 33 | + function fullPathInTests(collectedTests: Tests, fullpath?: string): Tests { |
| 34 | + collectedTests.testFiles = [{ |
| 35 | + fullPath: fullpath ? fullpath : 'path/to/testfile', |
| 36 | + ...anything() |
| 37 | + }]; |
| 38 | + return collectedTests; |
| 39 | + } |
| 40 | + |
| 41 | + setup(() => { |
| 42 | + mockedCommandManager = mock(CommandManager); |
| 43 | + mockedServiceContainer = mock(ServiceContainer); |
| 44 | + mockedTestCollectionStorage = mock(TestCollectionStorageService); |
| 45 | + mockedAppShell = mock(ApplicationShell); |
| 46 | + when(mockedServiceContainer.get<ITestCollectionStorageService>(ITestCollectionStorageService)) |
| 47 | + .thenReturn(instance(mockedTestCollectionStorage)); |
| 48 | + when(mockedServiceContainer.get<IApplicationShell>(IApplicationShell)) |
| 49 | + .thenReturn(instance(mockedAppShell)); |
| 50 | + |
| 51 | + testDisplay = new TestDisplay(instance(mockedServiceContainer), instance(mockedCommandManager)); |
| 52 | + }); |
| 53 | + |
| 54 | + suite('displayFunctionTestPickerUI', () => { |
| 55 | + const paths: { [key: string]: any } = { |
| 56 | + match: { |
| 57 | + fullPath: '/path/to/testfile', |
| 58 | + fileName: '/path/to/testfile' |
| 59 | + }, |
| 60 | + mismatch: { |
| 61 | + fullPath: '/path/to/testfile', |
| 62 | + fileName: '/testfile/to/path' |
| 63 | + } |
| 64 | + }; |
| 65 | + let tests: Tests; |
| 66 | + |
| 67 | + function codeLensTestFunctions(testfunctions?: TestFunction[]): TestFunction[] { |
| 68 | + if (!testfunctions) { |
| 69 | + return [{ ...anything() }]; |
| 70 | + } |
| 71 | + const functions: TestFunction[] = []; |
| 72 | + testfunctions.forEach(fn => functions.push(fn)); |
| 73 | + return functions; |
| 74 | + } |
| 75 | + |
| 76 | + setup(() => { |
| 77 | + tests = createEmptyResults(); |
| 78 | + when(mockedServiceContainer.get<IFileSystem>(IFileSystem)).thenReturn(new FileSystem(new PlatformService())); |
| 79 | + when(mockedTestCollectionStorage.getTests(wkspace)).thenReturn(tests); |
| 80 | + when(mockedAppShell.showQuickPick(anything(), anything())).thenResolve(); |
| 81 | + }); |
| 82 | + |
| 83 | + test(`Test that a dropdown picker for parametrized tests is shown if compared paths are equal (OS independent) (#8627)`, () => { |
| 84 | + const { fullPath, fileName } = paths.match; |
| 85 | + fullPathInTests(tests, fullPath); |
| 86 | + |
| 87 | + testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions()); |
| 88 | + |
| 89 | + verify(mockedAppShell.showQuickPick(anything(), anything())).once(); |
| 90 | + }); |
| 91 | + |
| 92 | + test(`Test that a dropdown picker for parametrized tests is NOT shown if compared paths are NOT equal (OS independent) (#8627)`, () => { |
| 93 | + const { fullPath, fileName } = paths.mismatch; |
| 94 | + fullPathInTests(tests, fullPath); |
| 95 | + |
| 96 | + testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions()); |
| 97 | + |
| 98 | + verify(mockedAppShell.showQuickPick(anything(), anything())).never(); |
| 99 | + }); |
| 100 | + |
| 101 | + test(`Test that clicking a codelens on parametrized tests opens a dropdown picker on windows (#8627)`, function () { |
| 102 | + if (process.platform !== 'win32') { |
| 103 | + // tslint:disable-next-line: no-invalid-this |
| 104 | + this.skip(); |
| 105 | + } |
| 106 | + // The error described in #8627 originated from the problem that the casing of the drive letter was different |
| 107 | + // in a test items fullPath property to the one of a file that contained the clicked parametrized test. |
| 108 | + const fileName = 'c:\\path\\to\\testfile'; |
| 109 | + fullPathInTests(tests, 'C:\\path\\to\\testfile'); |
| 110 | + |
| 111 | + testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions()); |
| 112 | + |
| 113 | + verify(mockedAppShell.showQuickPick(anything(), anything())).once(); |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments