@@ -5,29 +5,91 @@ import path from 'path';
5
5
import TabHeaderView from '../../lib/views/tab-header-view' ;
6
6
7
7
describe ( 'TabHeaderView' , function ( ) {
8
- let wrapper , select ;
9
- const path1 = 'test/path/project1' ;
10
- const path2 = '2nd-test/path/project2' ;
11
- const paths = [ path1 , path2 ] ;
12
-
13
- beforeEach ( function ( ) {
14
- select = sinon . spy ( ) ;
15
- wrapper = shallow ( < TabHeaderView handleProjectSelect = { select } projectPaths = { paths } currentProject = { path2 } /> ) ;
16
- } ) ;
8
+ function build ( options = { } ) {
9
+ const props = {
10
+ currentWorkDir : undefined ,
11
+ onDidChangeWorkDirs : undefined ,
12
+ handleWorkDirSelect : undefined ,
13
+ getCurrentWorkDirs : ( ) => [ ] ,
14
+ ...options ,
15
+ }
16
+ return shallow ( < TabHeaderView { ...props } /> ) ;
17
+ }
18
+
19
+ describe ( 'with a select listener and paths' , function ( ) {
20
+ let wrapper , select ;
21
+ const path1 = path . normalize ( 'test/path/project1' ) ;
22
+ const path2 = path . normalize ( '2nd-test/path/project2' ) ;
23
+ const paths = [ path1 , path2 ] ;
24
+
25
+ beforeEach ( function ( ) {
26
+ select = sinon . spy ( ) ;
27
+ wrapper = build ( { handleWorkDirSelect : select , getCurrentWorkDirs : ( ) => paths , currentWorkDir : path2 } ) ;
28
+ } ) ;
29
+
30
+ it ( 'renders an option for all given working directories' , function ( ) {
31
+ wrapper . find ( 'option' ) . forEach ( function ( node , index ) {
32
+ assert . strictEqual ( node . props ( ) . value , paths [ index ] ) ;
33
+ assert . strictEqual ( node . children ( ) . text ( ) , path . basename ( paths [ index ] ) ) ;
34
+ } ) ;
35
+ } ) ;
17
36
18
- it ( 'renders an option for all given project paths' , function ( ) {
19
- wrapper . find ( 'option' ) . forEach ( function ( node , index ) {
20
- assert . strictEqual ( node . props ( ) . value , paths [ index ] ) ;
21
- assert . strictEqual ( node . children ( ) . text ( ) , path . basename ( paths [ index ] ) ) ;
37
+ it ( 'selects the current working directory\'s path' , function ( ) {
38
+ assert . strictEqual ( wrapper . find ( 'select' ) . props ( ) . value , path2 ) ;
22
39
} ) ;
40
+
41
+ it ( 'calls handleWorkDirSelect on select' , function ( ) {
42
+ wrapper . find ( 'select' ) . simulate ( 'change' , { target : { value : path1 } } ) ;
43
+ assert . isTrue ( select . calledWith ( { target : { value : path1 } } ) ) ;
44
+ } ) ;
45
+
46
+ it ( 'updates paths' , function ( ) {
47
+ const path3 = 'test3/path/project3' ;
48
+ paths . push ( path3 ) ;
49
+ wrapper . instance ( ) . updateWorkDirs ( ) ;
50
+ assert . strictEqual ( wrapper . find ( 'option' ) . length , 3 ) ;
51
+ } )
23
52
} ) ;
24
53
25
- it ( 'selects the current project\'s path' , function ( ) {
26
- assert . strictEqual ( wrapper . find ( 'select' ) . props ( ) . value , path2 ) ;
54
+ describe ( 'with onDidChangeWorkDirs' , function ( ) {
55
+ let wrapper , changeSpy , disposeSpy ;
56
+
57
+ beforeEach ( function ( ) {
58
+ disposeSpy = sinon . spy ( ) ;
59
+ const stub = sinon . stub ( ) . callsFake ( function ( updateWorkDirs ) {
60
+ updateWorkDirs ( ) ;
61
+ return { dispose : disposeSpy } ;
62
+ } ) ;
63
+ changeSpy = sinon . spy ( stub ) ;
64
+ wrapper = build ( { onDidChangeWorkDirs : changeSpy } ) ;
65
+ } ) ;
66
+
67
+ it ( 'calls onDidChangeWorkDirs with updateWorkDirs' , function ( ) {
68
+ assert . isTrue ( changeSpy . calledWith ( wrapper . instance ( ) . updateWorkDirs ) ) ;
69
+ } ) ;
70
+
71
+ it ( 'calls dispose on unmount' , function ( ) {
72
+ wrapper . unmount ( ) ;
73
+ assert . isTrue ( disposeSpy . called ) ;
74
+ } ) ;
75
+
76
+ it ( 'does nothing on unmount without a disposable' , function ( ) {
77
+ wrapper . instance ( ) . disposable = undefined ;
78
+ wrapper . unmount ( ) ;
79
+ assert . isFalse ( disposeSpy . called ) ;
80
+ } ) ;
81
+
27
82
} ) ;
28
83
29
- it ( 'calls handleProjectSelect on select' , function ( ) {
30
- wrapper . find ( 'select' ) . simulate ( 'change' , { target : { value : path1 } } ) ;
31
- assert . isTrue ( select . calledWith ( { target : { value : path1 } } ) ) ;
84
+ describe ( 'with no paths' , function ( ) {
85
+ let wrapper ;
86
+
87
+ beforeEach ( function ( ) {
88
+ wrapper = build ( ) ;
89
+ } ) ;
90
+
91
+ it ( 'renders no options' , function ( ) {
92
+ assert . isTrue ( wrapper . find ( 'select' ) . children ( ) . isEmpty ( ) ) ;
93
+ } ) ;
32
94
} ) ;
33
95
} ) ;
0 commit comments