TestUtils.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. /**
  16. * Retrieve from a XML document the first element with name "score-partwise"
  17. * @param doc is the XML Document
  18. * @returns {Element}
  19. */
  20. public static getPartWiseElement(doc: Document): Element {
  21. const nodes: NodeList = doc.childNodes;
  22. for (let i: number = 0, length: number = nodes.length; i < length; i += 1) {
  23. const node: Node = nodes[i];
  24. if (node.nodeType === Node.ELEMENT_NODE && node.nodeName.toLowerCase() === "score-partwise") {
  25. return <Element>node;
  26. }
  27. }
  28. }
  29. }