mirror of
https://github.com/nasa/openmct.git
synced 2025-04-08 11:54:25 +00:00
[Fixed Position] Add unit tests
This commit is contained in:
parent
3ed0880c6e
commit
aa8f780e4e
@ -24,6 +24,8 @@ define(
|
||||
['../../src/elements/ElementProxy'],
|
||||
function (ElementProxy) {
|
||||
|
||||
var GRID_SIZE = [13,21];
|
||||
|
||||
describe("A fixed position element proxy", function () {
|
||||
var testElement,
|
||||
testElements,
|
||||
@ -35,13 +37,15 @@ define(
|
||||
y: 2,
|
||||
stroke: '#717171',
|
||||
width: 42,
|
||||
height: 24
|
||||
height: 24,
|
||||
useGrid: true
|
||||
};
|
||||
testElements = [{}, {}, testElement, {}];
|
||||
proxy = new ElementProxy(
|
||||
testElement,
|
||||
testElements.indexOf(testElement),
|
||||
testElements
|
||||
testElements,
|
||||
GRID_SIZE
|
||||
);
|
||||
});
|
||||
|
||||
@ -73,6 +77,29 @@ define(
|
||||
expect(proxy.x()).toEqual(0);
|
||||
expect(proxy.y()).toEqual(0);
|
||||
});
|
||||
|
||||
it("allows modifying the current grid size", function () {
|
||||
proxy.setGridSize([112,420]);
|
||||
expect(proxy.gridSize).toEqual([112,420]);
|
||||
});
|
||||
|
||||
it("returns the current grid size only if the element snaps to grid", function () {
|
||||
expect(proxy.getGridSize()).toEqual([13,21]);
|
||||
proxy.useGrid(false);
|
||||
expect(proxy.getGridSize()).toEqual([1,1]);
|
||||
});
|
||||
|
||||
it("returns the mininum height and width of an element currently used units", function () {
|
||||
// Assumes mininum height and width are 10, in pixels
|
||||
expect(proxy.getMinWidth()).toEqual(1);
|
||||
expect(proxy.getMinHeight()).toEqual(1);
|
||||
proxy.setGridSize([7,4]);
|
||||
expect(proxy.getMinWidth()).toEqual(2);
|
||||
expect(proxy.getMinHeight()).toEqual(3);
|
||||
proxy.useGrid(false);
|
||||
expect(proxy.getMinWidth()).toEqual(10);
|
||||
expect(proxy.getMinHeight()).toEqual(10);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -24,6 +24,8 @@ define(
|
||||
['../../src/elements/LineHandle'],
|
||||
function (LineHandle) {
|
||||
|
||||
var GRID_SIZE = [45,21];
|
||||
|
||||
describe("A fixed position drag handle", function () {
|
||||
var testElement,
|
||||
handle;
|
||||
@ -33,10 +35,11 @@ define(
|
||||
x: 3,
|
||||
y: 42,
|
||||
x2: 8,
|
||||
y2: 11
|
||||
y2: 11,
|
||||
useGrid: true
|
||||
};
|
||||
|
||||
handle = new LineHandle(testElement, 'x', 'y', 'x2', 'y2');
|
||||
handle = new LineHandle(testElement, 'x', 'y', 'x2', 'y2', GRID_SIZE);
|
||||
});
|
||||
|
||||
it("provides x/y grid coordinates for its corner", function () {
|
||||
@ -67,6 +70,9 @@ define(
|
||||
expect(testElement.y).not.toEqual(testElement.y2);
|
||||
});
|
||||
|
||||
it("returns the correct grid size", function () {
|
||||
expect(handle.getGridSize()).toEqual([45,21]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ define(
|
||||
['../../src/elements/ResizeHandle'],
|
||||
function (ResizeHandle) {
|
||||
|
||||
var TEST_MIN_WIDTH = 4, TEST_MIN_HEIGHT = 2;
|
||||
var TEST_MIN_WIDTH = 4, TEST_MIN_HEIGHT = 2,
|
||||
GRID_SIZE = [34,81];
|
||||
|
||||
describe("A fixed position drag handle", function () {
|
||||
var testElement,
|
||||
@ -35,13 +36,15 @@ define(
|
||||
x: 3,
|
||||
y: 42,
|
||||
width: 30,
|
||||
height: 36
|
||||
height: 36,
|
||||
useGrid: true
|
||||
};
|
||||
|
||||
handle = new ResizeHandle(
|
||||
testElement,
|
||||
TEST_MIN_WIDTH,
|
||||
TEST_MIN_HEIGHT
|
||||
TEST_MIN_HEIGHT,
|
||||
GRID_SIZE
|
||||
);
|
||||
});
|
||||
|
||||
@ -73,6 +76,10 @@ define(
|
||||
expect(testElement.height).toEqual(TEST_MIN_HEIGHT);
|
||||
});
|
||||
|
||||
it("returns the correct grid size", function () {
|
||||
expect(handle.getGridSize()).toEqual([34,81]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT, Copyright (c) 2014-2017, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
['../../src/elements/UnitAccessorMutator'],
|
||||
function (UnitAccessorMutator) {
|
||||
@ -7,7 +29,10 @@ define(
|
||||
describe("An elementProxy.gridSize accessor-mutator", function () {
|
||||
var mockElementProxy,
|
||||
testElement,
|
||||
uAM;
|
||||
mockLineProxy,
|
||||
testLine,
|
||||
uAM,
|
||||
uAMLine;
|
||||
|
||||
beforeEach(function () {
|
||||
testElement = {
|
||||
@ -25,11 +50,33 @@ define(
|
||||
getMinWidth: jasmine.createSpy('minWidth')
|
||||
};
|
||||
|
||||
testLine = {
|
||||
x: 7,
|
||||
y: 8,
|
||||
x2: 9,
|
||||
y2: 10,
|
||||
width: 11,
|
||||
height: 12,
|
||||
useGrid: true
|
||||
};
|
||||
|
||||
mockLineProxy = {
|
||||
element: testLine,
|
||||
gridSize: GRID_SIZE,
|
||||
getMinHeight: jasmine.createSpy('minHeight'),
|
||||
getMinWidth: jasmine.createSpy('minWidth')
|
||||
};
|
||||
|
||||
|
||||
|
||||
uAM = new UnitAccessorMutator(mockElementProxy);
|
||||
uAMLine = new UnitAccessorMutator(mockLineProxy);
|
||||
|
||||
mockElementProxy.getMinWidth.andReturn(1);
|
||||
mockElementProxy.getMinHeight.andReturn(1);
|
||||
|
||||
mockLineProxy.getMinWidth.andReturn(1);
|
||||
mockLineProxy.getMinHeight.andReturn(1);
|
||||
});
|
||||
|
||||
it("allows access to useGrid", function () {
|
||||
@ -41,7 +88,7 @@ define(
|
||||
expect(mockElementProxy.element.useGrid).toEqual(false);
|
||||
});
|
||||
|
||||
it("converts coordinates appropriately", function () {
|
||||
it("converts coordinates appropriately for a box", function () {
|
||||
uAM(false);
|
||||
expect(mockElementProxy.element.x).toEqual(26);
|
||||
expect(mockElementProxy.element.y).toEqual(51);
|
||||
@ -54,6 +101,23 @@ define(
|
||||
expect(mockElementProxy.element.height).toEqual(5);
|
||||
});
|
||||
|
||||
it("converts coordinates appropriately for a line", function () {
|
||||
uAMLine(false);
|
||||
expect(mockLineProxy.element.x).toEqual(91);
|
||||
expect(mockLineProxy.element.y).toEqual(136);
|
||||
expect(mockLineProxy.element.x2).toEqual(117);
|
||||
expect(mockLineProxy.element.y2).toEqual(170);
|
||||
expect(mockLineProxy.element.width).toEqual(143);
|
||||
expect(mockLineProxy.element.height).toEqual(204);
|
||||
uAMLine(true);
|
||||
expect(mockLineProxy.element.x).toEqual(7);
|
||||
expect(mockLineProxy.element.y).toEqual(8);
|
||||
expect(mockLineProxy.element.x2).toEqual(9);
|
||||
expect(mockLineProxy.element.y2).toEqual(10);
|
||||
expect(mockLineProxy.element.width).toEqual(11);
|
||||
expect(mockLineProxy.element.height).toEqual(12);
|
||||
});
|
||||
|
||||
it("doesn't covert coordinates unecessarily", function () {
|
||||
uAM(false);
|
||||
expect(mockElementProxy.element.x).toEqual(26);
|
||||
@ -67,6 +131,27 @@ define(
|
||||
expect(mockElementProxy.element.height).toEqual(85);
|
||||
});
|
||||
|
||||
it("snaps coordinates onto the grid", function () {
|
||||
uAM(false);
|
||||
mockElementProxy.element.x += 11;
|
||||
mockElementProxy.element.y -= 27;
|
||||
mockElementProxy.element.width -= 14;
|
||||
mockElementProxy.element.height += 4;
|
||||
uAM(true);
|
||||
expect(mockElementProxy.element.x).toEqual(3);
|
||||
expect(mockElementProxy.element.y).toEqual(1);
|
||||
expect(mockElementProxy.element.width).toEqual(3);
|
||||
expect(mockElementProxy.element.height).toEqual(5);
|
||||
});
|
||||
|
||||
it("enforces a minimum height and width", function () {
|
||||
uAM(false);
|
||||
mockElementProxy.element.width = 4;
|
||||
mockElementProxy.element.height = 4;
|
||||
uAM(true);
|
||||
expect(mockElementProxy.element.width).toEqual(1);
|
||||
expect(mockElementProxy.element.height).toEqual(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user