@@ -335,6 +335,76 @@ test("template set with base message", async () => {
335
335
expect ( getByTestId ( "body" ) . value ) . toBe ( `blurg\n\n\nOn ${ msg . date } , ${ msg . from } wrote:\n> Test mail` ) ;
336
336
} ) ;
337
337
338
+ test ( "complex template set by click" , async ( ) => {
339
+ const tmpl = { "from" :
"foo" , "to" :
[ "[email protected] " ] , "cc" :
[ "[email protected] " ] , "bcc" :
[ "[email protected] " ] ,
340
+ "subject" : "fooSubject" , "tags" : [ "tag1" , "tag2" ] , "body" : "barBody" } ,
341
+ cmp = { "templates" : [ { "shortcut" : "1" , "description" : "foo" , "template" : tmpl } ] } ;
342
+ vi . stubGlobal ( "data" , { "accounts" : accts , "allTags" : tags , "compose" : cmp } ) ;
343
+ const { getByTestId } = render ( ( ) => < Write /> ) ;
344
+
345
+ await vi . waitFor ( ( ) => {
346
+ expect ( screen . getByText ( "Send" ) ) . toBeInTheDocument ( ) ;
347
+ } ) ;
348
+
349
+ expect ( screen . getByText ( "foo (1)" ) ) . toBeInTheDocument ( ) ;
350
+ expect ( getByTestId ( "from" ) . value ) . toBe ( "bar" ) ;
351
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
352
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
353
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
354
+ expect ( getByTestId ( "subject" ) . value ) . toBe ( "" ) ;
355
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
356
+ expect ( getByTestId ( "body" ) . value ) . toBe ( "" ) ;
357
+
358
+ await userEvent . click ( screen . getByText ( "foo (1)" ) ) ;
359
+ expect ( getByTestId ( "from" ) . value ) . toBe ( "foo" ) ;
360
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
361
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
362
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
363
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
364
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
365
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
366
+ expect ( getByTestId ( "subject" ) . value ) . toBe ( "fooSubject" ) ;
367
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 2 ) ;
368
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "tag1" ) ;
369
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) [ 1 ] . textContent ) . toBe ( "tag2" ) ;
370
+ expect ( getByTestId ( "body" ) . value ) . toBe ( "barBody" ) ;
371
+ } ) ;
372
+
373
+ test ( "complex template set by shortcut" , async ( ) => {
374
+ const tmpl = { "from" :
"foo" , "to" :
[ "[email protected] " ] , "cc" :
[ "[email protected] " ] , "bcc" :
[ "[email protected] " ] ,
375
+ "subject" : "fooSubject" , "tags" : [ "tag1" , "tag2" ] , "body" : "barBody" } ,
376
+ cmp = { "templates" : [ { "shortcut" : "1" , "description" : "foo" , "template" : tmpl } ] } ;
377
+ vi . stubGlobal ( "data" , { "accounts" : accts , "allTags" : tags , "compose" : cmp } ) ;
378
+ const { getByTestId } = render ( ( ) => < Write /> ) ;
379
+
380
+ await vi . waitFor ( ( ) => {
381
+ expect ( screen . getByText ( "Send" ) ) . toBeInTheDocument ( ) ;
382
+ } ) ;
383
+
384
+ expect ( screen . getByText ( "foo (1)" ) ) . toBeInTheDocument ( ) ;
385
+ expect ( getByTestId ( "from" ) . value ) . toBe ( "bar" ) ;
386
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
387
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
388
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
389
+ expect ( getByTestId ( "subject" ) . value ) . toBe ( "" ) ;
390
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 0 ) ;
391
+ expect ( getByTestId ( "body" ) . value ) . toBe ( "" ) ;
392
+
393
+ await userEvent . type ( document . body , "1" ) ;
394
+ expect ( getByTestId ( "from" ) . value ) . toBe ( "foo" ) ;
395
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
396
+ expect ( getByTestId ( "to" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
397
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
398
+ expect ( getByTestId ( "cc" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
399
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 1 ) ;
400
+ expect ( getByTestId ( "bcc" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "[email protected] " ) ;
401
+ expect ( getByTestId ( "subject" ) . value ) . toBe ( "fooSubject" ) ;
402
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) . length ) . toBe ( 2 ) ;
403
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) [ 0 ] . textContent ) . toBe ( "tag1" ) ;
404
+ expect ( getByTestId ( "tagedit" ) . querySelectorAll ( ".chip" ) [ 1 ] . textContent ) . toBe ( "tag2" ) ;
405
+ expect ( getByTestId ( "body" ) . value ) . toBe ( "barBody" ) ;
406
+ } ) ;
407
+
338
408
test ( "addresses editable and complete" , async ( ) => {
339
409
const { getByTestId } = render ( ( ) => < Write /> ) ;
340
410
0 commit comments