import{state as checkoutState,dispose as disposeCheckout}from"..";import{getCheckout}from"../../checkouts/mutations";import{dispose}from"../../checkouts";describe("checkout store",(()=>{beforeEach((()=>{dispose(),disposeCheckout()})),describe("watchers",(()=>{it("syncs checkout object with checkout store",(()=>{checkoutState.formId=1,checkoutState.mode="test",checkoutState.checkout={id:"test"},expect(getCheckout(1,"test")).toEqual(checkoutState.checkout),expect(checkoutState.checkout).toEqual(getCheckout(1,"test"))}))})),describe("events",(()=>{it("emits scCheckoutInitiated event",(()=>{const e=jest.fn();window.addEventListener("scCheckoutInitiated",e),checkoutState.checkout={id:"test"},expect(e).toBeCalledTimes(0)})),it("emits scAddedToCart, scRemovedFromCart and scCartUpdated events",(()=>{const e=jest.fn();window.addEventListener("scAddedToCart",e);const t=jest.fn();window.addEventListener("scRemovedFromCart",t);const c=jest.fn();window.addEventListener("scCartUpdated",c),checkoutState.checkout={id:"test",line_items:{data:[{id:"test"}]}},expect(e).toBeCalledTimes(1),expect(t).toBeCalledTimes(0),expect(c).toBeCalledTimes(1),checkoutState.checkout={id:"test",line_items:{data:[]}},expect(e).toBeCalledTimes(1),expect(t).toBeCalledTimes(1),expect(c).toBeCalledTimes(2)})),it("emits scCheckoutCompleted, scOrderPaid and scTrialStarted events",(()=>{const e=jest.fn();window.addEventListener("scCheckoutCompleted",e);const t=jest.fn();window.addEventListener("scOrderPaid",t);const c=jest.fn();window.addEventListener("scTrialStarted",c),checkoutState.checkout={id:"test",status:"finalized"},expect(e).toBeCalledTimes(0),expect(t).toBeCalledTimes(0),checkoutState.checkout={id:"test",status:"finalized"},expect(e).toBeCalledTimes(0),expect(t).toBeCalledTimes(0),checkoutState.checkout={id:"test",status:"processing"},expect(e).toBeCalledTimes(1),expect(t).toBeCalledTimes(1),checkoutState.checkout={id:"test",status:"paid",line_items:{data:[{id:"test",price:{trial_duration_days:10}}]}},expect(c).toBeCalledTimes(1),expect(e).toBeCalledTimes(2),expect(t).toBeCalledTimes(2)}))}))}));