1
1
import * as React from 'react' ;
2
2
import 'jest' ;
3
3
import { shallow } from 'enzyme' ;
4
- import { CommitBox } from '../../src/components/CommitBox' ;
4
+ import { CommitBox } from '../../src/components/CommitBox' ;
5
+ import { CommandRegistry } from '@lumino/commands' ;
6
+ import { SUBMIT_COMMIT_COMMAND } from '../../src/commandsAndMenu' ;
5
7
6
8
describe ( 'CommitBox' , ( ) => {
9
+
10
+ const defaultCommands = new CommandRegistry ( )
11
+ defaultCommands . addKeyBinding ( {
12
+ keys : [ 'Accel Enter' ] ,
13
+ command : SUBMIT_COMMIT_COMMAND ,
14
+ selector : '.jp-git-CommitBox'
15
+ } )
16
+
7
17
describe ( '#constructor()' , ( ) => {
8
18
it ( 'should return a new instance' , ( ) => {
9
19
const box = new CommitBox ( {
10
20
onCommit : async ( ) => { } ,
11
- hasFiles : false
21
+ hasFiles : false ,
22
+ commands : defaultCommands
12
23
} ) ;
13
24
expect ( box ) . toBeInstanceOf ( CommitBox ) ;
14
25
} ) ;
15
26
16
27
it ( 'should set the default commit message summary to an empty string' , ( ) => {
17
28
const box = new CommitBox ( {
18
29
onCommit : async ( ) => { } ,
19
- hasFiles : false
30
+ hasFiles : false ,
31
+ commands : defaultCommands
20
32
} ) ;
21
33
expect ( box . state . summary ) . toEqual ( '' ) ;
22
34
} ) ;
23
35
24
36
it ( 'should set the default commit message description to an empty string' , ( ) => {
25
37
const box = new CommitBox ( {
26
38
onCommit : async ( ) => { } ,
27
- hasFiles : false
39
+ hasFiles : false ,
40
+ commands : defaultCommands
28
41
} ) ;
29
42
expect ( box . state . description ) . toEqual ( '' ) ;
30
43
} ) ;
@@ -34,17 +47,36 @@ describe('CommitBox', () => {
34
47
it ( 'should display placeholder text for the commit message summary' , ( ) => {
35
48
const props = {
36
49
onCommit : async ( ) => { } ,
37
- hasFiles : false
50
+ hasFiles : false ,
51
+ commands : defaultCommands
52
+ } ;
53
+ const component = shallow ( < CommitBox { ...props } /> ) ;
54
+ const node = component . find ( 'input[type="text"]' ) . first ( ) ;
55
+ expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Summary (Ctrl+Enter to commit)' ) ;
56
+ } ) ;
57
+
58
+ it ( 'should adjust placeholder text for the commit message summary when keybinding changes' , ( ) => {
59
+ const adjustedCommands = new CommandRegistry ( )
60
+ adjustedCommands . addKeyBinding ( {
61
+ keys : [ 'Shift Enter' ] ,
62
+ command : SUBMIT_COMMIT_COMMAND ,
63
+ selector : '.jp-git-CommitBox'
64
+ } )
65
+ const props = {
66
+ onCommit : async ( ) => { } ,
67
+ hasFiles : false ,
68
+ commands : adjustedCommands
38
69
} ;
39
70
const component = shallow ( < CommitBox { ...props } /> ) ;
40
71
const node = component . find ( 'input[type="text"]' ) . first ( ) ;
41
- expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Summary (required )' ) ;
72
+ expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Summary (Shift+Enter to commit )' ) ;
42
73
} ) ;
43
74
44
75
it ( 'should set a `title` attribute on the input element to provide a commit message summary' , ( ) => {
45
76
const props = {
46
77
onCommit : async ( ) => { } ,
47
- hasFiles : false
78
+ hasFiles : false ,
79
+ commands : defaultCommands
48
80
} ;
49
81
const component = shallow ( < CommitBox { ...props } /> ) ;
50
82
const node = component . find ( 'input[type="text"]' ) . first ( ) ;
@@ -54,17 +86,19 @@ describe('CommitBox', () => {
54
86
it ( 'should display placeholder text for the commit message description' , ( ) => {
55
87
const props = {
56
88
onCommit : async ( ) => { } ,
57
- hasFiles : false
89
+ hasFiles : false ,
90
+ commands : defaultCommands
58
91
} ;
59
92
const component = shallow ( < CommitBox { ...props } /> ) ;
60
93
const node = component . find ( 'TextareaAutosize' ) . first ( ) ;
61
- expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Description' ) ;
94
+ expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Description (optional) ' ) ;
62
95
} ) ;
63
96
64
97
it ( 'should set a `title` attribute on the input element to provide a commit message description' , ( ) => {
65
98
const props = {
66
99
onCommit : async ( ) => { } ,
67
- hasFiles : false
100
+ hasFiles : false ,
101
+ commands : defaultCommands
68
102
} ;
69
103
const component = shallow ( < CommitBox { ...props } /> ) ;
70
104
const node = component . find ( 'TextareaAutosize' ) . first ( ) ;
@@ -74,7 +108,8 @@ describe('CommitBox', () => {
74
108
it ( 'should display a button to commit changes' , ( ) => {
75
109
const props = {
76
110
onCommit : async ( ) => { } ,
77
- hasFiles : false
111
+ hasFiles : false ,
112
+ commands : defaultCommands
78
113
} ;
79
114
const component = shallow ( < CommitBox { ...props } /> ) ;
80
115
const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -84,7 +119,8 @@ describe('CommitBox', () => {
84
119
it ( 'should set a `title` attribute on the button to commit changes' , ( ) => {
85
120
const props = {
86
121
onCommit : async ( ) => { } ,
87
- hasFiles : false
122
+ hasFiles : false ,
123
+ commands : defaultCommands
88
124
} ;
89
125
const component = shallow ( < CommitBox { ...props } /> ) ;
90
126
const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -94,7 +130,8 @@ describe('CommitBox', () => {
94
130
it ( 'should apply a class to disable the commit button when no files have changes to commit' , ( ) => {
95
131
const props = {
96
132
onCommit : async ( ) => { } ,
97
- hasFiles : false
133
+ hasFiles : false ,
134
+ commands : defaultCommands
98
135
} ;
99
136
const component = shallow ( < CommitBox { ...props } /> ) ;
100
137
const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -105,7 +142,8 @@ describe('CommitBox', () => {
105
142
it ( 'should apply a class to disable the commit button when files have changes to commit, but the user has not entered a commit message summary' , ( ) => {
106
143
const props = {
107
144
onCommit : async ( ) => { } ,
108
- hasFiles : true
145
+ hasFiles : true ,
146
+ commands : defaultCommands
109
147
} ;
110
148
const component = shallow ( < CommitBox { ...props } /> ) ;
111
149
const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -116,7 +154,8 @@ describe('CommitBox', () => {
116
154
it ( 'should not apply a class to disable the commit button when files have changes to commit and the user has entered a commit message summary' , ( ) => {
117
155
const props = {
118
156
onCommit : async ( ) => { } ,
119
- hasFiles : true
157
+ hasFiles : true ,
158
+ commands : defaultCommands
120
159
} ;
121
160
const component = shallow ( < CommitBox { ...props } /> ) ;
122
161
component . setState ( {
0 commit comments