@@ -29,12 +29,10 @@ describe('KeyboardShortcutsModal', () => {
2929 ) ;
3030 } ;
3131
32- const findButton = ( wrapper , label ) =>
33- wrapper . find ( 'Button' ) . filterWhere ( node => node . props ( ) . children === label ) ;
34- const findShortcutInput = ( wrapper , label ) =>
35- wrapper
36- . find ( 'Input' )
37- . filterWhere ( node => node . prop ( 'aria-label' ) === `Shortcut for ${ label } ` ) ;
32+ const findButton = ( wrapper , testId ) =>
33+ wrapper . find ( `[data-testid="${ testId } "]` ) . first ( ) ;
34+ const findShortcutInput = ( wrapper , id ) =>
35+ wrapper . find ( `[data-testid="shortcut-input-${ id } "]` ) . first ( ) ;
3836
3937 beforeEach ( ( ) => {
4038 fakeSession = {
@@ -101,7 +99,7 @@ describe('KeyboardShortcutsModal', () => {
10199 it ( 'saves shortcuts when there are no duplicates' , ( ) => {
102100 const wrapper = createComponent ( ) ;
103101
104- const saveButton = findButton ( wrapper , 'Save ' ) ;
102+ const saveButton = findButton ( wrapper , 'save-shortcuts-button ' ) ;
105103 saveButton . props ( ) . onClick ( ) ;
106104
107105 assert . calledWith (
@@ -119,7 +117,7 @@ describe('KeyboardShortcutsModal', () => {
119117 const wrapper = createComponent ( ) ;
120118
121119 assert . isTrue ( wrapper . exists ( '[data-testid="duplicate-shortcuts-error"]' ) ) ;
122- const saveButton = findButton ( wrapper , 'Save ' ) ;
120+ const saveButton = findButton ( wrapper , 'save-shortcuts-button ' ) ;
123121 assert . isTrue ( saveButton . prop ( 'disabled' ) ) ;
124122 } ) ;
125123
@@ -138,7 +136,7 @@ describe('KeyboardShortcutsModal', () => {
138136 it ( 'resets shortcuts to defaults' , ( ) => {
139137 const wrapper = createComponent ( ) ;
140138
141- const resetButton = findButton ( wrapper , 'Reset all shortcuts to defaults ' ) ;
139+ const resetButton = findButton ( wrapper , 'reset- shortcuts-button ' ) ;
142140 resetButton . props ( ) . onClick ( ) ;
143141
144142 assert . called ( fakeResetShortcuts ) ;
@@ -156,7 +154,7 @@ describe('KeyboardShortcutsModal', () => {
156154
157155 const wrapper = createComponent ( ) ;
158156
159- const saveButton = findButton ( wrapper , 'Save ' ) ;
157+ const saveButton = findButton ( wrapper , 'save-shortcuts-button ' ) ;
160158 saveButton . props ( ) . onClick ( ) ;
161159
162160 assert . notCalled ( fakeSession . updateShortcutPreferences ) ;
@@ -169,13 +167,78 @@ describe('KeyboardShortcutsModal', () => {
169167
170168 const wrapper = createComponent ( ) ;
171169
172- const saveButton = findButton ( wrapper , 'Save ' ) ;
170+ const saveButton = findButton ( wrapper , 'save-shortcuts-button ' ) ;
173171 await saveButton . props ( ) . onClick ( ) ;
174172
175173 wrapper . update ( ) ;
176174 assert . isTrue ( wrapper . exists ( '[data-testid="save-shortcuts-error"]' ) ) ;
177175 } ) ;
178176
177+ it ( 'shows an error message when resetting shortcuts fails' , async ( ) => {
178+ fakeSession . updateShortcutPreferences . rejects (
179+ new Error ( 'Error resetting shortcuts' ) ,
180+ ) ;
181+
182+ const wrapper = createComponent ( ) ;
183+
184+ const resetButton = findButton ( wrapper , 'reset-shortcuts-button' ) ;
185+ await resetButton . props ( ) . onClick ( ) ;
186+
187+ wrapper . update ( ) ;
188+ assert . isTrue ( wrapper . exists ( '[data-testid="save-shortcuts-error"]' ) ) ;
189+ } ) ;
190+
191+ it ( 'clears save errors when updating a shortcut' , async ( ) => {
192+ fakeSession . updateShortcutPreferences . rejects (
193+ new Error ( 'Error saving shortcuts' ) ,
194+ ) ;
195+ fakeParseShortcutInputEvent . returns ( {
196+ shortcut : 'ctrl+k' ,
197+ shouldClear : false ,
198+ } ) ;
199+
200+ const wrapper = createComponent ( ) ;
201+
202+ const saveButton = findButton ( wrapper , 'save-shortcuts-button' ) ;
203+ await saveButton . props ( ) . onClick ( ) ;
204+ wrapper . update ( ) ;
205+ assert . isTrue ( wrapper . exists ( '[data-testid="save-shortcuts-error"]' ) ) ;
206+
207+ const event = new KeyboardEvent ( 'keydown' , { key : 'k' , ctrlKey : true } ) ;
208+ findShortcutInput ( wrapper , 'applyUpdates' ) . props ( ) . onKeyDown ( event ) ;
209+
210+ wrapper . update ( ) ;
211+ assert . isFalse ( wrapper . exists ( '[data-testid="save-shortcuts-error"]' ) ) ;
212+ } ) ;
213+
214+ it ( 'renders shortcut labels and descriptions when provided' , ( ) => {
215+ fakeShortcutDefinitions . splice (
216+ 0 ,
217+ fakeShortcutDefinitions . length ,
218+ {
219+ id : 'applyUpdates' ,
220+ label : 'Apply new updates' ,
221+ description : 'Apply any new updates in the thread' ,
222+ group : 'Sidebar' ,
223+ } ,
224+ {
225+ id : 'annotateSelection' ,
226+ label : 'Annotate selection' ,
227+ group : 'Annotator' ,
228+ } ,
229+ ) ;
230+
231+ const wrapper = createComponent ( ) ;
232+
233+ const label = wrapper . find ( '[data-testid="shortcut-label-applyUpdates"]' ) ;
234+ assert . equal ( label . text ( ) , 'Apply new updates' ) ;
235+ const description = wrapper . find (
236+ '[data-testid="shortcut-description-applyUpdates"]' ,
237+ ) ;
238+ assert . equal ( description . length , 1 ) ;
239+ assert . equal ( description . text ( ) , 'Apply any new updates in the thread' ) ;
240+ } ) ;
241+
179242 it ( 'restores profile shortcuts on close' , ( ) => {
180243 const onClose = sinon . stub ( ) ;
181244 const profileShortcuts = { applyUpdates : 'p' } ;
@@ -190,10 +253,10 @@ describe('KeyboardShortcutsModal', () => {
190253
191254 const wrapper = createComponent ( { onClose } ) ;
192255
193- const input = findShortcutInput ( wrapper , 'Apply new updates ' ) ;
256+ const input = findShortcutInput ( wrapper , 'applyUpdates ' ) ;
194257 input . props ( ) . onKeyDown ( new KeyboardEvent ( 'keydown' , { key : 'x' } ) ) ;
195258
196- const cancelButton = findButton ( wrapper , 'Cancel ' ) ;
259+ const cancelButton = findButton ( wrapper , 'cancel-shortcuts-button ' ) ;
197260 cancelButton . props ( ) . onClick ( ) ;
198261
199262 assert . calledWith ( fakeSetShortcut , 'applyUpdates' , 'x' ) ;
@@ -221,7 +284,7 @@ describe('KeyboardShortcutsModal', () => {
221284 const wrapper = createComponent ( ) ;
222285 const event = new KeyboardEvent ( 'keydown' , { key : 'k' , ctrlKey : true } ) ;
223286
224- findShortcutInput ( wrapper , 'Apply new updates ' ) . props ( ) . onKeyDown ( event ) ;
287+ findShortcutInput ( wrapper , 'applyUpdates ' ) . props ( ) . onKeyDown ( event ) ;
225288
226289 assert . calledWith ( fakeParseShortcutInputEvent , event ) ;
227290 assert . calledWith ( fakeSetShortcut , 'applyUpdates' , parsedShortcut . shortcut ) ;
@@ -239,7 +302,7 @@ describe('KeyboardShortcutsModal', () => {
239302 stopPropagation : sinon . stub ( ) ,
240303 } ;
241304
242- findShortcutInput ( wrapper , 'Apply new updates ' ) . props ( ) . onKeyDown ( event ) ;
305+ findShortcutInput ( wrapper , 'applyUpdates ' ) . props ( ) . onKeyDown ( event ) ;
243306
244307 assert . called ( event . preventDefault ) ;
245308 assert . called ( event . stopPropagation ) ;
@@ -250,7 +313,7 @@ describe('KeyboardShortcutsModal', () => {
250313
251314 const wrapper = createComponent ( ) ;
252315
253- findShortcutInput ( wrapper , 'Apply new updates ' )
316+ findShortcutInput ( wrapper , 'applyUpdates ' )
254317 . props ( )
255318 . onKeyDown ( new KeyboardEvent ( 'keydown' , { key : 'Shift' } ) ) ;
256319
@@ -265,7 +328,7 @@ describe('KeyboardShortcutsModal', () => {
265328
266329 const wrapper = createComponent ( ) ;
267330
268- findShortcutInput ( wrapper , 'Apply new updates ' )
331+ findShortcutInput ( wrapper , 'applyUpdates ' )
269332 . props ( )
270333 . onKeyDown ( new KeyboardEvent ( 'keydown' , { key : 'Backspace' } ) ) ;
271334
0 commit comments