import{state as checkoutState,dispose as disposeCheckout}from"../../../../../src/store/checkout";import{dispose as disposeProcessors}from"../../../../../src/store/processors";describe("sc-stripe-payment-element",(()=>{beforeEach((()=>{disposeCheckout(),disposeProcessors()})),describe("maybeApplyFilters",(()=>{let e,t;const o=function(e){var t,o,a;return(null===(o=null===(t=null===window||void 0===window?void 0:window.wp)||void 0===t?void 0:t.hooks)||void 0===o?void 0:o.applyFilters)?{...e,paymentMethodOrder:window.wp.hooks.applyFilters("surecart_stripe_payment_element_payment_method_order",[],checkoutState.checkout),wallets:window.wp.hooks.applyFilters("surecart_stripe_payment_element_wallets",{},checkoutState.checkout),terms:window.wp.hooks.applyFilters("surecart_stripe_payment_element_terms",{},checkoutState.checkout),fields:window.wp.hooks.applyFilters("surecart_stripe_payment_element_fields",null!==(a=e.fields)&&void 0!==a?a:{})}:e};beforeEach((()=>{global.window||(global.window={}),t=global.window,global.window.wp=void 0,e=jest.fn()})),afterEach((()=>{global.window=t})),it("returns original options when window.wp is undefined",(()=>{const e={fields:{test:"value"},other:"data"},t=o(e);expect(t).toBe(e),expect(t).toEqual(e)})),it("returns original options when window.wp.hooks is undefined",(()=>{global.window.wp={};const e={fields:{test:"value"},other:"data"},t=o(e);expect(t).toBe(e),expect(t).toEqual(e)})),it("returns original options when window.wp.hooks.applyFilters is undefined",(()=>{global.window.wp={hooks:{}};const e={fields:{test:"value"},other:"data"},t=o(e);expect(t).toBe(e),expect(t).toEqual(e)})),it("applies filters when wp.hooks.applyFilters is available",(()=>{const t={id:"test-checkout"};checkoutState.checkout=t,e.mockImplementation(((e,t)=>{switch(e){case"surecart_stripe_payment_element_payment_method_order":return["card","paypal"];case"surecart_stripe_payment_element_wallets":return{applePay:"auto",googlePay:"auto"};case"surecart_stripe_payment_element_terms":return{card:"auto"};case"surecart_stripe_payment_element_fields":return{billingDetails:{email:"never"}};default:return t}})),global.window.wp={hooks:{applyFilters:e}};const a={fields:{test:"value"},other:"data"},s=o(a);expect(e).toHaveBeenCalledTimes(4),expect(e).toHaveBeenCalledWith("surecart_stripe_payment_element_payment_method_order",[],t),expect(e).toHaveBeenCalledWith("surecart_stripe_payment_element_wallets",{},t),expect(e).toHaveBeenCalledWith("surecart_stripe_payment_element_terms",{},t),expect(e).toHaveBeenCalledWith("surecart_stripe_payment_element_fields",{test:"value"}),expect(s).toEqual({fields:{billingDetails:{email:"never"}},other:"data",paymentMethodOrder:["card","paypal"],wallets:{applePay:"auto",googlePay:"auto"},terms:{card:"auto"}}),expect(a).toEqual({fields:{test:"value"},other:"data"}),expect(s).not.toBe(a)})),it("handles undefined options.fields gracefully",(()=>{checkoutState.checkout={},e.mockReturnValue({}),global.window.wp={hooks:{applyFilters:e}};const t=o({other:"data"});expect(e).toHaveBeenCalledWith("surecart_stripe_payment_element_fields",{}),expect(t).toHaveProperty("fields",{})})),it("preserves all original properties when applying filters",(()=>{checkoutState.checkout={},e.mockImplementation(((e,t)=>t)),global.window.wp={hooks:{applyFilters:e}};const t=o({fields:{test:"value"},existingProp1:"value1",existingProp2:{nested:"object"},existingProp3:[1,2,3]});expect(t.existingProp1).toBe("value1"),expect(t.existingProp2).toEqual({nested:"object"}),expect(t.existingProp3).toEqual([1,2,3]),expect(t).toHaveProperty("paymentMethodOrder"),expect(t).toHaveProperty("wallets"),expect(t).toHaveProperty("terms"),expect(t).toHaveProperty("fields")}))}))}));