libreoffice-online/browser/mocha_tests/CanvasSectionContainer.test.ts

76 lines
2.5 KiB
TypeScript
Raw Normal View History

/// <reference path="./refs/globals.ts"/>
/// <reference path="../src/geometry/Point.ts" />
/// <reference path="../src/geometry/Bounds.ts" />
/// <reference path="../src/layer/tile/CanvasSectionContainer.ts" />
/// <reference path="./helper/canvasContainerSetup.ts" />
/// <reference path="./helper/types.ts" />
var jsdom = require('jsdom');
var assert = require('assert').strict;
var dom = new jsdom.JSDOM(canvasDomString());
global.window = dom.window;
global.document = dom.window.document;
const canvasWidth = 1024;
const canvasHeight = 768;
function assertPosSize(actual: mtest.Rectangle, expected: mtest.Rectangle) {
// Only assert components of expected that are provided.
if (typeof expected.x === 'number')
assert.equal(actual.x, expected.x, 'Left mismatch');
if (typeof expected.y === 'number')
assert.equal(actual.y, expected.y, 'Top mismatch');
if (typeof expected.width === 'number')
assert.equal(actual.width, expected.width, 'Width mismatch');
if (typeof expected.height === 'number')
assert.equal(actual.height, expected.height, 'Height mismatch');
}
function getSectionRectangle(section: CanvasSectionObject): mtest.Rectangle {
return {
x: section.myTopLeft[0],
y: section.myTopLeft[1],
width: section.size[0],
height: section.size[1],
};
}
describe('Singleton section container', function() {
const canvas = <HTMLCanvasElement>document.getElementById('document-canvas');
const docLayer = {};
const tsManager = {};
const sectionContainer = new CanvasSectionContainer(canvas, true /* disableDrawing? */);
sectionContainer.onResize(canvasWidth, canvasHeight); // Set canvas size.
sectionContainer.createSection({
name: 'OnlySection',
anchor: 'top left',
position: [0, 0],
size: [1, 1],
expand: 'bottom right',
processingOrder: 1,
drawingOrder: 1,
zIndex: 1,
interactable: false,
sectionProperties: {
docLayer: docLayer,
tsManager: tsManager,
strokeStyle: '#c0c0c0'
},
});
sectionContainer.enableDrawing();
it('Container should have OnlySection', function() {
assert.ok(sectionContainer.doesSectionExist('OnlySection'));
});
it('OnlySection PosSize checks', function () {
const only = sectionContainer.getSectionWithName('OnlySection');
const onlyRect = getSectionRectangle(only);
assertPosSize(onlyRect, {x: 0, y: 0, width: 1024, height: 768});
});
});