Skip to content

Commit 26594c5

Browse files
committed
feat(foxy-tax-form): update automatic tax calculation options for taxes
1 parent c69d7f4 commit 26594c5

File tree

3 files changed

+48
-82
lines changed

3 files changed

+48
-82
lines changed

src/elements/public/TaxForm/TaxForm.test.ts

+26-45
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,23 @@ describe('TaxForm', () => {
212212
it('conditionally hides service provider select', () => {
213213
const form = new Form();
214214
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.true;
215-
form.edit({ type: 'union' });
215+
form.edit({ type: 'global', is_live: true });
216+
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.true;
217+
form.edit({ type: 'union', is_live: true });
216218
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.false;
217-
form.edit({ type: 'country' });
219+
form.edit({ type: 'country', is_live: true });
218220
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.false;
219-
form.edit({ type: 'region' });
221+
form.edit({ type: 'region', is_live: true });
220222
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.false;
221-
form.edit({ type: 'local' });
222-
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.true;
223-
form.edit({ type: 'custom_tax_endpoint' as Data['type'] });
223+
form.edit({ type: 'local', is_live: true });
224+
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.false;
225+
form.edit({ type: 'custom_tax_endpoint' as Data['type'], is_live: true });
224226
expect(form.hiddenSelector.matches('group-one:service-provider', true)).to.be.true;
225227
});
226228

227229
it('conditionally hides rate input', () => {
228230
const form = new Form();
229-
expect(form.hiddenSelector.matches('group-one:rate', true)).to.be.true;
231+
expect(form.hiddenSelector.matches('group-one:rate', true)).to.be.false;
230232
form.edit({ type: 'union' });
231233
expect(form.hiddenSelector.matches('group-one:rate', true)).to.be.false;
232234
form.edit({ type: 'country' });
@@ -241,6 +243,23 @@ describe('TaxForm', () => {
241243
expect(form.hiddenSelector.matches('group-one:rate', true)).to.be.true;
242244
});
243245

246+
it('conditionally hides Live Rates input', () => {
247+
const form = new Form();
248+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.false;
249+
form.edit({ type: 'global' });
250+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.true;
251+
form.edit({ type: 'union' });
252+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.false;
253+
form.edit({ type: 'country' });
254+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.false;
255+
form.edit({ type: 'region' });
256+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.false;
257+
form.edit({ type: 'local' });
258+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.false;
259+
form.edit({ type: 'custom_tax_endpoint' as Data['type'] });
260+
expect(form.hiddenSelector.matches('group-one:is-live', true)).to.be.true;
261+
});
262+
244263
it('conditionally hides apply to shipping switch', () => {
245264
const form = new Form();
246265
expect(form.hiddenSelector.matches('group-two:apply-to-shipping', true)).to.be.true;
@@ -377,20 +396,11 @@ describe('TaxForm', () => {
377396
'options',
378397
JSON.stringify([
379398
{ label: 'option_default', value: 'default' },
380-
{ label: 'option_none', value: 'none' },
381399
{ label: 'option_avalara', value: 'avalara' },
382400
{ label: 'option_onesource', value: 'onesource' },
383401
{ label: 'option_taxjar', value: 'taxjar' },
384402
])
385403
);
386-
387-
expect(control?.getValue()).to.equal('none');
388-
389-
form.edit({ is_live: true });
390-
expect(control?.getValue()).to.equal('default');
391-
392-
form.edit({ service_provider: 'avalara' });
393-
expect(control?.getValue()).to.equal('avalara');
394404
});
395405

396406
it('conditionally hides some options for service provider', async () => {
@@ -403,7 +413,6 @@ describe('TaxForm', () => {
403413
await form.requestUpdate();
404414
expect(control?.options).to.deep.equal([
405415
{ label: 'option_default', value: 'default' },
406-
{ label: 'option_none', value: 'none' },
407416
{ label: 'option_avalara', value: 'avalara' },
408417
{ label: 'option_onesource', value: 'onesource' },
409418
{ label: 'option_taxjar', value: 'taxjar' },
@@ -412,39 +421,11 @@ describe('TaxForm', () => {
412421
form.edit({ type: 'country', country: 'AZ' });
413422
await form.requestUpdate();
414423
expect(control?.options).to.deep.equal([
415-
{ label: 'option_none', value: 'none' },
416424
{ label: 'option_avalara', value: 'avalara' },
417425
{ label: 'option_onesource', value: 'onesource' },
418426
]);
419427
});
420428

421-
it('resets some form values on service provider change', async () => {
422-
const form = await fixture<Form>(html`<foxy-tax-form></foxy-tax-form>`);
423-
const control = form.renderRoot.querySelector<InternalSelectControl>(
424-
'foxy-internal-summary-control[infer="group-one"] foxy-internal-select-control[infer="service-provider"]'
425-
);
426-
427-
form.edit({
428-
type: 'local',
429-
service_provider: 'avalara',
430-
use_origin_rates: true,
431-
is_live: true,
432-
exempt_all_customer_tax_ids: true,
433-
apply_to_shipping: true,
434-
});
435-
436-
control?.setValue('none');
437-
438-
expect(form.form).to.deep.equal({
439-
type: 'local',
440-
service_provider: '',
441-
use_origin_rates: false,
442-
is_live: false,
443-
exempt_all_customer_tax_ids: false,
444-
apply_to_shipping: false,
445-
});
446-
});
447-
448429
it('renders a number control for rate in group one', async () => {
449430
const form = await fixture<Form>(html`<foxy-tax-form></foxy-tax-form>`);
450431
const control = form.renderRoot.querySelector(

src/elements/public/TaxForm/TaxForm.ts

+14-34
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,6 @@ export class TaxForm extends Base<Data> {
6868
/** URL of the `fx:regions` property helper resource. */
6969
regions: string | null = null;
7070

71-
private __serviceProviderGetValue = () => {
72-
return this.form.service_provider || (this.form.is_live ? 'default' : 'none');
73-
};
74-
75-
private __serviceProviderSetValue = (newValue: string) => {
76-
const newProvider = ['none', 'default'].includes(newValue) ? '' : newValue;
77-
78-
this.edit({
79-
service_provider: newProvider as Data['service_provider'],
80-
use_origin_rates: false,
81-
is_live: newValue !== 'none',
82-
});
83-
84-
this.edit({
85-
exempt_all_customer_tax_ids: this.__isExemptAllCustomerTaxIdsHidden,
86-
apply_to_shipping: this.__isApplyToShippingHidden,
87-
});
88-
};
89-
9071
private __countrySetValue = (newValue: string) => {
9172
this.edit({ country: newValue, region: '', city: '' });
9273
this.edit({ apply_to_shipping: this.__isApplyToShippingHidden });
@@ -129,6 +110,18 @@ export class TaxForm extends Base<Data> {
129110

130111
get hiddenSelector(): BooleanSelector {
131112
const alwaysMatch = [super.hiddenSelector.toString()];
113+
const type = this.form.type as string | undefined;
114+
115+
if (type === 'global' || type === 'custom_tax_endpoint') {
116+
alwaysMatch.unshift('group-one:is-live', 'group-one:service-provider');
117+
if (type === 'custom_tax_endpoint') alwaysMatch.unshift('group-one:rate');
118+
} else {
119+
if (this.form.is_live) {
120+
alwaysMatch.unshift('group-one:rate');
121+
} else {
122+
alwaysMatch.unshift('group-one:service-provider');
123+
}
124+
}
132125

133126
if (this.__nativeIntegrationsUrl === void 0) alwaysMatch.unshift('native-integrations');
134127
if (this.__isCountryHidden) alwaysMatch.unshift('group-three:country');
@@ -137,8 +130,6 @@ export class TaxForm extends Base<Data> {
137130
}
138131

139132
if (this.__isCityHidden) alwaysMatch.unshift('group-three:city');
140-
if (this.__isProviderHidden) alwaysMatch.unshift('group-one:service-provider');
141-
if (this.__isRateHidden) alwaysMatch.unshift('group-one:rate');
142133
if (this.__isApplyToShippingHidden) alwaysMatch.unshift('group-two:apply-to-shipping');
143134
if (this.__isUseOriginRatesHidden) alwaysMatch.unshift('group-two:use-origin-rates');
144135
if (this.__isExemptAllCustomerTaxIdsHidden) {
@@ -172,12 +163,12 @@ export class TaxForm extends Base<Data> {
172163
>
173164
</foxy-internal-select-control>
174165
166+
<foxy-internal-switch-control infer="is-live"></foxy-internal-switch-control>
167+
175168
<foxy-internal-select-control
176169
options=${JSON.stringify(this.__serviceProviderOptions)}
177170
layout="summary-item"
178171
infer="service-provider"
179-
.getValue=${this.__serviceProviderGetValue}
180-
.setValue=${this.__serviceProviderSetValue}
181172
>
182173
</foxy-internal-select-control>
183174
@@ -252,7 +243,6 @@ export class TaxForm extends Base<Data> {
252243

253244
private get __serviceProviderOptions() {
254245
const options = [
255-
{ label: 'option_none', value: 'none' },
256246
{ label: 'option_avalara', value: 'avalara' },
257247
{ label: 'option_onesource', value: 'onesource' },
258248
];
@@ -334,11 +324,6 @@ export class TaxForm extends Base<Data> {
334324
return this.form.type !== 'union' || !this.form.is_live || !!this.form.service_provider;
335325
}
336326

337-
private get __isProviderHidden() {
338-
const type = this.form.type as string;
339-
return !type || type === 'global' || type === 'local' || type === 'custom_tax_endpoint';
340-
}
341-
342327
private get __isCountryHidden() {
343328
if (this.form.type === 'union') {
344329
return (!this.form.service_provider || this.form.is_live) && !this.form.use_origin_rates;
@@ -354,9 +339,4 @@ export class TaxForm extends Base<Data> {
354339
private get __isCityHidden() {
355340
return this.form.type !== 'local';
356341
}
357-
358-
private get __isRateHidden() {
359-
const type = this.form.type as string;
360-
return !type || type === 'custom_tax_endpoint' || this.form.is_live === true;
361-
}
362342
}

src/static/translations/tax-form/en.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@
3737
"option_local": "Local",
3838
"option_custom_tax_endpoint": "Custom tax endpoint"
3939
},
40+
"is-live": {
41+
"label": "Calculate tax automatically",
42+
"helper_text": "",
43+
"checked": "Yes",
44+
"unchecked": "No"
45+
},
4046
"service-provider": {
41-
"label": "Live rate provider",
47+
"label": "Service provider",
4248
"helper_text": "",
4349
"placeholder": "Select",
4450
"option_avalara": "Avalara AvaTax 15",
4551
"option_custom_tax": "Custom Tax Endpoint",
4652
"option_taxjar": "TaxJar",
4753
"option_onesource": "Thomson Reuters ONESOURCE",
48-
"option_none": "None",
49-
"option_default": "Default"
54+
"option_default": "Foxy Default (Thomson Reuters; others)"
5055
},
5156
"rate": {
5257
"label": "Fixed rate",

0 commit comments

Comments
 (0)