11import * as React from 'react' ;
22import 'jest' ;
33import { 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' ;
57
68describe ( '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+
717 describe ( '#constructor()' , ( ) => {
818 it ( 'should return a new instance' , ( ) => {
919 const box = new CommitBox ( {
1020 onCommit : async ( ) => { } ,
11- hasFiles : false
21+ hasFiles : false ,
22+ commands : defaultCommands
1223 } ) ;
1324 expect ( box ) . toBeInstanceOf ( CommitBox ) ;
1425 } ) ;
1526
1627 it ( 'should set the default commit message summary to an empty string' , ( ) => {
1728 const box = new CommitBox ( {
1829 onCommit : async ( ) => { } ,
19- hasFiles : false
30+ hasFiles : false ,
31+ commands : defaultCommands
2032 } ) ;
2133 expect ( box . state . summary ) . toEqual ( '' ) ;
2234 } ) ;
2335
2436 it ( 'should set the default commit message description to an empty string' , ( ) => {
2537 const box = new CommitBox ( {
2638 onCommit : async ( ) => { } ,
27- hasFiles : false
39+ hasFiles : false ,
40+ commands : defaultCommands
2841 } ) ;
2942 expect ( box . state . description ) . toEqual ( '' ) ;
3043 } ) ;
@@ -34,17 +47,36 @@ describe('CommitBox', () => {
3447 it ( 'should display placeholder text for the commit message summary' , ( ) => {
3548 const props = {
3649 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
3869 } ;
3970 const component = shallow ( < CommitBox { ...props } /> ) ;
4071 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 )' ) ;
4273 } ) ;
4374
4475 it ( 'should set a `title` attribute on the input element to provide a commit message summary' , ( ) => {
4576 const props = {
4677 onCommit : async ( ) => { } ,
47- hasFiles : false
78+ hasFiles : false ,
79+ commands : defaultCommands
4880 } ;
4981 const component = shallow ( < CommitBox { ...props } /> ) ;
5082 const node = component . find ( 'input[type="text"]' ) . first ( ) ;
@@ -54,17 +86,19 @@ describe('CommitBox', () => {
5486 it ( 'should display placeholder text for the commit message description' , ( ) => {
5587 const props = {
5688 onCommit : async ( ) => { } ,
57- hasFiles : false
89+ hasFiles : false ,
90+ commands : defaultCommands
5891 } ;
5992 const component = shallow ( < CommitBox { ...props } /> ) ;
6093 const node = component . find ( 'TextareaAutosize' ) . first ( ) ;
61- expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Description' ) ;
94+ expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Description (optional) ' ) ;
6295 } ) ;
6396
6497 it ( 'should set a `title` attribute on the input element to provide a commit message description' , ( ) => {
6598 const props = {
6699 onCommit : async ( ) => { } ,
67- hasFiles : false
100+ hasFiles : false ,
101+ commands : defaultCommands
68102 } ;
69103 const component = shallow ( < CommitBox { ...props } /> ) ;
70104 const node = component . find ( 'TextareaAutosize' ) . first ( ) ;
@@ -74,7 +108,8 @@ describe('CommitBox', () => {
74108 it ( 'should display a button to commit changes' , ( ) => {
75109 const props = {
76110 onCommit : async ( ) => { } ,
77- hasFiles : false
111+ hasFiles : false ,
112+ commands : defaultCommands
78113 } ;
79114 const component = shallow ( < CommitBox { ...props } /> ) ;
80115 const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -84,7 +119,8 @@ describe('CommitBox', () => {
84119 it ( 'should set a `title` attribute on the button to commit changes' , ( ) => {
85120 const props = {
86121 onCommit : async ( ) => { } ,
87- hasFiles : false
122+ hasFiles : false ,
123+ commands : defaultCommands
88124 } ;
89125 const component = shallow ( < CommitBox { ...props } /> ) ;
90126 const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -94,7 +130,8 @@ describe('CommitBox', () => {
94130 it ( 'should apply a class to disable the commit button when no files have changes to commit' , ( ) => {
95131 const props = {
96132 onCommit : async ( ) => { } ,
97- hasFiles : false
133+ hasFiles : false ,
134+ commands : defaultCommands
98135 } ;
99136 const component = shallow ( < CommitBox { ...props } /> ) ;
100137 const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -105,7 +142,8 @@ describe('CommitBox', () => {
105142 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' , ( ) => {
106143 const props = {
107144 onCommit : async ( ) => { } ,
108- hasFiles : true
145+ hasFiles : true ,
146+ commands : defaultCommands
109147 } ;
110148 const component = shallow ( < CommitBox { ...props } /> ) ;
111149 const node = component . find ( 'input[type="button"]' ) . first ( ) ;
@@ -116,7 +154,8 @@ describe('CommitBox', () => {
116154 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' , ( ) => {
117155 const props = {
118156 onCommit : async ( ) => { } ,
119- hasFiles : true
157+ hasFiles : true ,
158+ commands : defaultCommands
120159 } ;
121160 const component = shallow ( < CommitBox { ...props } /> ) ;
122161 component . setState ( {
0 commit comments