jest.mock("@store/checkouts/store",(()=>({__esModule:!0,default:{state:{live:{},test:{}},set:jest.fn(),get:jest.fn(),onChange:jest.fn(),on:jest.fn(),dispose:jest.fn()},state:{live:{},test:{}},set:jest.fn(),get:jest.fn(),onChange:jest.fn(),on:jest.fn(),dispose:jest.fn()}))),jest.mock("@store/checkout",(()=>({state:{checkout:null,formId:null},onChange:jest.fn((()=>jest.fn()))}))),jest.mock("@store/checkout/getters",(()=>({fullShippingAddressRequired:jest.fn((()=>!1)),shippingAddressRequired:jest.fn((()=>!1))})));import{h}from"@stencil/core";import{newSpecPage}from"@stencil/core/testing";import{state as checkoutState}from"../../../../store/checkout/index";import{ScFormComponentsValidator}from"../sc-form-components-validator";import{ScCustomerName}from"../../../controllers/checkout-form/customer-name/sc-customer-name";import{ScOrderShippingAddress}from"../../../controllers/checkout-form/order-shipping-address/sc-order-shipping-address";import{shippingAddressRequired}from"../../../../store/checkout/getters";const mockShippingAddressRequired=shippingAddressRequired;describe("sc-form-components-validator",(()=>{beforeEach((()=>{checkoutState.checkout=null,checkoutState.formId=null,mockShippingAddressRequired.mockReturnValue(!1),jest.clearAllMocks()})),it("renders",(async()=>{const e=await newSpecPage({components:[ScFormComponentsValidator],html:"<sc-form-components-validator></sc-form-components-validator>"});expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("appends missing address field if required",(async()=>{mockShippingAddressRequired.mockReturnValue(!0);const e=await newSpecPage({components:[ScFormComponentsValidator],template:()=>h("sc-form-components-validator",{disabled:!1},h("sc-payment",null))});await e.waitForChanges(),checkoutState.checkout={tax_status:"address_invalid"},await e.waitForChanges(),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("appends missing tax id input if required",(async()=>{const e=await newSpecPage({components:[ScFormComponentsValidator],template:()=>h("sc-form-components-validator",{disabled:!1,taxProtocol:{tax_enabled:!0,eu_vat_required:!0}},h("sc-payment",null))});await e.waitForChanges(),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("appends missing trial line item if required",(async()=>{const e=await newSpecPage({components:[ScFormComponentsValidator],template:()=>h("sc-form-components-validator",{disabled:!1},h("sc-order-summary",null,h("sc-line-item-total",{total:"subtotal"})))});checkoutState.checkout={trial_amount:10},await e.waitForChanges(),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("appends missing address field with shipping address required",(async()=>{mockShippingAddressRequired.mockReturnValue(!0);const e=await newSpecPage({components:[ScFormComponentsValidator],template:()=>h("sc-form-components-validator",{disabled:!1},h("sc-payment",null))});checkoutState.checkout={shipping_address_required:!0},await e.waitForChanges(),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("requires the customer name on sc-customer-name if present in page and shipping address required",(async()=>{const e=await newSpecPage({components:[ScFormComponentsValidator,ScCustomerName,ScOrderShippingAddress],template:()=>h("sc-form-components-validator",{disabled:!1},h("sc-payment",null),h("sc-customer-name",null),h("sc-order-shipping-address",null))});await e.waitForChanges(),checkoutState.checkout={shipping_address_required:!0},await e.waitForChanges(),e.rootInstance.handleShippingAddressRequired(),await e.waitForChanges();const t=e.root.querySelector("sc-customer-name");expect(t.required).toBe(!0);const o=e.root.querySelector("sc-order-shipping-address");expect(o.required).toBe(!0),expect(!!o.requireName).toBe(!1),expect(!!o.showName).toBe(!1),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()})),it("requires the customer name on sc-order-shipping-address if shipping address is required",(async()=>{const e=await newSpecPage({components:[ScFormComponentsValidator,ScCustomerName,ScOrderShippingAddress],template:()=>h("sc-form-components-validator",{disabled:!1},h("sc-payment",null),h("sc-order-shipping-address",null))});await e.waitForChanges(),checkoutState.checkout={shipping_address_required:!0},await e.waitForChanges(),e.rootInstance.handleShippingAddressRequired(),await e.waitForChanges();const t=e.root.querySelector("sc-order-shipping-address");expect(t.required).toBe(!0),expect(t.requireName).toBe(!0),expect(t.showName).toBe(!0),expect(e.root).toMatchSnapshot(),e.rootInstance.disconnectedCallback()}))}));