import{newSpecPage}from"@stencil/core/testing";import{ScVerificationCode}from"../sc-verification-code";describe("sc-verification-code",(()=>{it("renders",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"});expect(e.root).toMatchSnapshot()})),it("renders with total",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:'<sc-verification-code total="4"></sc-verification-code>'});expect(e.root).toMatchSnapshot()})),it("renders 6 code inputs by default",(async()=>{const e=(await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"})).root.querySelectorAll('input[id^="code-input-"]');expect(e.length).toBe(6)})),it("renders inputs with numeric inputmode and pattern",(async()=>{const e=(await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"})).root.querySelector("#code-input-0");expect(e.getAttribute("inputmode")).toBe("numeric"),expect(e.getAttribute("pattern")).toBe("[0-9]*")})),it("renders inputs with aria-labels",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"}),t=e.root.querySelector("#code-input-0");expect(t.getAttribute("aria-label")).toContain("1 of 6");const o=e.root.querySelector("#code-input-5");expect(o.getAttribute("aria-label")).toContain("6 of 6")})),it("advances focus on single character input",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"}),t=e.root.querySelector("#code-input-0"),o=e.root.querySelector("#code-input-1"),c=jest.spyOn(o,"focus");t.value="1",t.dispatchEvent(new Event("input")),await e.waitForChanges(),expect(c).toHaveBeenCalled()})),it("moves focus back on backspace",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"}),t=e.root.querySelector("#code-input-1"),o=e.root.querySelector("#code-input-0"),c=jest.spyOn(o,"focus");t.dispatchEvent(new KeyboardEvent("keydown",{key:"Backspace"})),await e.waitForChanges(),expect(c).toHaveBeenCalled()})),it("calls onChange when all inputs are filled",(async()=>{const e=jest.fn(),t=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"});t.rootInstance.onChange=e;for(let e=0;e<6;e++){const o=t.root.querySelector(`#code-input-${e}`);o.value=String(e+1),o.dispatchEvent(new Event("input",{bubbles:!0}))}await t.waitForChanges(),expect(e).toHaveBeenCalledWith("123456")})),it("resets all codes when reset is called",(async()=>{const e=await newSpecPage({components:[ScVerificationCode],html:"<sc-verification-code></sc-verification-code>"}),t=e.rootInstance;t.codes=["1","2","3","4","5","6"],t.reset(),await e.waitForChanges(),expect(t.codes).toEqual(["","","","","",""])}))}));