@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
import 'jest' ;
3
3
import { shallow } from 'enzyme' ;
4
4
import { CommitBox } from '../../src/components/CommitBox' ;
5
+ import { commitButtonDisabledClass } from '../../src/style/CommitBox' ;
5
6
6
7
describe ( 'CommitBox' , ( ) => {
7
8
describe ( '#constructor()' , ( ) => {
@@ -43,5 +44,52 @@ describe('CommitBox', () => {
43
44
const node = component . find ( 'TextareaAutosize' ) . first ( ) ;
44
45
expect ( node . prop ( 'placeholder' ) ) . toEqual ( 'Description' ) ;
45
46
} ) ;
47
+
48
+ it ( 'should display a button to commit changes' , ( ) => {
49
+ const props = {
50
+ onCommit : async ( ) => { } ,
51
+ hasFiles : false
52
+ } ;
53
+ const component = shallow ( < CommitBox { ...props } /> ) ;
54
+ const node = component . find ( 'input[type="button"]' ) . first ( ) ;
55
+ expect ( node . prop ( 'value' ) ) . toEqual ( 'Commit' ) ;
56
+ } ) ;
57
+
58
+ it ( 'should apply a class to disable the commit button when no files have changes to commit' , ( ) => {
59
+ const props = {
60
+ onCommit : async ( ) => { } ,
61
+ hasFiles : false
62
+ } ;
63
+ const component = shallow ( < CommitBox { ...props } /> ) ;
64
+ const node = component . find ( 'input[type="button"]' ) . first ( ) ;
65
+ const idx = node . prop ( 'className' ) . indexOf ( commitButtonDisabledClass ) ;
66
+ expect ( idx >= 0 ) . toEqual ( true ) ;
67
+ } ) ;
68
+
69
+ 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' , ( ) => {
70
+ const props = {
71
+ onCommit : async ( ) => { } ,
72
+ hasFiles : true
73
+ } ;
74
+ const component = shallow ( < CommitBox { ...props } /> ) ;
75
+ const node = component . find ( 'input[type="button"]' ) . first ( ) ;
76
+ const idx = node . prop ( 'className' ) . indexOf ( commitButtonDisabledClass ) ;
77
+ expect ( idx >= 0 ) . toEqual ( true ) ;
78
+ } ) ;
79
+
80
+ 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' , ( ) => {
81
+ const props = {
82
+ onCommit : async ( ) => { } ,
83
+ hasFiles : true
84
+ } ;
85
+ const component = shallow ( < CommitBox { ...props } /> ) ;
86
+ component . setState ( {
87
+ summary : 'beep boop'
88
+ } ) ;
89
+
90
+ const node = component . find ( 'input[type="button"]' ) . first ( ) ;
91
+ const idx = node . prop ( 'className' ) . indexOf ( commitButtonDisabledClass ) ;
92
+ expect ( idx >= 0 ) . toEqual ( false ) ;
93
+ } ) ;
46
94
} ) ;
47
95
} ) ;
0 commit comments