TestUtils.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * This class collects useful methods to interact with test data.
  3. * During tests, XML and MXL documents are preprocessed by karma,
  4. * and this is some helper code to retrieve them.
  5. */
  6. export class TestUtils {
  7. public static getScore(name: string): Document {
  8. const path: string = "test/data/" + name;
  9. return ((window as any).__xml__)[path];
  10. }
  11. public static getMXL(scoreName: string): string {
  12. const path: string = "test/data/" + scoreName;
  13. return ((window as any).__raw__)[path];
  14. }
  15. public static getDivElement(document: Document): HTMLElement {
  16. const div: HTMLElement = document.createElement("div");
  17. const body: HTMLElement = document.getElementsByTagName("body")[0];
  18. body.appendChild(div);
  19. return div;
  20. }
  21. /**
  22. * Retrieve from a XML document the first element with name "score-partwise"
  23. * @param doc is the XML Document
  24. * @returns {Element}
  25. */
  26. public static getPartWiseElement(doc: Document): Element {
  27. const nodes: NodeList = doc.childNodes;
  28. for (let i: number = 0, length: number = nodes.length; i < length; i += 1) {
  29. const node: Node = nodes[i];
  30. if (node.nodeType === Node.ELEMENT_NODE && node.nodeName.toLowerCase() === "score-partwise") {
  31. return <Element>node;
  32. }
  33. }
  34. }
  35. }