|
| 1 | +const saveMxmlOutput = require("../mxml"); |
| 2 | + |
| 3 | +describe("saveMxmlOutput", () => { |
| 4 | + it("should return a valid XML string for a basic input", () => { |
| 5 | + const logo = { |
| 6 | + notation: { |
| 7 | + notationStaging: { |
| 8 | + "0": [ |
| 9 | + [["C"], 4, 0], |
| 10 | + ], |
| 11 | + "1": [] |
| 12 | + } |
| 13 | + } |
| 14 | + }; |
| 15 | + |
| 16 | + const output = saveMxmlOutput(logo); |
| 17 | + |
| 18 | + expect(output).toContain("<?xml version='1.0' encoding='UTF-8'?>"); |
| 19 | + expect(output).toContain("<score-partwise version=\"3.1\">"); |
| 20 | + expect(output).toContain("<part-list>"); |
| 21 | + expect(output).toContain("<score-part id=\"P1\">"); |
| 22 | + expect(output).toContain("<part id=\"P1\">"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should handle multiple voices", () => { |
| 26 | + const logo = { |
| 27 | + notation: { |
| 28 | + notationStaging: { |
| 29 | + "0": [ |
| 30 | + [["C"], 4, 0], |
| 31 | + [["D"], 4, 0] |
| 32 | + ], |
| 33 | + "1": [ |
| 34 | + [["E"], 4, 0], |
| 35 | + [["F"], 4, 0] |
| 36 | + ] |
| 37 | + } |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + const output = saveMxmlOutput(logo); |
| 42 | + |
| 43 | + expect(output).toContain("<score-part id=\"P1\">"); |
| 44 | + expect(output).toContain("<score-part id=\"P2\">"); |
| 45 | + expect(output).toContain("<part id=\"P1\">"); |
| 46 | + expect(output).toContain("<part id=\"P2\">"); |
| 47 | + expect(output).toContain("<step>C</step>"); |
| 48 | + expect(output).toContain("<step>E</step>"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should ignore specified elements", () => { |
| 52 | + const logo = { |
| 53 | + notation: { |
| 54 | + notationStaging: { |
| 55 | + "0": [ |
| 56 | + "voice one", |
| 57 | + [["C"], 4, 0], |
| 58 | + "voice two" |
| 59 | + ] |
| 60 | + } |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + const output = saveMxmlOutput(logo); |
| 65 | + |
| 66 | + expect(output).not.toContain("voice one"); |
| 67 | + expect(output).not.toContain("voice two"); |
| 68 | + expect(output).toContain("<step>C</step>"); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should handle tempo changes", () => { |
| 72 | + const logo = { |
| 73 | + notation: { |
| 74 | + notationStaging: { |
| 75 | + "0": [ |
| 76 | + "tempo", 120, 4, |
| 77 | + [["C"], 4, 0] |
| 78 | + ] |
| 79 | + } |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + const output = saveMxmlOutput(logo); |
| 84 | + |
| 85 | + expect(output).toContain("<sound tempo=\"120\"/>"); |
| 86 | + expect(output).toContain("<step>C</step>"); |
| 87 | + }); |
| 88 | + |
| 89 | + it("should handle meter changes", () => { |
| 90 | + const logo = { |
| 91 | + notation: { |
| 92 | + notationStaging: { |
| 93 | + "0": [ |
| 94 | + "meter", 3, 4, |
| 95 | + [["C"], 4, 0] |
| 96 | + ] |
| 97 | + } |
| 98 | + } |
| 99 | + }; |
| 100 | + |
| 101 | + const output = saveMxmlOutput(logo); |
| 102 | + |
| 103 | + expect(output).toContain("<time>"); |
| 104 | + expect(output).toContain("<beat-type>4</beat-type>"); |
| 105 | + expect(output).toContain("<step>C</step>"); |
| 106 | + }); |
| 107 | + |
| 108 | + it("should handle crescendo and decrescendo markings", () => { |
| 109 | + const logo = { |
| 110 | + notation: { |
| 111 | + notationStaging: { |
| 112 | + "0": [ |
| 113 | + "begin crescendo", |
| 114 | + [["C"], 4, 0], |
| 115 | + "end crescendo", |
| 116 | + "begin decrescendo", |
| 117 | + [["D"], 4, 0], |
| 118 | + "end decrescendo" |
| 119 | + ] |
| 120 | + } |
| 121 | + } |
| 122 | + }; |
| 123 | + |
| 124 | + const output = saveMxmlOutput(logo); |
| 125 | + |
| 126 | + expect(output).toContain('<wedge type="crescendo"/>'); |
| 127 | + expect(output).toContain('<wedge type="diminuendo"/>'); |
| 128 | + expect(output).toContain('<wedge type="stop"/>'); |
| 129 | + expect(output).toContain("<step>C</step>"); |
| 130 | + expect(output).toContain("<step>D</step>"); |
| 131 | + }); |
| 132 | + |
| 133 | + it("should handle tied notes", () => { |
| 134 | + const logo = { |
| 135 | + notation: { |
| 136 | + notationStaging: { |
| 137 | + "0": [ |
| 138 | + [["C"], 4, 0], |
| 139 | + "tie", |
| 140 | + [["C"], 4, 0] |
| 141 | + ] |
| 142 | + } |
| 143 | + } |
| 144 | + }; |
| 145 | + |
| 146 | + const output = saveMxmlOutput(logo); |
| 147 | + |
| 148 | + expect(output).toContain('<tie type="start"/>'); |
| 149 | + expect(output).toContain('<tie type="stop"/>'); |
| 150 | + }); |
| 151 | +}); |
0 commit comments