UNPKG

satie

Version:

A sheet music renderer for the web

130 lines (129 loc) 4.68 kB
/** * This file is part of Satie music engraver <https://github.com/jnetterf/satie>. * Copyright (C) Joshua Netterfield <joshua.ca> 2015 - present. * * Satie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Satie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Satie. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; var implAttributes_attributesModel_1 = require("../implAttributes_attributesModel"); var chai_1 = require("chai"); var document_1 = require("../document"); var engine_factory_1 = require("../engine_factory"); function makeCursor(factory, models) { models.part = "P1"; var v = { const: function () { return v; }, document: { __fakeDocument: true }, fixup: null, dangerouslyPatchWithoutValidation: null, patch: null, advance: null, segmentInstance: models, segmentPosition: 0, staffAttributes: { divisions: 60, clef: { sign: "G", clefOctaveChange: "0", line: 2 }, time: { beats: ["4"], beatTypes: [4], senzaMisura: null } }, staffAccidentals: {}, staffIdx: 0, measureInstance: { uuid: 100, nonControlling: false, idx: 0, number: "1", implicit: false, parts: { "P1": { staves: [ null, {} ], voices: null, } } }, measureIsLast: true, print: null, header: { partList: [ { _class: "ScorePart", id: "P1" } ] }, segmentDivision: 0, factory: factory, preview: false, singleLineMode: false, }; return v; } exports.makeCursor = makeCursor; function FakeChord(constructors) { constructors[document_1.Type.Chord] = function () { // pass }; } describe("[attributes.ts]", function () { describe("AttributesModel", function () { var factory = new engine_factory_1.default([implAttributes_attributesModel_1.default, FakeChord]); var attributes; var segment; it("can be created", function () { attributes = factory.create(document_1.Type.Attributes); chai_1.expect(!!attributes).to.be.true; // Divisions is usually set by the engine attributes.divisions = 100; segment = [attributes]; var cursor = makeCursor(factory, segment); cursor.staffAttributes = {}; attributes.refresh(cursor); }); it("lays out properly when at start of song", function () { var cursor = makeCursor(factory, segment); cursor.staffAttributes = {}; var lCursor = __assign({}, cursor, { measureX: 0, lineShortest: Number.MAX_VALUE, lineBarOnLine: 0, lineTotalBarsOnLine: 1, lineIndex: 0, lineCount: 1, segmentX: 100, lineMaxPaddingTopByStaff: [], lineMaxPaddingBottomByStaff: [] }); var layout = attributes.getLayout(lCursor); chai_1.expect(!!layout.keySignature).to.be.true; chai_1.expect(!!layout.time).to.be.true; chai_1.expect(!!layout.clef).to.be.true; chai_1.expect(layout.tsSpacing).to.be.gt(0); chai_1.expect(layout.clefSpacing).to.be.gt(0); chai_1.expect(layout.ksSpacing).to.be.gt(0); chai_1.expect(layout.x).to.be.lt(lCursor.segmentX); var expectedChange = layout.clefSpacing + layout.tsSpacing + layout.ksSpacing; chai_1.expect(lCursor.segmentX - layout.x).to.equal(expectedChange); }); }); });