1
+ import type { InternalNativeIntegrationFormCodeMapControl } from './internal/InternalNativeIntegrationFormCodeMapControl/InternalNativeIntegrationFormCodeMapControl' ;
2
+ import type { InternalPasswordControl } from '../../internal/InternalPasswordControl/InternalPasswordControl' ;
3
+ import type { InternalSwitchControl } from '../../internal/InternalSwitchControl/InternalSwitchControl' ;
4
+ import type { InternalTextControl } from '../../internal/InternalTextControl/InternalTextControl' ;
5
+ import type { NucleonElement } from '../NucleonElement/NucleonElement' ;
1
6
import type { Data } from './types' ;
2
7
3
8
import './index' ;
@@ -6,9 +11,6 @@ import { expect, fixture, html, waitUntil } from '@open-wc/testing';
6
11
import { NativeIntegrationForm as Form } from './NativeIntegrationForm' ;
7
12
import { InternalEditableListControl } from '../../internal/InternalEditableListControl/InternalEditableListControl' ;
8
13
import { InternalSelectControl } from '../../internal/InternalSelectControl/InternalSelectControl' ;
9
- import { InternalPasswordControl } from '../../internal/InternalPasswordControl/InternalPasswordControl' ;
10
- import { InternalSwitchControl } from '../../internal/InternalSwitchControl/InternalSwitchControl' ;
11
- import { InternalTextControl } from '../../internal/InternalTextControl/InternalTextControl' ;
12
14
import { createRouter } from '../../../server' ;
13
15
import { getTestData } from '../../../testgen/getTestData' ;
14
16
import { FetchEvent } from '../NucleonElement/FetchEvent' ;
@@ -17,6 +19,17 @@ import { stub } from 'sinon';
17
19
18
20
import * as defaults from './defaults' ;
19
21
22
+ async function waitForIdle ( element : Form ) {
23
+ await waitUntil (
24
+ ( ) => {
25
+ const loaders = element . renderRoot . querySelectorAll < NucleonElement < any > > ( 'foxy-nucleon' ) ;
26
+ return [ ...loaders ] . every ( loader => loader . in ( 'idle' ) ) ;
27
+ } ,
28
+ '' ,
29
+ { timeout : 5000 }
30
+ ) ;
31
+ }
32
+
20
33
describe ( 'NativeIntegrationForm' , ( ) => {
21
34
it ( 'imports and defines foxy-internal-editable-list-control element' , ( ) => {
22
35
expect ( customElements . get ( 'foxy-internal-editable-list-control' ) ) . to . exist ;
@@ -46,6 +59,10 @@ describe('NativeIntegrationForm', () => {
46
59
expect ( customElements . get ( 'foxy-internal-form' ) ) . to . exist ;
47
60
} ) ;
48
61
62
+ it ( 'imports and defines foxy-internal-native-integration-form-code-map-control element' , ( ) => {
63
+ expect ( customElements . get ( 'foxy-internal-native-integration-form-code-map-control' ) ) . to . exist ;
64
+ } ) ;
65
+
49
66
it ( 'defines itself as foxy-native-integration-form element' , ( ) => {
50
67
expect ( customElements . get ( 'foxy-native-integration-form' ) ) . to . equal ( Form ) ;
51
68
} ) ;
@@ -59,6 +76,14 @@ describe('NativeIntegrationForm', () => {
59
76
expect ( new Form ( ) ) . to . have . property ( 'ns' , 'native-integration-form' ) ;
60
77
} ) ;
61
78
79
+ it ( 'has a reactive property itemCategoryBase' , ( ) => {
80
+ const element = new Form ( ) ;
81
+ expect ( element ) . to . have . property ( 'itemCategoryBase' ) . that . equals ( null ) ;
82
+ expect ( Form . properties ) . to . have . deep . property ( 'itemCategoryBase' , {
83
+ attribute : 'item-category-base' ,
84
+ } ) ;
85
+ } ) ;
86
+
62
87
it ( 'produces avalara-service-url:v8n_required error if service url for avalara is missing' , ( ) => {
63
88
const element = new Form ( ) ;
64
89
element . edit ( { provider : 'avalara' } ) ;
@@ -101,15 +126,6 @@ describe('NativeIntegrationForm', () => {
101
126
expect ( element . errors ) . to . not . include ( 'avalara-company-code:v8n_required' ) ;
102
127
} ) ;
103
128
104
- it ( 'produces avalara-category-to-product-tax-code-mappings:v8n_required error if there are no mappings for avalara' , ( ) => {
105
- const element = new Form ( ) ;
106
- const error = 'avalara-category-to-product-tax-code-mappings:v8n_required' ;
107
- element . edit ( { provider : 'avalara' } ) ;
108
- expect ( element . errors ) . to . include ( error ) ;
109
- element . edit ( { config : JSON . stringify ( { category_to_product_tax_code_mappings : { a : 'b' } } ) } ) ;
110
- expect ( element . errors ) . to . not . include ( error ) ;
111
- } ) ;
112
-
113
129
it ( 'produces taxjar-api-token:v8n_required error if api token for taxjar is missing' , ( ) => {
114
130
const element = new Form ( ) ;
115
131
element . edit ( { provider : 'taxjar' } ) ;
@@ -493,32 +509,49 @@ describe('NativeIntegrationForm', () => {
493
509
expect ( control ) . to . have . attribute ( 'layout' , 'summary-item' ) ;
494
510
} ) ;
495
511
496
- it ( 'renders an editable list control for avalara tax code mappings in avalara group two ' , async ( ) => {
512
+ it ( 'renders an internal control for avalara tax code mappings' , async ( ) => {
497
513
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
514
+ const router = createRouter ( ) ;
515
+
498
516
data . provider = 'avalara' ;
499
517
data . config = JSON . stringify ( {
500
518
...JSON . parse ( defaults . avalara ) ,
501
519
category_to_product_tax_code_mappings : { foo : 'bar' , bar : 'qux' } ,
502
520
} ) ;
503
521
504
522
const element = await fixture < Form > ( html `
505
- < foxy-native-integration-form .data =${ data } > </ foxy-native-integration-form >
523
+ < foxy-native-integration-form
524
+ item-category-base ="https://demo.api/hapi/item_categories/ "
525
+ store ="https://demo.api/hapi/stores/0 "
526
+ .data =${ data }
527
+ @fetch =${ ( evt : FetchEvent ) => router . handleEvent ( evt ) }
528
+ >
529
+ </ foxy-native-integration-form >
506
530
` ) ;
507
531
532
+ await waitForIdle ( element ) ;
508
533
const control = element . renderRoot . querySelector (
509
- 'foxy-internal-summary-control[infer="avalara-group-two"] foxy-internal-editable-list -control[infer="avalara-category-to-product-tax-code-mappings"]'
510
- ) as InternalEditableListControl ;
534
+ 'foxy-internal-native-integration-form-code-map -control[infer="avalara-category-to-product-tax-code-mappings"]'
535
+ ) as InternalNativeIntegrationFormCodeMapControl ;
511
536
512
537
expect ( control ) . to . exist ;
513
- expect ( control ) . to . have . attribute ( 'layout' , 'summary-item' ) ;
514
- expect ( control . getValue ( ) ) . to . deep . equal ( [ { value : 'foo:bar' } , { value : 'bar:qux' } ] ) ;
515
538
516
- control . setValue ( [ { value : 'a:b' } ] ) ;
517
- const config = JSON . parse ( element . form . config as string ) ;
518
- expect ( config ) . to . have . deep . property ( 'category_to_product_tax_code_mappings' , { a : 'b' } ) ;
539
+ expect ( control ) . to . have . attribute (
540
+ 'item-category-base' ,
541
+ 'https://demo.api/hapi/item_categories/'
542
+ ) ;
543
+
544
+ expect ( control ) . to . have . attribute (
545
+ 'item-categories' ,
546
+ 'https://demo.api/hapi/item_categories?store_id=0'
547
+ ) ;
548
+
549
+ expect ( control ) . to . have . attribute ( 'json-template' , defaults . avalara ) ;
550
+ expect ( control ) . to . have . attribute ( 'json-path' , 'category_to_product_tax_code_mappings' ) ;
551
+ expect ( control ) . to . have . attribute ( 'property' , 'config' ) ;
519
552
} ) ;
520
553
521
- it ( 'renders a switch control for avalara use_ava_tax in avalara group three ' , async ( ) => {
554
+ it ( 'renders a switch control for avalara use_ava_tax in avalara group two ' , async ( ) => {
522
555
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
523
556
data . provider = 'avalara' ;
524
557
data . config = JSON . stringify ( { ...JSON . parse ( defaults . avalara ) , use_ava_tax : true } ) ;
@@ -528,7 +561,7 @@ describe('NativeIntegrationForm', () => {
528
561
` ) ;
529
562
530
563
const control = element . renderRoot . querySelector (
531
- 'foxy-internal-summary-control[infer="avalara-group-three "] foxy-internal-switch-control[infer="avalara-use-ava-tax"]'
564
+ 'foxy-internal-summary-control[infer="avalara-group-two "] foxy-internal-switch-control[infer="avalara-use-ava-tax"]'
532
565
) ;
533
566
534
567
expect ( control ) . to . exist ;
@@ -537,7 +570,7 @@ describe('NativeIntegrationForm', () => {
537
570
expect ( control ) . to . have . attribute ( 'property' , 'config' ) ;
538
571
} ) ;
539
572
540
- it ( 'renders a switch control for avalara use_address_validation in avalara group three ' , async ( ) => {
573
+ it ( 'renders a switch control for avalara use_address_validation in avalara group two ' , async ( ) => {
541
574
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
542
575
data . provider = 'avalara' ;
543
576
data . config = JSON . stringify ( { ...JSON . parse ( defaults . avalara ) , use_address_validation : true } ) ;
@@ -547,7 +580,7 @@ describe('NativeIntegrationForm', () => {
547
580
` ) ;
548
581
549
582
const control = element . renderRoot . querySelector (
550
- 'foxy-internal-summary-control[infer="avalara-group-three "] foxy-internal-switch-control[infer="avalara-use-address-validation"]'
583
+ 'foxy-internal-summary-control[infer="avalara-group-two "] foxy-internal-switch-control[infer="avalara-use-address-validation"]'
551
584
) ;
552
585
553
586
expect ( control ) . to . exist ;
@@ -569,7 +602,7 @@ describe('NativeIntegrationForm', () => {
569
602
` ) ;
570
603
571
604
const control = element . renderRoot . querySelector (
572
- 'foxy-internal-summary-control[infer="avalara-group-three "] foxy-internal-editable-list-control[infer="avalara-address-validation-countries"]'
605
+ 'foxy-internal-summary-control[infer="avalara-group-two "] foxy-internal-editable-list-control[infer="avalara-address-validation-countries"]'
573
606
) as InternalEditableListControl ;
574
607
575
608
expect ( control ) . to . exist ;
@@ -580,7 +613,7 @@ describe('NativeIntegrationForm', () => {
580
613
expect ( control ) . to . have . deep . property ( 'options' , [ { value : 'US' } , { value : 'CA' } ] ) ;
581
614
} ) ;
582
615
583
- it ( 'renders a switch control for avalara create_invoice in avalara group three ' , async ( ) => {
616
+ it ( 'renders a switch control for avalara create_invoice in avalara group two ' , async ( ) => {
584
617
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
585
618
data . provider = 'avalara' ;
586
619
data . config = JSON . stringify ( { ...JSON . parse ( defaults . avalara ) , create_invoice : true } ) ;
@@ -590,7 +623,7 @@ describe('NativeIntegrationForm', () => {
590
623
` ) ;
591
624
592
625
const control = element . renderRoot . querySelector (
593
- 'foxy-internal-summary-control[infer="avalara-group-three "] foxy-internal-switch-control[infer="avalara-create-invoice"]'
626
+ 'foxy-internal-summary-control[infer="avalara-group-two "] foxy-internal-switch-control[infer="avalara-create-invoice"]'
594
627
) ;
595
628
596
629
expect ( control ) . to . exist ;
@@ -599,7 +632,7 @@ describe('NativeIntegrationForm', () => {
599
632
expect ( control ) . to . have . attribute ( 'property' , 'config' ) ;
600
633
} ) ;
601
634
602
- it ( 'renders a switch control for avalara enable_colorado_delivery_fee in avalara group three ' , async ( ) => {
635
+ it ( 'renders a switch control for avalara enable_colorado_delivery_fee in avalara group two ' , async ( ) => {
603
636
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
604
637
data . provider = 'avalara' ;
605
638
data . config = JSON . stringify ( {
@@ -612,7 +645,7 @@ describe('NativeIntegrationForm', () => {
612
645
` ) ;
613
646
614
647
const control = element . renderRoot . querySelector (
615
- 'foxy-internal-summary-control[infer="avalara-group-three "] foxy-internal-switch-control[infer="avalara-enable-colorado-delivery-fee"]'
648
+ 'foxy-internal-summary-control[infer="avalara-group-two "] foxy-internal-switch-control[infer="avalara-enable-colorado-delivery-fee"]'
616
649
) ;
617
650
618
651
expect ( control ) . to . exist ;
@@ -660,28 +693,46 @@ describe('NativeIntegrationForm', () => {
660
693
expect ( control ) . to . have . attribute ( 'property' , 'config' ) ;
661
694
} ) ;
662
695
663
- it ( 'renders an editable list control for taxjar product code mappings in taxjar group two ' , async ( ) => {
696
+ it ( 'renders an internal control for taxjar tax code mappings' , async ( ) => {
664
697
const data = await getTestData < Data > ( './hapi/native_integrations/0' ) ;
698
+ const router = createRouter ( ) ;
699
+
665
700
data . provider = 'taxjar' ;
666
701
data . config = JSON . stringify ( {
667
702
...JSON . parse ( defaults . taxjar ) ,
668
703
category_to_product_tax_code_mappings : { foo : 'bar' , bar : 'qux' } ,
669
704
} ) ;
670
705
671
706
const element = await fixture < Form > ( html `
672
- < foxy-native-integration-form .data =${ data } > </ foxy-native-integration-form >
707
+ < foxy-native-integration-form
708
+ item-category-base ="https://demo.api/hapi/item_categories/ "
709
+ store ="https://demo.api/hapi/stores/0 "
710
+ .data =${ data }
711
+ @fetch =${ ( evt : FetchEvent ) => router . handleEvent ( evt ) }
712
+ >
713
+ </ foxy-native-integration-form >
673
714
` ) ;
674
715
716
+ await waitForIdle ( element ) ;
675
717
const control = element . renderRoot . querySelector (
676
- '[infer="taxjar-group-two"] foxy-internal-editable-list -control[infer="taxjar-category-to-product-tax-code-mappings"]'
677
- ) as InternalEditableListControl ;
718
+ 'foxy-internal-native-integration-form-code-map -control[infer="taxjar-category-to-product-tax-code-mappings"]'
719
+ ) as InternalNativeIntegrationFormCodeMapControl ;
678
720
679
- expect ( control ) . to . be . instanceOf ( InternalEditableListControl ) ;
680
- expect ( control . getValue ( ) ) . to . deep . equal ( [ { value : 'foo:bar' } , { value : 'bar:qux' } ] ) ;
721
+ expect ( control ) . to . exist ;
681
722
682
- control . setValue ( [ { value : 'a:b' } ] ) ;
683
- const config = JSON . parse ( element . form . config as string ) ;
684
- expect ( config ) . to . have . deep . property ( 'category_to_product_tax_code_mappings' , { a : 'b' } ) ;
723
+ expect ( control ) . to . have . attribute (
724
+ 'item-category-base' ,
725
+ 'https://demo.api/hapi/item_categories/'
726
+ ) ;
727
+
728
+ expect ( control ) . to . have . attribute (
729
+ 'item-categories' ,
730
+ 'https://demo.api/hapi/item_categories?store_id=0'
731
+ ) ;
732
+
733
+ expect ( control ) . to . have . attribute ( 'json-template' , defaults . taxjar ) ;
734
+ expect ( control ) . to . have . attribute ( 'json-path' , 'category_to_product_tax_code_mappings' ) ;
735
+ expect ( control ) . to . have . attribute ( 'property' , 'config' ) ;
685
736
} ) ;
686
737
687
738
it ( 'renders a text control for onesource service url in onesource group one' , async ( ) => {
0 commit comments