@@ -509,6 +509,139 @@ describe('Collection import', function () {
509
509
await toastElement . waitForDisplayed ( { reverse : true } ) ;
510
510
} ) ;
511
511
512
+ context ( 'with validation' , function ( ) {
513
+ beforeEach ( async function ( ) {
514
+ const FAILING_VALIDATOR =
515
+ '{ $jsonSchema: { bsonType: "object", required: [ "abcdefgh" ] } }' ;
516
+ await browser . setValidation ( {
517
+ connectionName : DEFAULT_CONNECTION_NAME_1 ,
518
+ database : 'test' ,
519
+ collection : 'extended-json-file' ,
520
+ validator : FAILING_VALIDATOR ,
521
+ } ) ;
522
+ } ) ;
523
+
524
+ afterEach ( async function ( ) {
525
+ await browser . navigateWithinCurrentCollectionTabs ( 'Validation' ) ;
526
+ await browser . setValidationWithinValidationTab ( '{}' ) ;
527
+ } ) ;
528
+
529
+ it ( 'with JSON + abort on error checked, it displays a validation error with details' , async function ( ) {
530
+ const jsonPath = path . resolve (
531
+ __dirname ,
532
+ '..' ,
533
+ 'fixtures' ,
534
+ 'three-documents.json'
535
+ ) ;
536
+
537
+ await browser . navigateWithinCurrentCollectionTabs ( 'Documents' ) ;
538
+
539
+ // open the import modal
540
+ await browser . clickVisible ( Selectors . AddDataButton ) ;
541
+ const insertDocumentOption = browser . $ ( Selectors . ImportFileOption ) ;
542
+ await insertDocumentOption . waitForDisplayed ( ) ;
543
+ await browser . clickVisible ( Selectors . ImportFileOption ) ;
544
+
545
+ // Select the file.
546
+ await browser . selectFile ( Selectors . ImportFileInput , jsonPath ) ;
547
+ // Wait for the modal to appear.
548
+ const importModal = browser . $ ( Selectors . ImportModal ) ;
549
+ await importModal . waitForDisplayed ( ) ;
550
+
551
+ // Click the stop on errors checkbox.
552
+ const stopOnErrorsCheckbox = browser . $ (
553
+ Selectors . ImportStopOnErrorsCheckbox
554
+ ) ;
555
+ const stopOnErrorsLabel = stopOnErrorsCheckbox . parentElement ( ) ;
556
+ await stopOnErrorsLabel . click ( ) ;
557
+
558
+ // Confirm import.
559
+ await browser . clickVisible ( Selectors . ImportConfirm ) ;
560
+
561
+ // Wait for the modal to go away.
562
+ await importModal . waitForDisplayed ( { reverse : true } ) ;
563
+
564
+ // Wait for the error toast to appear
565
+ const toastElement = browser . $ ( Selectors . ImportToast ) ;
566
+ await toastElement . waitForDisplayed ( ) ;
567
+ const errorText = await toastElement . getText ( ) ;
568
+ expect ( errorText ) . to . include ( 'Document failed validation' ) ;
569
+
570
+ // Visit error details
571
+ await browser . clickVisible ( Selectors . ImportToastErrorDetailsBtn ) ;
572
+ const errorDetailsModal = browser . $ ( Selectors . ImportErrorDetailsModal ) ;
573
+ await errorDetailsModal . waitForDisplayed ( ) ;
574
+ expect ( await errorDetailsModal . getText ( ) ) . to . include (
575
+ 'schemaRulesNotSatisfied'
576
+ ) ;
577
+ await browser . clickVisible ( Selectors . ErrorDetailsCloseButton ) ;
578
+
579
+ // Close the toast
580
+ await browser
581
+ . $ ( Selectors . closeToastButton ( Selectors . ImportToast ) )
582
+ . waitForDisplayed ( ) ;
583
+ await browser . clickVisible (
584
+ Selectors . closeToastButton ( Selectors . ImportToast )
585
+ ) ;
586
+ await toastElement . waitForDisplayed ( { reverse : true } ) ;
587
+ } ) ;
588
+
589
+ it ( 'with CSV + abort on error unchecked, it includes the details in a file' , async function ( ) {
590
+ const filename = 'array-documents.csv' ;
591
+ const csvPath = path . resolve ( __dirname , '..' , 'fixtures' , filename ) ;
592
+
593
+ await browser . navigateWithinCurrentCollectionTabs ( 'Documents' ) ;
594
+
595
+ // open the import modal
596
+ await browser . clickVisible ( Selectors . AddDataButton ) ;
597
+ const insertDocumentOption = browser . $ ( Selectors . ImportFileOption ) ;
598
+ await insertDocumentOption . waitForDisplayed ( ) ;
599
+ await browser . clickVisible ( Selectors . ImportFileOption ) ;
600
+
601
+ // Select the file.
602
+ await browser . selectFile ( Selectors . ImportFileInput , csvPath ) ;
603
+ // Wait for the modal to appear.
604
+ const importModal = browser . $ ( Selectors . ImportModal ) ;
605
+ await importModal . waitForDisplayed ( ) ;
606
+
607
+ // Confirm import.
608
+ await browser . clickVisible ( Selectors . ImportConfirm ) ;
609
+
610
+ // Wait for the modal to go away.
611
+ await importModal . waitForDisplayed ( { reverse : true } ) ;
612
+
613
+ // Wait for the error toast to appear
614
+ const toastElement = browser . $ ( Selectors . ImportToast ) ;
615
+ await toastElement . waitForDisplayed ( ) ;
616
+ const errorText = await toastElement . getText ( ) ;
617
+ console . log ( { errorText } ) ;
618
+ expect ( errorText ) . to . include ( 'Document failed validation' ) ;
619
+ expect ( errorText ) . to . include ( 'VIEW LOG' ) ;
620
+
621
+ // Find the log file
622
+ const logFilePath = path . resolve (
623
+ compass . userDataPath || '' ,
624
+ compass . appName || '' ,
625
+ 'ImportErrorLogs' ,
626
+ `import-${ filename } .log`
627
+ ) ;
628
+ await expect ( fs . stat ( logFilePath ) ) . to . not . be . rejected ;
629
+
630
+ // Check the log file contents for 3 errors.
631
+ const logFileContent = await fs . readFile ( logFilePath , 'utf-8' ) ;
632
+ expect ( logFileContent . includes ( 'schemaRulesNotSatisfied:' ) ) ;
633
+
634
+ // Close the toast
635
+ await browser
636
+ . $ ( Selectors . closeToastButton ( Selectors . ImportToast ) )
637
+ . waitForDisplayed ( ) ;
638
+ await browser . clickVisible (
639
+ Selectors . closeToastButton ( Selectors . ImportToast )
640
+ ) ;
641
+ await toastElement . waitForDisplayed ( { reverse : true } ) ;
642
+ } ) ;
643
+ } ) ;
644
+
512
645
it ( 'supports CSV files' , async function ( ) {
513
646
const csvPath = path . resolve ( __dirname , '..' , 'fixtures' , 'listings.csv' ) ;
514
647
0 commit comments