Skip to content

Commit

Permalink
fix tests to work with lightDOM
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Oct 16, 2024
1 parent 723f690 commit 0522049
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions test/sparql-editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("sparql-editor", () => {
></sparql-editor>
`;

const sparqlEditor = document.querySelector("sparql-editor") as HTMLElement & {shadowRoot: ShadowRoot};
const sparqlEditor = document.querySelector("sparql-editor") as HTMLElement;
await customElements.whenDefined("sparql-editor");
// Wait for the element to pull examples
await new Promise(resolve => setTimeout(resolve, 2000));
Expand All @@ -57,24 +57,21 @@ describe("sparql-editor", () => {
expect(sparqlEditor?.getAttribute("endpoint")).toBe("https://sparql.uniprot.org/sparql/");
expect(sparqlEditor?.getAttribute("examples-on-main-page")).toBe("10");

// Check shadow DOM
const shadowRoot = sparqlEditor.shadowRoot;
expect(shadowRoot).not.toBeNull();
expect(shadowRoot.querySelector("#sparql-editor")).toBeInTheDocument();
expect(shadowRoot.querySelector("#yasgui")).toBeInTheDocument();
// Check DOM
expect(sparqlEditor.querySelector("#yasgui")).toBeInTheDocument();

const button = shadowRoot.querySelector("#sparql-add-prefixes-btn") as HTMLButtonElement;
const button = sparqlEditor.querySelector("#sparql-add-prefixes-btn");
expect(button).toBeInTheDocument();
expect(button).toHaveTextContent("Add common prefixes");

// Check YASGUI components. Not working when ran inside GH actions
// const yasqeEditor = shadowRoot?.querySelectorAll(".yasqe");
// const yasqeEditor = sparqlEditor?.querySelectorAll(".yasqe");
// expect(yasqeEditor?.length).toBe(1);
// const yasrResult = shadowRoot?.querySelectorAll(".yasr");
// const yasrResult = sparqlEditor?.querySelectorAll(".yasr");
// expect(yasrResult?.length).toBe(1);

// Check examples pulled successfully
const examplesOnMainPage = shadowRoot?.querySelectorAll(".main-query-example");
const examplesOnMainPage = sparqlEditor.querySelectorAll(".main-query-example");
expect(examplesOnMainPage?.length).toBe(10);
});
});

0 comments on commit 0522049

Please sign in to comment.