TestUtils.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { OpenSheetMusicDisplay } from "../../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay";
  2. /**
  3. * This class collects useful methods to interact with test data.
  4. * During tests, XML and MXL documents are preprocessed by karma,
  5. * and this is some helper code to retrieve them.
  6. */
  7. export class TestUtils {
  8. public static getScore(name: string): Document {
  9. const path: string = "test/data/" + name;
  10. return ((window as any).__xml__)[path];
  11. }
  12. public static getMXL(scoreName: string): string {
  13. const path: string = "test/data/" + scoreName;
  14. return ((window as any).__raw__)[path];
  15. }
  16. public static getDivElement(document: Document): HTMLElement {
  17. const div: HTMLElement = document.createElement("div");
  18. const body: HTMLElement = document.getElementsByTagName("body")[0];
  19. body.appendChild(div);
  20. return div;
  21. }
  22. /**
  23. * Retrieve from a XML document the first element with name "score-partwise"
  24. * @param doc is the XML Document
  25. * @returns {Element}
  26. */
  27. public static getPartWiseElement(doc: Document): Element {
  28. const nodes: NodeList = doc.childNodes;
  29. for (let i: number = 0, length: number = nodes.length; i < length; i += 1) {
  30. const node: Node = nodes[i];
  31. if (node.nodeType === Node.ELEMENT_NODE && node.nodeName.toLowerCase() === "score-partwise") {
  32. return <Element>node;
  33. }
  34. }
  35. }
  36. public static createOpenSheetMusicDisplay(div: HTMLElement): OpenSheetMusicDisplay {
  37. return new OpenSheetMusicDisplay(div, {autoResize: false});
  38. }
  39. // Test all the following xml files:
  40. public static XmlTestSet: string[] = [
  41. "ActorPreludeSample.xml",
  42. "Beethoven_AnDieFerneGeliebte.xml",
  43. "CharlesGounod_Meditation.xml",
  44. "Debussy_Mandoline.xml",
  45. "Dichterliebe01.xml",
  46. "JohannSebastianBach_Air.xml",
  47. "JohannSebastianBach_PraeludiumInCDur_BWV846_1.xml",
  48. "JosephHaydn_ConcertanteCello.xml",
  49. "Mozart_AnChloe.xml",
  50. "Mozart_DasVeilchen.xml",
  51. "MuzioClementi_SonatinaOpus36No1_Part1.xml",
  52. "MuzioClementi_SonatinaOpus36No1_Part2.xml",
  53. "MuzioClementi_SonatinaOpus36No3_Part1.xml",
  54. "MuzioClementi_SonatinaOpus36No3_Part2.xml",
  55. "Saltarello.xml",
  56. "ScottJoplin_EliteSyncopations.xml",
  57. "ScottJoplin_The_Entertainer.xml",
  58. "TelemannWV40.102_Sonate-Nr.1.1-Dolce.xml",
  59. "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
  60. //"VariousChordTests.musicxml", // doesn't exist anymore
  61. ];
  62. }