Mxl_Test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { IXmlElement } from "../../../src/Common/FileIO/Xml";
  2. import { TestUtils } from "../../Util/TestUtils";
  3. import { MXLHelper } from "../../../src/Common/FileIO/Mxl";
  4. describe("MXL Tests", () => {
  5. // Generates a test for a mxl file name
  6. function testFile(scoreName: string): void {
  7. it(scoreName, (done: MochaDone) => {
  8. // Load the xml file content
  9. let mxl: string = TestUtils.getMXL(scoreName);
  10. chai.expect(mxl).to.not.be.undefined;
  11. // Extract XML from MXL
  12. // Warning: the sheet is loaded asynchronously,
  13. // (with Promises), thus we need a little fix
  14. // in the end with 'then(null, done)' to
  15. // make Mocha work asynchronously
  16. MXLHelper.MXLtoIXmlElement(mxl).then(
  17. (score: IXmlElement) => {
  18. chai.expect(score).to.not.be.undefined;
  19. chai.expect(score.name).to.equal("score-partwise");
  20. done();
  21. },
  22. (exc: any) => { throw exc; }
  23. ).then(undefined, done);
  24. });
  25. }
  26. // Test all the following mxl files:
  27. let scores: string[] = [
  28. "MozartTrio.mxl",
  29. ];
  30. for (let score of scores) {
  31. testFile(score);
  32. }
  33. // Test failure
  34. it("Corrupted file", (done: MochaDone) => {
  35. MXLHelper.MXLtoIXmlElement("").then(
  36. (score: IXmlElement) => {
  37. chai.expect(score).to.not.be.undefined;
  38. chai.expect(score.name).to.equal("score-partwise");
  39. done(new Error("Empty zip file was loaded correctly. How is that even possible?"));
  40. },
  41. (exc: any) => { done(); }
  42. );
  43. });
  44. });