Skip to content

Commit

Permalink
Tests and minor edits for classes/docking.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ericman314 committed Oct 29, 2018
1 parent 3c18d0a commit c783fa6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/src/classes/docking.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { System } from "./generic";

export default class DockingPort extends System {
constructor(params) {
constructor(params = {}) {
super(params);
this.class = "DockingPort";
this.type = params.type || "shuttlebay";
Expand All @@ -20,6 +20,7 @@ export default class DockingPort extends System {
}
}
updateDockingPort({ name, type, clamps, compress, doors, image, docked }) {
// Suggestion: change to if(arguments[0].hasOwnProperty('name'))
if (name || name === "") {
this.name = name;
}
Expand Down
50 changes: 50 additions & 0 deletions server/tests/classes/docking.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Engine } from '../../src/classes/engine';
import { System } from "../../src/classes/generic";
import DockingPort from "../../src/classes/docking";

describe('DockingPort', () => {

test('should throw if called without the \'new\' operator', () => {
expect(() => { const d = DockingPort(); }).toThrow(/Cannot call a class as a function/);
});

test('should extend System', () => {
expect(new DockingPort()).toBeInstanceOf(System);
})

describe('constructor', () => {
test('should set default parameters', () => {
const dock = new DockingPort();
expect(dock.class).toBe('DockingPort');
expect(dock.type).toBe('shuttlebay');
expect(dock.clamps).toBe(true);
expect(dock.compress).toBe(true);
expect(dock.doors).toBe(true);
expect(dock.image).toBe('/Docking Images/Default.png');
expect(dock.docked).toBe(true);

const dock2 = new DockingPort({ type: 'not_a_shuttlebay' });
expect(dock2.type).toBe('not_a_shuttlebay');
expect(dock2.clamps).toBe(false);
expect(dock2.compress).toBe(false);
expect(dock2.doors).toBe(false);
expect(dock2.image).toBe('/Docking Images/Default.png');
expect(dock2.docked).toBe(false);
});
});

describe('updateDockingPort', () => {
test('should update a docking port', () => {
const dock = new DockingPort();
dock.updateDockingPort({ name: 'Emergency Exit', type: 'screen_door', clamps: false, compress: false, doors: false, docked: false, image: '404_NOT_FOUND' });
expect(dock.name).toBe('Emergency Exit');
expect(dock.type).toBe('screen_door');
expect(dock.clamps).toBe(false);
expect(dock.compress).toBe(false);
expect(dock.doors).toBe(false);
expect(dock.image).toBe('404_NOT_FOUND');
expect(dock.docked).toBe(false);
})
})
});

0 comments on commit c783fa6

Please sign in to comment.