Skip to content

Commit

Permalink
Tests for coolant.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ericman314 committed Oct 28, 2018
1 parent e8e5d0e commit 3f9bc90
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions server/tests/classes/coolant.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// TODO: Figure out why we need import { Engine } what to do about it
import { Engine } from '../../src/classes/engine';
import { System } from "../../src/classes/generic";
import Coolant from '../../src/classes/coolant';

describe('Coolant', () => {

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

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

describe('constructor', () => {
test('should set default parameters', () => {
const cool = new Coolant();
expect(cool.name).toBe('Coolant');
expect(cool.class).toBe('Coolant');
expect(cool.type).toBe('Coolant');
expect(cool.coolant).toBe(1);
expect(cool.coolantRate).toBe(0.2);
expect(cool.transfer).toBeNull();
});
});

describe('power', () => {
test.skip('should get/set', () => {
// TODO: The getter and setter don't seem to do very much yet
});
});

describe('setCoolant', () => {
test('should limit coolant to 0..1', () => {
const cool = new Coolant();
cool.setCoolant(0.5);
expect(cool.coolant).toBe(0.5);
cool.setCoolant(3);
expect(cool.coolant).toBe(1);
cool.setCoolant(-3);
expect(cool.coolant).toBe(0);
});
});

describe('transferCoolant and cancelTransfer', () => {
test('should set or cancel a coolant transfer', () => {
const cool = new Coolant();
cool.transferCoolant('fake_sysid');
expect(cool.transfer).toEqual({ sysId: 'fake_sysid', sign: 1 });
cool.transferCoolant('another_sysid', 'tank');
expect(cool.transfer).toEqual({ sysId: 'another_sysid', sign: -1 });
cool.cancelTransfer();
expect(cool.transfer).toBeNull();
});
});
});

0 comments on commit 3f9bc90

Please sign in to comment.