import{newSpecPage}from"@stencil/core/testing";import{ScProductLineItem}from"../sc-product-line-item";const bundleComponent=(t,e,o,n=1)=>({id:t,quantity:n,variant_display_options:o,price:{product:{name:e}}});describe("sc-product-line-item",(()=>{it("renders",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});expect(t.root).toMatchSnapshot()})),it("renders bundle components in the details region and the note as a standalone note",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});t.root.note="Please gift wrap this order.",t.root.bundleComponents=[bundleComponent("c1","Sleeping Bag","10°C / Forest",1),bundleComponent("c2","Trail Tent","2-Person",2)],await t.waitForChanges();const e=t.root.shadowRoot.querySelector(".line-item-details");expect(e).toBeTruthy();const o=t.root.shadowRoot.querySelectorAll(".line-item-details__row");expect(o.length).toBe(2),expect(o[0].textContent).toContain("Sleeping Bag - 10°C / Forest"),expect(o[1].textContent).toContain("Trail Tent - 2-Person"),expect(o[1].textContent).toContain("× 2"),expect(t.root.shadowRoot.querySelector(".line-item-details__note")).toBeNull();const n=t.root.shadowRoot.querySelector("sc-product-line-item-note");expect(n).toBeTruthy(),expect(n.getAttribute("note")).toContain("Please gift wrap this order.")})),it("shows bundle items without a variant by default (name only)",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});t.root.bundleComponents=[bundleComponent("c1","Sleeping Bag","10°C / Forest",1),bundleComponent("c2","Camp Mug","",1)],await t.waitForChanges();const e=t.root.shadowRoot.querySelectorAll(".line-item-details__row");expect(e.length).toBe(2),expect(e[0].textContent).toContain("Sleeping Bag - 10°C / Forest"),expect(e[1].textContent).toContain("Camp Mug"),expect(e[1].textContent).not.toContain("Camp Mug -")})),it("hides bundle items without a variant when showAllBundleItems is false",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});t.root.showAllBundleItems=!1,t.root.bundleComponents=[bundleComponent("c1","Sleeping Bag","10°C / Forest",1),bundleComponent("c2","Camp Mug","",1)],await t.waitForChanges();const e=t.root.shadowRoot.querySelectorAll(".line-item-details__row");expect(e.length).toBe(1),expect(e[0].textContent).toContain("Sleeping Bag - 10°C / Forest")})),it("omits the details region when there is no bundle; a note alone renders standalone",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});t.root.note="Please gift wrap this order.",await t.waitForChanges(),expect(t.root.shadowRoot.querySelector(".line-item-details")).toBeNull(),expect(t.root.shadowRoot.querySelector("sc-product-line-item-note")).toBeTruthy()})),it("omits the meta row when there is no description or trial/fees content",(async()=>{const t=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});await t.waitForChanges(),expect(t.root.shadowRoot.querySelector('[part="description"]')).toBeNull(),expect(t.root.shadowRoot.querySelector('[part="trial-fees"]')).toBeNull()})),it("renders the meta row when variant or trial content is present",(async()=>{var t,e;const o=await newSpecPage({components:[ScProductLineItem],html:"<sc-product-line-item></sc-product-line-item>"});o.root.variant="Large / Blue",await o.waitForChanges(),expect(null===(t=o.root.shadowRoot.querySelector('[part="description"]'))||void 0===t?void 0:t.textContent).toContain("Large / Blue"),expect(o.root.shadowRoot.querySelector('[part="trial-fees"]')).toBeTruthy(),o.root.variant="",o.root.trial="7-day free trial",await o.waitForChanges(),expect(o.root.shadowRoot.querySelector('[part="description"]')).toBeTruthy(),expect(null===(e=o.root.shadowRoot.querySelector('[part="trial-fees"]'))||void 0===e?void 0:e.textContent).toContain("7-day free trial")}))}));