import{newSpecPage}from"@stencil/core/testing";import{ScOrderSummary}from"../sc-order-summary";import{h}from"@stencil/core";import{state as checkoutStore,dispose}from"../../../../../store/checkout/index";function mockBodyRects(e=1e3,o=1e4){const t={x:0,y:0,width:e,height:o,top:0,right:e,bottom:o,left:0};document.body.getClientRects=jest.fn((()=>({item:()=>({...t,toJSON:()=>t}),length:1,[Symbol.iterator]:jest.fn()})))}describe("sc-order-summary",(()=>{beforeEach((()=>{mockBodyRects(),dispose()})),it("renders",(async()=>{const e=await newSpecPage({components:[ScOrderSummary],html:"<sc-order-summary></sc-order-summary>"});expect(e.root).toMatchSnapshot()})),it("renders scratch price if no trial has total savings amount",(async()=>{checkoutStore.checkout={amount_due:1e3,total_amount:1e3,total_savings_amount:-100};const e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsed:!0})});expect(e.root).toMatchSnapshot()})),it("does not render scratch price amount_due is different than total_amount",(async()=>{const e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{order:{scratch_amount:1e3,total_amount:2e3,total_savings_amount:-100},collapsible:!0,collapsed:!0})});expect(e.root).toMatchSnapshot()})),it("should render when collapsible, collapsed on desktop and collapsed in mobile",(async()=>{let e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnDesktop:!0,collapsedOnMobile:!0})});expect(e.root).toMatchSnapshot(),mockBodyRects(500,500),e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnDesktop:!0,collapsedOnMobile:!0})}),expect(e.root).toMatchSnapshot()})),it("should render when collapsible, collapsed on desktop and not collapsed in mobile",(async()=>{let e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnDesktop:!0})});expect(e.root).toMatchSnapshot(),mockBodyRects(500,500),e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnDesktop:!0})}),expect(e.root).toMatchSnapshot()})),it("should render when collapsible, not collapsed on desktop and collapsed in mobile",(async()=>{let e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnMobile:!0})});expect(e.root).toMatchSnapshot(),mockBodyRects(500,500),e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0,collapsedOnMobile:!0})}),expect(e.root).toMatchSnapshot()})),it("should render when collapsible, not collapsed on desktop and not collapsed in mobile",(async()=>{let e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0})});expect(e.root).toMatchSnapshot(),mockBodyRects(500,500),e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",{collapsible:!0})}),expect(e.root).toMatchSnapshot()})),it("should render when not collapsible",(async()=>{let e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",null)});expect(e.root).toMatchSnapshot(),mockBodyRects(500,500),e=await newSpecPage({components:[ScOrderSummary],template:()=>h("sc-order-summary",null)}),expect(e.root).toMatchSnapshot()}))}));