Xml_Test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {IXmlElement} from "../../../src/Common/FileIO/Xml";
  2. import {TestUtils} from "../../Util/TestUtils";
  3. import {OpenSheetMusicDisplay} from "../../../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay";
  4. // Test XML simple document
  5. const xmlTestData: string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  6. <!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\">\
  7. <score-partwise> <identification> <encoding> <software>Example Software name</software> \
  8. <encoding-date>2016-04-04</encoding-date> </encoding> </identification> <credit page=\"1\"> \
  9. <credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit> </score-partwise>";
  10. describe("XML interface", () => {
  11. const parser: DOMParser = new DOMParser();
  12. const doc: Document = parser.parseFromString(xmlTestData, "text/xml");
  13. const documentElement: IXmlElement = new IXmlElement(doc.documentElement);
  14. // test all test files
  15. for (const score of TestUtils.XmlTestSet) {
  16. testFile(score);
  17. }
  18. // Generates a test for a mxl file name
  19. function testFile(scoreName: string): void {
  20. it(scoreName, (done: Mocha.Done) => {
  21. // Load the xml file content
  22. const score: Document = TestUtils.getScore(scoreName);
  23. const div: HTMLElement = document.createElement("div");
  24. const openSheetMusicDisplay: OpenSheetMusicDisplay =
  25. TestUtils.createOpenSheetMusicDisplay(div);
  26. openSheetMusicDisplay.load(score);
  27. done();
  28. }).timeout(30000);
  29. }
  30. it("test IXmlElement", (done: Mocha.Done) => {
  31. // Test name attribute
  32. chai.expect(documentElement.name).to.equal("score-partwise");
  33. // Test element method
  34. chai.should().exist(documentElement.element("identification"));
  35. // Test value attribute
  36. chai.expect(documentElement
  37. .element("identification")
  38. .element("encoding")
  39. .element("software").value).to.equal("Example Software name");
  40. done();
  41. });
  42. it("test IXmlAttribute", (done: Mocha.Done) => {
  43. // Test attributes method
  44. chai.expect(
  45. documentElement.element("credit").attributes()[0].name
  46. ).to.equal("page");
  47. const creditWords: IXmlElement =
  48. documentElement.element("credit").element("credit-words");
  49. // Test attributes method
  50. chai.expect(creditWords.attributes().length).to.equal(2);
  51. // Test value attribute
  52. chai.expect(creditWords.attribute("justify").value).to.equal("center");
  53. done();
  54. });
  55. });