377
377
} ) ;
378
378
} ) ;
379
379
} , "NFCWriter.push should replace all previously configured push operations." ) ;
380
- </ script >
380
+
381
+ nfc_test ( async ( t , mockNFC ) => {
382
+ const writer = new NFCWriter ( ) ;
383
+ await writer . push ( { records : [ { data : test_text_data } ] } ) ;
384
+ assertNDEFMessagesEqual ( test_text_data , mockNFC . pushedMessage ( ) ) ;
385
+ } , "Test that recordType should be set to 'text' if NDEFRecordInit.record's \
386
+ recordType is undefined and NDEFRecordInit.record's data is DOMString." ) ;
387
+
388
+ nfc_test ( async ( t , mockNFC ) => {
389
+ const writer = new NFCWriter ( ) ;
390
+ await writer . push ( { records : [ { data : test_buffer_data } ] } ) ;
391
+ assertNDEFMessagesEqual ( test_buffer_data , mockNFC . pushedMessage ( ) ) ;
392
+ } , "Test that recordType should be set to 'opaque' if NDEFRecordInit.record's \
393
+ recordType is undefined and NDEFRecordInit.record's data is ArrayBuffer." ) ;
394
+
395
+ nfc_test ( async ( t , mockNFC ) => {
396
+ const writer = new NFCWriter ( ) ;
397
+ await writer . push ( { records : [ { data : test_json_data } ] } ) ;
398
+ const message = createMessage ( [ createJsonRecord ( test_json_data ) ] ) ;
399
+ assertNDEFMessagesEqual ( message , mockNFC . pushedMessage ( ) ) ;
400
+ } , "Test that recordType should be set to 'json' if NDEFRecordInit.record's \
401
+ recordType is undefined and NDEFRecordInit.record's data is not DOMString or \
402
+ ArrayBuffer." ) ;
403
+
404
+ nfc_test ( async ( t , mockNFC ) => {
405
+ const writer = new NFCWriter ( ) ;
406
+ await writer . push ( { records : [ { recordType : "text" , data : test_text_data } ] } ) ;
407
+ assertNDEFMessagesEqual ( test_text_data , mockNFC . pushedMessage ( ) ) ;
408
+ } , "Test that mediaType should be set to 'text/plain' if NDEFRecordInit.record's \
409
+ recordType is 'text' and NDEFRecordInit.record's mediaType is undefined." ) ;
410
+
411
+ nfc_test ( async ( t , mockNFC ) => {
412
+ const writer = new NFCWriter ( ) ;
413
+ await writer . push ( { records : [ { recordType : "opaque" , data : test_buffer_data } ] } ) ;
414
+ assertNDEFMessagesEqual ( test_buffer_data , mockNFC . pushedMessage ( ) ) ;
415
+ } , "Test that mediaType should be set to 'application/octet-stream' if \
416
+ NDEFRecordInit.record's recordType is 'opaque' and NDEFRecordInit.record's \
417
+ mediaType is undefined." ) ;
418
+
419
+ nfc_test ( async ( t , mockNFC ) => {
420
+ const writer = new NFCWriter ( ) ;
421
+ await writer . push ( { records : [ { recordType : "json" , data : test_json_data } ] } ) ;
422
+ const message = createMessage ( [ createJsonRecord ( test_json_data ) ] ) ;
423
+ assertNDEFMessagesEqual ( message , mockNFC . pushedMessage ( ) ) ;
424
+ } , "Test that mediaType should be set to 'application/json' if \
425
+ NDEFRecordInit.record's recordType is 'json' and NDEFRecordInit.record's \
426
+ mediaType is undefined." ) ;
427
+
428
+ nfc_test ( async ( t , mockNFC ) => {
429
+ const writer = new NFCWriter ( ) ;
430
+ await writer . push ( { records : [ { recordType : "url" , data : test_url_data } ] } ) ;
431
+ const message = createMessage ( [ createUrlRecord ( test_url_data ) ] ) ;
432
+ assertNDEFMessagesEqual ( message , mockNFC . pushedMessage ( ) ) ;
433
+ } , "Test that mediaType should be set to 'text/plain' if NDEFRecordInit.record's \
434
+ recordType is 'url' and NDEFRecordInit.record's mediaType is undefined." ) ;
435
+
436
+ nfc_test ( async ( t , mockNFC ) => {
437
+ const writer = new NFCWriter ( ) ;
438
+ await writer . push ( { records : [ { recordType : "w3.org:xyz" , data : test_buffer_data } ] } ) ;
439
+ const message = createMessage ( [ createRecord ( 'w3.org:xyz' , 'application/octet-stream' ,
440
+ test_buffer_data ) ] ) ;
441
+ assertNDEFMessagesEqual ( message , mockNFC . pushedMessage ( ) ) ;
442
+ } , "Test that mediaType should be set to 'application/octet-stream' if \
443
+ NDEFRecordInit.record's recordType is external type and NDEFRecordInit.record's \
444
+ mediaType is undefined." ) ;
445
+ </ script >
0 commit comments