@justifi/webcomponents 4.10.0-rc.0 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{Business-79361c8a.js → Business-663db337.js} +12 -1
- package/dist/cjs/Identity-1c4528b8.js +49 -0
- package/dist/cjs/{SubAccount-b3902202.js → SubAccount-05867651.js} +1 -1
- package/dist/cjs/additional-questions-details_5.cjs.entry.js +2 -1
- package/dist/cjs/form-control-datepart_3.cjs.entry.js +38 -34
- package/dist/cjs/form-control-monetary.cjs.entry.js +19 -17
- package/dist/cjs/form-control-number_3.cjs.entry.js +6 -2
- package/dist/cjs/gross-payment-chart-core.cjs.entry.js +2 -1
- package/dist/cjs/justifi-additional-questions-form-step_5.cjs.entry.js +10 -9
- package/dist/cjs/justifi-additional-questions_4.cjs.entry.js +3 -1
- package/dist/cjs/justifi-billing-form_4.cjs.entry.js +3 -3
- package/dist/cjs/justifi-business-address-form-step.cjs.entry.js +1 -1
- package/dist/cjs/justifi-business-details.cjs.entry.js +3 -1
- package/dist/cjs/justifi-business-form.cjs.entry.js +4 -2
- package/dist/cjs/justifi-business-list.cjs.entry.js +3 -2
- package/dist/cjs/justifi-checkout-core.cjs.entry.js +5 -4
- package/dist/cjs/justifi-owner-form.cjs.entry.js +5 -3
- package/dist/cjs/justifi-payment-balance-transactions.cjs.entry.js +2 -1
- package/dist/cjs/justifi-payment-form.cjs.entry.js +2 -1
- package/dist/cjs/{justifi-business-form-stepped.cjs.entry.js → justifi-payment-provisioning.cjs.entry.js} +4 -4
- package/dist/cjs/justifi-proceeds-list.cjs.entry.js +2 -1
- package/dist/cjs/justifi-subaccount-details.cjs.entry.js +3 -2
- package/dist/cjs/justifi-subaccounts-list.cjs.entry.js +3 -2
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{payload-parsers-25ed3936.js → payload-parsers-9e72e80f.js} +3 -2
- package/dist/cjs/payment-details-core.cjs.entry.js +2 -1
- package/dist/cjs/payments-list-core.cjs.entry.js +2 -1
- package/dist/cjs/payout-details-core.cjs.entry.js +2 -1
- package/dist/cjs/payouts-list-core.cjs.entry.js +2 -1
- package/dist/cjs/subaccount-account-details_4.cjs.entry.js +2 -1
- package/dist/cjs/{utils-6f62f7a1.js → utils-2b9940e1.js} +7 -0
- package/dist/cjs/webcomponents.cjs.js +1 -1
- package/dist/collection/api/Business.js +10 -1
- package/dist/collection/collection-manifest.json +7 -7
- package/dist/collection/components/billing-form/billing-form.js +1 -1
- package/dist/collection/components/business-details/additional-questions-details/additional-questions-details.js +4 -4
- package/dist/collection/components/business-forms/business-form/business-address/business-address-form.js +1 -1
- package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/additional-questions/business-additional-questions-form-step.js +3 -2
- package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-address/business-address-form-step.js +1 -1
- package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-representative/business-representative-form-step.js +3 -2
- package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/legal-address-form/legal-address-form-step.js +2 -1
- package/dist/collection/components/business-forms/{business-form-stepped/business-form-stepped.js → payment-provisioning/payment-provisioning.js} +4 -4
- package/dist/collection/components/business-forms/payment-provisioning/test/payment-provisioning.spec.js +61 -0
- package/dist/collection/components/business-forms/schemas/business-address-schema.js +3 -2
- package/dist/collection/components/checkout/checkout-core.js +4 -4
- package/dist/collection/components/form/form-control-datepart.js +39 -34
- package/dist/collection/components/form/form-control-monetary.js +22 -20
- package/dist/collection/components/form/form-control-number.js +1 -0
- package/dist/collection/components/form/form-control-select.js +3 -1
- package/dist/collection/components/form/form-control-text.js +2 -1
- package/dist/collection/components/form/test/form-control-datepart.spec.js +88 -0
- package/dist/collection/components/form/test/form-control-monetary.spec.js +69 -0
- package/dist/collection/components/form/test/form-control-number.spec.js +77 -0
- package/dist/collection/components/form/test/form-control-select.spec.js +84 -0
- package/dist/collection/components/form/test/form-control-text.spec.js +104 -0
- package/dist/collection/components/form/test/form.spec.js +60 -0
- package/dist/collection/utils/utils.js +5 -0
- package/dist/docs.json +231 -230
- package/dist/esm/{Business-1df362e0.js → Business-6cc4e473.js} +12 -2
- package/dist/esm/Identity-5f8f916f.js +46 -0
- package/dist/esm/{SubAccount-f4ae9809.js → SubAccount-61ac70eb.js} +1 -1
- package/dist/esm/additional-questions-details_5.entry.js +2 -1
- package/dist/esm/form-control-datepart_3.entry.js +38 -34
- package/dist/esm/form-control-monetary.entry.js +19 -17
- package/dist/esm/form-control-number_3.entry.js +6 -2
- package/dist/esm/gross-payment-chart-core.entry.js +2 -1
- package/dist/esm/justifi-additional-questions-form-step_5.entry.js +10 -9
- package/dist/esm/justifi-additional-questions_4.entry.js +3 -1
- package/dist/esm/justifi-billing-form_4.entry.js +3 -3
- package/dist/esm/justifi-business-address-form-step.entry.js +1 -1
- package/dist/esm/justifi-business-details.entry.js +3 -1
- package/dist/esm/justifi-business-form.entry.js +4 -2
- package/dist/esm/justifi-business-list.entry.js +3 -2
- package/dist/esm/justifi-checkout-core.entry.js +5 -4
- package/dist/esm/justifi-owner-form.entry.js +5 -3
- package/dist/esm/justifi-payment-balance-transactions.entry.js +2 -1
- package/dist/esm/justifi-payment-form.entry.js +2 -1
- package/dist/esm/{justifi-business-form-stepped.entry.js → justifi-payment-provisioning.entry.js} +4 -4
- package/dist/esm/justifi-proceeds-list.entry.js +2 -1
- package/dist/esm/justifi-subaccount-details.entry.js +3 -2
- package/dist/esm/justifi-subaccounts-list.entry.js +3 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{payload-parsers-1dd7474f.js → payload-parsers-caea809d.js} +3 -2
- package/dist/esm/payment-details-core.entry.js +2 -1
- package/dist/esm/payments-list-core.entry.js +2 -1
- package/dist/esm/payout-details-core.entry.js +2 -1
- package/dist/esm/payouts-list-core.entry.js +2 -1
- package/dist/esm/subaccount-account-details_4.entry.js +2 -1
- package/dist/esm/{utils-243abdb4.js → utils-d9e90399.js} +7 -1
- package/dist/esm/webcomponents.js +1 -1
- package/dist/module/Business.js +12 -2
- package/dist/module/Identity.js +46 -0
- package/dist/module/SubAccount.js +1 -1
- package/dist/module/business-additional-questions-form-step.js +3 -2
- package/dist/module/business-address-schema.js +3 -2
- package/dist/module/business-owners-form-step.js +2 -1
- package/dist/module/business-representative-form-step.js +3 -2
- package/dist/module/checkout-core.js +4 -4
- package/dist/module/form-control-datepart2.js +37 -33
- package/dist/module/form-control-monetary2.js +20 -18
- package/dist/module/form-control-number2.js +1 -0
- package/dist/module/form-control-select2.js +3 -1
- package/dist/module/form-control-text2.js +2 -1
- package/dist/module/justifi-payment-balance-transactions.js +1 -1
- package/dist/module/justifi-payment-provisioning.d.ts +11 -0
- package/dist/module/{justifi-business-form-stepped.js → justifi-payment-provisioning.js} +9 -9
- package/dist/module/justifi-subaccount-details.js +1 -1
- package/dist/module/justifi-subaccounts-list.js +1 -1
- package/dist/module/legal-address-form-step.js +3 -2
- package/dist/module/owner-form.js +2 -24
- package/dist/module/payment-details-core2.js +1 -1
- package/dist/module/payment-method-form.js +1 -1
- package/dist/module/payments-list-core2.js +1 -1
- package/dist/module/payout-details-core2.js +1 -1
- package/dist/module/payouts-list-core2.js +1 -1
- package/dist/module/subaccount-merchant-details2.js +1 -1
- package/dist/module/utils2.js +7 -1
- package/dist/types/api/Business.d.ts +10 -3
- package/dist/types/components/business-details/additional-questions-details/additional-questions-details.d.ts +2 -2
- package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/additional-questions/business-additional-questions-form-step.d.ts +2 -1
- package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/business-representative/business-representative-form-step.d.ts +2 -1
- package/dist/types/components/business-forms/{business-form-stepped/business-form-stepped.d.ts → payment-provisioning/payment-provisioning.d.ts} +1 -1
- package/dist/types/components/form/form-control-datepart.d.ts +2 -1
- package/dist/types/components/form/form-control-monetary.d.ts +2 -1
- package/dist/types/components.d.ts +63 -63
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/webcomponents/p-03b1d0d5.entry.js +1 -0
- package/dist/webcomponents/p-0e189d6a.entry.js +1 -0
- package/dist/webcomponents/p-16dcf053.entry.js +1 -0
- package/dist/webcomponents/p-221b9504.entry.js +1 -0
- package/dist/webcomponents/p-2df32b4a.entry.js +1 -0
- package/dist/webcomponents/p-38ba2848.entry.js +1 -0
- package/dist/webcomponents/p-3d4aaa4a.entry.js +1 -0
- package/dist/webcomponents/p-41870765.entry.js +1 -0
- package/dist/webcomponents/p-461f42b8.entry.js +1 -0
- package/dist/webcomponents/p-48c2400e.js +1 -0
- package/dist/webcomponents/p-491ca87f.js +1 -0
- package/dist/webcomponents/p-60714f2a.entry.js +1 -0
- package/dist/webcomponents/p-60b2344a.js +1 -0
- package/dist/webcomponents/{p-fe2af0cf.entry.js → p-65500b31.entry.js} +1 -1
- package/dist/webcomponents/p-6d39b8bc.entry.js +1 -0
- package/dist/webcomponents/{p-9ce8d98c.entry.js → p-7ec301b5.entry.js} +1 -1
- package/dist/webcomponents/p-817211f2.entry.js +1 -0
- package/dist/webcomponents/{p-65510838.js → p-8482c23f.js} +1 -1
- package/dist/webcomponents/p-a4122c35.entry.js +1 -0
- package/dist/webcomponents/{p-c8d62072.entry.js → p-a68519e5.entry.js} +1 -1
- package/dist/webcomponents/p-af8363a1.entry.js +1 -0
- package/dist/webcomponents/p-b37d6888.entry.js +1 -0
- package/dist/webcomponents/p-b5a3bf86.entry.js +1 -0
- package/dist/webcomponents/p-cb8f9cb8.entry.js +1 -0
- package/dist/webcomponents/{p-0811bc77.entry.js → p-d0761829.entry.js} +1 -1
- package/dist/webcomponents/p-dbe32e75.entry.js +1 -0
- package/dist/webcomponents/p-e0c1cba8.js +1 -0
- package/dist/webcomponents/p-ea03b424.entry.js +1 -0
- package/dist/webcomponents/p-ec230480.entry.js +1 -0
- package/dist/webcomponents/{p-583dd5a2.entry.js → p-eed5f4ad.entry.js} +1 -1
- package/dist/webcomponents/webcomponents.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/Identity-b6364aee.js +0 -27
- package/dist/collection/components/business-forms/business-form-stepped/test/business-form-stepped.spec.js +0 -61
- package/dist/esm/Identity-774788c0.js +0 -25
- package/dist/module/justifi-business-form-stepped.d.ts +0 -11
- package/dist/webcomponents/p-0399f02b.entry.js +0 -1
- package/dist/webcomponents/p-04a98c63.js +0 -1
- package/dist/webcomponents/p-06888c2e.entry.js +0 -1
- package/dist/webcomponents/p-17f64853.entry.js +0 -1
- package/dist/webcomponents/p-22085999.entry.js +0 -1
- package/dist/webcomponents/p-252835df.entry.js +0 -1
- package/dist/webcomponents/p-28b38699.js +0 -1
- package/dist/webcomponents/p-374c44e6.entry.js +0 -1
- package/dist/webcomponents/p-4697ccfa.entry.js +0 -1
- package/dist/webcomponents/p-4781cd06.js +0 -1
- package/dist/webcomponents/p-4d806131.entry.js +0 -1
- package/dist/webcomponents/p-4e0b3206.entry.js +0 -1
- package/dist/webcomponents/p-5da4fbe7.entry.js +0 -1
- package/dist/webcomponents/p-6103c20d.entry.js +0 -1
- package/dist/webcomponents/p-7654c70d.entry.js +0 -1
- package/dist/webcomponents/p-847441ce.entry.js +0 -1
- package/dist/webcomponents/p-861ba3fc.entry.js +0 -1
- package/dist/webcomponents/p-a98eea84.entry.js +0 -1
- package/dist/webcomponents/p-b27c9b0d.entry.js +0 -1
- package/dist/webcomponents/p-e3748ea4.entry.js +0 -1
- package/dist/webcomponents/p-eef5ed19.entry.js +0 -1
- package/dist/webcomponents/p-efc7025c.entry.js +0 -1
- package/dist/webcomponents/p-f3453ca2.js +0 -1
- package/dist/webcomponents/p-f3ca6fda.entry.js +0 -1
- /package/dist/cjs/{state-options-96d05a98.js → state-options-4fbcb48a.js} +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/additional-questions/test/business-additional-questions-form-step.spec.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-address/business-address-form-step.css +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-address/test/business-address-form-step.spec.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-core-info/business-core-info-form-step.css +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-core-info/business-core-info-form-step.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-core-info/test/business-core-info-form-step.spec.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-owners/business-owners-form-step.css +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-owners/business-owners-form-step.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-owners/test/business-owners-form-step.spec.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-representative/business-representative-form-step.css +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/business-representative/test/business-representative-form-step.spec.js +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped → payment-provisioning}/legal-address-form/legal-address-form-step.css +0 -0
- /package/dist/collection/components/business-forms/{business-form-stepped/business-form-stepped.css → payment-provisioning/payment-provisioning.css} +0 -0
- /package/dist/collection/{components/billing-form → utils}/state-options.js +0 -0
- /package/dist/esm/{state-options-fc1daf67.js → state-options-a356fb11.js} +0 -0
- /package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/business-address/business-address-form-step.d.ts +0 -0
- /package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/business-core-info/business-core-info-form-step.d.ts +0 -0
- /package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/business-owners/business-owners-form-step.d.ts +0 -0
- /package/dist/types/components/business-forms/{business-form-stepped → payment-provisioning}/legal-address-form/legal-address-form-step.d.ts +0 -0
- /package/dist/types/{components/billing-form → utils}/state-options.d.ts +0 -0
- /package/dist/webcomponents/{p-8e2a88a8.js → p-6078a370.js} +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { newSpecPage } from "@stencil/core/testing";
|
|
2
|
+
import { TextInput } from "../form-control-text";
|
|
3
|
+
describe('form-control-text', () => {
|
|
4
|
+
// Test 1: Initial Rendering and Props
|
|
5
|
+
it('renders with default props', async () => {
|
|
6
|
+
const page = await newSpecPage({
|
|
7
|
+
components: [TextInput],
|
|
8
|
+
html: `<form-control-text label="Username" name="username"></form-control-text>`,
|
|
9
|
+
});
|
|
10
|
+
expect(page.root).toMatchSnapshot();
|
|
11
|
+
expect(page.rootInstance.label).toBe('Username');
|
|
12
|
+
expect(page.rootInstance.name).toBe('username');
|
|
13
|
+
});
|
|
14
|
+
// Test 2: Rendering with all props
|
|
15
|
+
it('renders with all props provided', async () => {
|
|
16
|
+
const page = await newSpecPage({
|
|
17
|
+
components: [TextInput],
|
|
18
|
+
html: `
|
|
19
|
+
<form-control-text
|
|
20
|
+
label="Email"
|
|
21
|
+
name="email"
|
|
22
|
+
default-value="user@example.com"
|
|
23
|
+
error="Invalid email"
|
|
24
|
+
disabled
|
|
25
|
+
></form-control-text>
|
|
26
|
+
`,
|
|
27
|
+
});
|
|
28
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
29
|
+
expect(page.rootInstance.label).toBe('Email');
|
|
30
|
+
expect(inputElement.value).toBe('user@example.com');
|
|
31
|
+
expect(inputElement.disabled).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
// Test 3: Handle Default Value Changes
|
|
34
|
+
it('updates input value on defaultValue prop change', async () => {
|
|
35
|
+
const page = await newSpecPage({
|
|
36
|
+
components: [TextInput],
|
|
37
|
+
html: `<form-control-text default-value="initial"></form-control-text>`,
|
|
38
|
+
});
|
|
39
|
+
page.rootInstance.defaultValue = 'updated';
|
|
40
|
+
await page.waitForChanges();
|
|
41
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
42
|
+
expect(inputElement.value).toBe('updated');
|
|
43
|
+
});
|
|
44
|
+
// Test 4: User Interaction - Input
|
|
45
|
+
it('handles user input correctly', async () => {
|
|
46
|
+
const page = await newSpecPage({
|
|
47
|
+
components: [TextInput],
|
|
48
|
+
html: `<form-control-text></form-control-text>`,
|
|
49
|
+
});
|
|
50
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
51
|
+
const testValue = 'Hello, World!';
|
|
52
|
+
inputElement.value = testValue;
|
|
53
|
+
await inputElement.dispatchEvent(new Event('input'));
|
|
54
|
+
expect(inputElement.value).toBe(testValue);
|
|
55
|
+
});
|
|
56
|
+
// Test 5: Event Emission on Input
|
|
57
|
+
it('emits formControlInput event on input', async () => {
|
|
58
|
+
const page = await newSpecPage({
|
|
59
|
+
components: [TextInput],
|
|
60
|
+
html: `<form-control-text></form-control-text>`,
|
|
61
|
+
});
|
|
62
|
+
// Set a mock inputHandler to prevent it from being undefined
|
|
63
|
+
page.rootInstance.inputHandler = jest.fn();
|
|
64
|
+
const inputEventSpy = jest.fn();
|
|
65
|
+
page.root.addEventListener('formControlInput', inputEventSpy);
|
|
66
|
+
await page.waitForChanges();
|
|
67
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
68
|
+
inputElement.value = 'Hello, World!';
|
|
69
|
+
inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
70
|
+
await page.waitForChanges();
|
|
71
|
+
expect(inputEventSpy).toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
// Test 6: Event Emission on Blur
|
|
74
|
+
it('emits formControlBlur event on blur', async () => {
|
|
75
|
+
const page = await newSpecPage({
|
|
76
|
+
components: [TextInput],
|
|
77
|
+
html: `<form-control-text></form-control-text>`,
|
|
78
|
+
});
|
|
79
|
+
const blurEventSpy = jest.fn();
|
|
80
|
+
page.win.addEventListener('formControlBlur', blurEventSpy);
|
|
81
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
82
|
+
inputElement.dispatchEvent(new Event('blur'));
|
|
83
|
+
expect(blurEventSpy).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
// Test 7: Disabled Prop
|
|
86
|
+
it('disables input when disabled prop is true', async () => {
|
|
87
|
+
const page = await newSpecPage({
|
|
88
|
+
components: [TextInput],
|
|
89
|
+
html: `<form-control-text disabled></form-control-text>`,
|
|
90
|
+
});
|
|
91
|
+
const inputElement = page.root.shadowRoot.querySelector('input');
|
|
92
|
+
expect(inputElement.disabled).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
// Test 8: Error Prop
|
|
95
|
+
it('shows error and applies error styling when error prop is provided', async () => {
|
|
96
|
+
const page = await newSpecPage({
|
|
97
|
+
components: [TextInput],
|
|
98
|
+
html: `<form-control-text error="This field is required."></form-control-text>`,
|
|
99
|
+
});
|
|
100
|
+
const shadowRoot = page.root.shadowRoot;
|
|
101
|
+
expect(shadowRoot.querySelector('.invalid-feedback').textContent).toBe('This field is required.');
|
|
102
|
+
expect(shadowRoot.querySelector('.form-control').classList.contains('is-invalid')).toBeTruthy();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as yup from "yup";
|
|
2
|
+
import { FormController } from "../form";
|
|
3
|
+
describe('FormController', () => {
|
|
4
|
+
let formController;
|
|
5
|
+
const mockSchema = yup.object().shape({
|
|
6
|
+
name: yup.string().required(),
|
|
7
|
+
email: yup.string().email().required(),
|
|
8
|
+
});
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
formController = new FormController(mockSchema);
|
|
11
|
+
});
|
|
12
|
+
it('should initialize with default empty values and errors', () => {
|
|
13
|
+
expect(formController.values.getValue()).toEqual({});
|
|
14
|
+
expect(formController.errors.getValue()).toEqual({});
|
|
15
|
+
});
|
|
16
|
+
it('should set initial values correctly', () => {
|
|
17
|
+
const initialValues = { name: 'John', email: 'john@example.com' };
|
|
18
|
+
formController.setInitialValues(initialValues);
|
|
19
|
+
expect(formController.values.getValue()).toEqual(initialValues);
|
|
20
|
+
});
|
|
21
|
+
it('should update values correctly', async () => {
|
|
22
|
+
const updateValues = { name: 'Jane' };
|
|
23
|
+
formController.setInitialValues({
|
|
24
|
+
name: 'John',
|
|
25
|
+
email: 'john@example.com',
|
|
26
|
+
});
|
|
27
|
+
formController.setValues(updateValues);
|
|
28
|
+
expect(formController.values.getValue()).toEqual({
|
|
29
|
+
name: 'Jane',
|
|
30
|
+
email: 'john@example.com',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it('should reset values to initial values', () => {
|
|
34
|
+
const initialValues = { name: 'John', email: 'john@example.com' };
|
|
35
|
+
formController.setInitialValues(initialValues);
|
|
36
|
+
formController.setValues({ name: 'Jane' }); // Update values
|
|
37
|
+
formController.resetValues(); // Reset to initial values
|
|
38
|
+
expect(formController.values.getValue()).toEqual(initialValues);
|
|
39
|
+
});
|
|
40
|
+
it('should validate and set errors correctly for invalid data', async () => {
|
|
41
|
+
formController.setValues({ email: 'invalid-email' }); // Set invalid email
|
|
42
|
+
await formController.validateAndSubmit(() => null);
|
|
43
|
+
expect(formController.errors.getValue()).toHaveProperty('email');
|
|
44
|
+
});
|
|
45
|
+
it('should call submit handler on valid data', async () => {
|
|
46
|
+
const submitHandlerMock = jest.fn();
|
|
47
|
+
formController.setInitialValues({
|
|
48
|
+
name: 'John',
|
|
49
|
+
email: 'john@example.com',
|
|
50
|
+
});
|
|
51
|
+
await formController.validateAndSubmit(submitHandlerMock);
|
|
52
|
+
expect(submitHandlerMock).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
it('should not call submit handler on invalid data', async () => {
|
|
55
|
+
const submitHandlerMock = jest.fn();
|
|
56
|
+
formController.setValues({ email: 'invalid-email' }); // Set invalid email
|
|
57
|
+
await formController.validateAndSubmit(submitHandlerMock);
|
|
58
|
+
expect(submitHandlerMock).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { format } from "date-fns";
|
|
2
2
|
import Dinero from "dinero.js";
|
|
3
|
+
import StateOptions from "./state-options";
|
|
3
4
|
export const RegExZip = /^\d{5}/;
|
|
4
5
|
export function formatCurrency(amount, withSymbol = true) {
|
|
5
6
|
if (!amount)
|
|
@@ -203,3 +204,7 @@ export async function loadFontsOnParent() {
|
|
|
203
204
|
export function isEmptyObject(obj) {
|
|
204
205
|
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
205
206
|
}
|
|
207
|
+
export function getStateAbbreviation(stateName) {
|
|
208
|
+
const state = StateOptions.find(s => s.label === stateName);
|
|
209
|
+
return state ? state.value : stateName;
|
|
210
|
+
}
|