3
3
4
4
'use strict' ;
5
5
6
- import { expect } from 'chai' ;
6
+ import { assert , expect } from 'chai' ;
7
7
import * as TypeMoq from 'typemoq' ;
8
- import { CancellationToken , CodeActionContext , CodeActionKind , Range , TextDocument } from 'vscode' ;
8
+ import { CancellationToken , CodeActionContext , CodeActionKind , Range , TextDocument , Uri } from 'vscode' ;
9
9
import { PythonCodeActionProvider } from '../../../client/providers/codeActionProvider/pythonCodeActionProvider' ;
10
10
11
11
suite ( 'Python CodeAction Provider' , ( ) => {
@@ -24,21 +24,36 @@ suite('Python CodeAction Provider', () => {
24
24
} ) ;
25
25
26
26
test ( 'Ensure it always returns a source.organizeImports CodeAction' , async ( ) => {
27
+ document . setup ( ( d ) => d . uri ) . returns ( ( ) => Uri . file ( 'hello.ipynb' ) ) ;
27
28
const codeActions = await codeActionsProvider . provideCodeActions (
28
29
document . object ,
29
30
range . object ,
30
31
context . object ,
31
32
token . object
32
33
) ;
33
34
34
- if ( ! codeActions ) {
35
- throw Error ( `codeActionsProvider.provideCodeActions did not return an array (it returned ${ codeActions } )` ) ;
36
- }
35
+ assert . isArray ( codeActions , 'codeActionsProvider.provideCodeActions did not return an array' ) ;
37
36
38
- const organizeImportsCodeAction = codeActions . filter (
37
+ const organizeImportsCodeAction = ( codeActions || [ ] ) . filter (
39
38
( codeAction ) => codeAction . kind === CodeActionKind . SourceOrganizeImports
40
39
) ;
41
40
expect ( organizeImportsCodeAction ) . to . have . length ( 1 ) ;
42
41
expect ( organizeImportsCodeAction [ 0 ] . kind ) . to . eq ( CodeActionKind . SourceOrganizeImports ) ;
43
42
} ) ;
43
+ test ( 'Ensure it does not returns a source.organizeImports CodeAction for Notebook Cells' , async ( ) => {
44
+ document . setup ( ( d ) => d . uri ) . returns ( ( ) => Uri . file ( 'hello.ipynb' ) . with ( { scheme : 'vscode-notebook-cell' } ) ) ;
45
+ const codeActions = await codeActionsProvider . provideCodeActions (
46
+ document . object ,
47
+ range . object ,
48
+ context . object ,
49
+ token . object
50
+ ) ;
51
+
52
+ assert . isArray ( codeActions , 'codeActionsProvider.provideCodeActions did not return an array' ) ;
53
+
54
+ const organizeImportsCodeAction = ( codeActions || [ ] ) . filter (
55
+ ( codeAction ) => codeAction . kind === CodeActionKind . SourceOrganizeImports
56
+ ) ;
57
+ expect ( organizeImportsCodeAction ) . to . have . length ( 0 ) ;
58
+ } ) ;
44
59
} ) ;
0 commit comments