@@ -2,7 +2,7 @@ import { EditorView } from '@codemirror/view';
22import ftl from '@fluent/dedent' ;
33import { fluentParseEntry } from '@mozilla/l10n' ;
44import { fireEvent } from '@testing-library/react' ;
5- import { useContext } from 'react' ;
5+ import { useContext , useState } from 'react' ;
66import { act } from 'react-dom/test-utils' ;
77import { beforeAll , describe , expect , it , vi } from 'vitest' ;
88
@@ -47,28 +47,29 @@ function mountForm(source, target = null, locale = DEFAULT_LOCALE) {
4747 } ,
4848 } ;
4949
50- let actions , result ;
50+ let actions , result , setCurrentEntity ;
5151 const Spy = ( ) => {
5252 actions = useContext ( EditorActions ) ;
5353 result = useContext ( EditorResult ) ;
5454 return null ;
5555 } ;
5656
57- const wrapper = mountComponentWithStore (
58- ( ) => (
57+ const wrapper = mountComponentWithStore ( ( ) => {
58+ const [ currentEntity , updateCurrentEntity ] = useState ( entity ) ;
59+ setCurrentEntity = updateCurrentEntity ;
60+ return (
5961 < Locale . Provider value = { locale } >
6062 < MockLocalizationProvider >
61- < EntityView . Provider value = { { entity } } >
63+ < EntityView . Provider value = { { entity : currentEntity } } >
6264 < EditorProvider >
6365 < Spy />
6466 < TranslationForm />
6567 </ EditorProvider >
6668 </ EntityView . Provider >
6769 </ MockLocalizationProvider >
6870 </ Locale . Provider >
69- ) ,
70- store ,
71- ) ;
71+ ) ;
72+ } , store ) ;
7273 vi . runAllTimers ( ) ;
7374
7475 // TODO:Replace the querySelector with testing-library-ish approaches
@@ -77,7 +78,7 @@ function mountForm(source, target = null, locale = DEFAULT_LOCALE) {
7778 EditorView . findFromDOM ( el ) ,
7879 ) ;
7980
80- return { actions, getResult : ( ) => result , views, wrapper } ;
81+ return { actions, getResult : ( ) => result , setCurrentEntity , views, wrapper } ;
8182}
8283
8384describe ( '<TranslationForm> with multiple fields' , ( ) => {
@@ -434,6 +435,39 @@ describe('<TranslationForm> with multiple fields', () => {
434435 expect ( docs ( ) ) . toEqual ( [ 'COMPOSED' , 'COMPOSED_LABEL' ] ) ;
435436 } ) ;
436437
438+ it ( 'inserts a placeable into the focused field after a rejection' , ( ) => {
439+ const source = ftl `
440+ key =
441+ { $num ->
442+ [one] ONE
443+ *[other] OTHER
444+ }
445+ ` ;
446+ const { actions, getResult, setCurrentEntity, views } = mountForm ( source ) ;
447+
448+ act ( ( ) =>
449+ setCurrentEntity ( ( entity ) => ( {
450+ ...entity ,
451+ translation : { ...entity . translation , status : 'rejected' } ,
452+ } ) ) ,
453+ ) ;
454+ vi . runAllTimers ( ) ;
455+
456+ act ( ( ) => views [ 1 ] . contentDOM . focus ( ) ) ;
457+ vi . runAllTimers ( ) ;
458+
459+ act ( ( ) => actions . setEditorSelection ( '{ $num }' ) ) ;
460+
461+ expect ( views . map ( ( view ) => view . state . doc . toString ( ) ) ) . toEqual ( [
462+ '' ,
463+ '{ $num }' ,
464+ ] ) ;
465+ expect ( getResult ( ) . value . alt ) . toMatchObject ( [
466+ { keys : [ 'one' ] , pat : [ ] } ,
467+ { keys : [ { '*' : 'other' } ] , pat : [ { $ : 'num' } ] } ,
468+ ] ) ;
469+ } ) ;
470+
437471 it ( 'copies a translation naming its catchall after the source, on one click' , ( ) => {
438472 const source = ftl `
439473 key =
0 commit comments