ed-safari/test/System.test.ts

83 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-05-17 13:09:57 -07:00
// noinspection DuplicatedCode
2023-05-18 20:13:30 -07:00
import { expect, jest, it, beforeEach } from '@jest/globals';
import { ExtendedNavRoute, FSDJump, Location } from '@kayahr/ed-journal';
import { Body } from '../src/models/Body';
import { CMDR } from '../src/models/CMDR';
import { EDSM } from '../src/models/EDSM';
import { Journal } from '../src/models/Journal';
import { ExtendedNavRouteSystem, System } from '../src/models/System';
import { mockEdsmResponses, mockObjects } from './mockData';
2023-05-17 13:09:57 -07:00
const appRoot = require('app-root-path');
2023-05-18 20:13:30 -07:00
describe('System', () => {
2023-05-17 13:09:57 -07:00
beforeEach(() => {
2023-05-18 20:13:30 -07:00
jest.spyOn(EDSM, 'getSystemValue').mockResolvedValue(undefined);
2023-05-17 13:09:57 -07:00
});
describe('constructor()', () => {
it('should create new system from NavRoute', () => {
2023-05-18 20:13:30 -07:00
const data = mockObjects.navRouteSystem as ExtendedNavRouteSystem;
2023-05-17 13:09:57 -07:00
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBe(data.StarClass);
expect(Array.isArray(system.bodies)).toBe(true);
});
2023-05-18 20:13:30 -07:00
it('should create new system from FsdJump', () => {
const data = mockObjects.FSDJumpSystem as FSDJump;
2023-05-17 13:09:57 -07:00
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBeUndefined();
expect(Array.isArray(system.bodies)).toBe(true);
});
it('should create new system from location', () => {
2023-05-18 20:13:30 -07:00
const data = mockObjects.LocationSystem as Location;
2023-05-17 13:09:57 -07:00
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBeUndefined();
expect(Array.isArray(system.bodies)).toBe(true);
});
});
describe('System Appraisal', () => {
it('should get system value', (done) => {
2023-05-18 20:13:30 -07:00
const edsmData = mockEdsmResponses.systemValue;
jest.spyOn(EDSM, 'getSystemValue').mockResolvedValue(edsmData);
2023-05-17 13:09:57 -07:00
2023-05-18 20:13:30 -07:00
const data = mockObjects.navRouteSystem as ExtendedNavRouteSystem;
2023-05-17 13:09:57 -07:00
const system = new System(data);
EDSM.connect().on('SYSTEM_APPRAISED', () => {
expect(system.estimatedValue).toBe(edsmData.estimatedValue);
done();
});
});
});
describe('sortBodies()', () => {
it('should set bodies to Body[] with the same amount of elements', (done) => {
2023-05-18 20:13:30 -07:00
const cmdr = new CMDR(`${appRoot}/test_journals/ScannedBodies`);
cmdr.on('BUILD_BODY_LIST', () => {
const before = cmdr.location.bodies;
cmdr.location.sortBodies();
expect(cmdr.location.bodies.length).toBe(before.length);
expect(Array.isArray(cmdr.location.bodies)).toBe(true);
expect(cmdr.location.bodies[0]).toBeInstanceOf(Body);
cmdr.shutdown();
2023-05-17 13:09:57 -07:00
done();
});
});
});
});