2016-02-04 00:00:11 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2016, United States Government
|
2016-02-04 00:00:11 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2016-02-04 00:00:11 +00:00
|
|
|
* "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.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2016-02-04 00:00:11 +00:00
|
|
|
* 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/Region'],
|
|
|
|
function (Region) {
|
|
|
|
|
|
|
|
describe("The region class ", function () {
|
|
|
|
|
|
|
|
var region,
|
2016-02-09 07:05:48 +00:00
|
|
|
part2 = new Region({'name': 'part2'});
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
beforeEach(function () {
|
2016-02-04 00:00:11 +00:00
|
|
|
region = new Region();
|
2016-02-09 07:05:48 +00:00
|
|
|
region.regions = [
|
|
|
|
new Region({name: 'part1'}),
|
|
|
|
new Region({name: 'part3'}),
|
|
|
|
new Region({name: 'part4'})
|
2016-02-04 00:00:11 +00:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
it("adding a region at a specified index adds it in that" +
|
2016-05-19 18:29:13 +00:00
|
|
|
" position", function () {
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
region.addRegion(part2, 1);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(region.regions.length).toBe(4);
|
|
|
|
expect(region.regions[1]).toBe(part2);
|
|
|
|
});
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("adding a region without an index adds it at the end", function () {
|
2016-02-09 07:05:48 +00:00
|
|
|
var partN = new Region({'name': 'partN'});
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
region.addRegion(partN);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(4);
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(region.regions[region.regions.length - 1]).toBe(partN);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
describe("removing a region", function () {
|
2016-02-04 00:00:11 +00:00
|
|
|
var partName = "part2";
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
beforeEach(function () {
|
2016-02-09 07:05:48 +00:00
|
|
|
region.regions = [
|
|
|
|
new Region({name: 'part1'}),
|
2016-02-04 00:00:11 +00:00
|
|
|
part2,
|
2016-02-09 07:05:48 +00:00
|
|
|
new Region({name: 'part3'}),
|
|
|
|
new Region({name: 'part4'})
|
2016-02-04 00:00:11 +00:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("with a string matches on region name", function () {
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(4);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(1);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
region.removeRegion(partName);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(3);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(-1);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("with a number removes by index", function () {
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(4);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(1);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
region.removeRegion(1);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(3);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(-1);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("with object matches that object", function () {
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(4);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(1);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
region.removeRegion(part2);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
expect(region.regions.length).toBe(3);
|
|
|
|
expect(region.regions.indexOf(part2)).toBe(-1);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|