2020-11-30 21:26:14 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
2021-06-11 14:15:14 +00:00
|
|
|
const { Diagnostic, DiagnosticElement } = require('../src/diagnostic');
|
2020-11-30 21:26:14 +00:00
|
|
|
const apiResponse = require('./diagnostic.sample.json');
|
|
|
|
|
|
|
|
describe('Diagnostics', () => {
|
|
|
|
let d;
|
|
|
|
|
|
|
|
describe('Diagnostic', () => {
|
|
|
|
beforeEach(() => d = new Diagnostic(_.get(apiResponse, 'commandResponse.body.diagnosticResponse[0]')));
|
|
|
|
|
|
|
|
it('should parse a diagnostic response', () => {
|
|
|
|
assert.strictEqual(d.name, 'AMBIENT AIR TEMPERATURE');
|
2021-06-11 14:15:14 +00:00
|
|
|
assert.strictEqual(d.diagnosticElements.length, 2);
|
2020-11-30 21:26:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should toString() correctly', () => {
|
|
|
|
const output = d.toString().trimEnd();
|
|
|
|
const lines = output.split(/\r\n|\r|\n/);
|
2021-06-11 14:15:14 +00:00
|
|
|
assert.strictEqual(lines.length, 3);
|
2020-11-30 21:26:14 +00:00
|
|
|
assert.strictEqual(lines[0], 'AMBIENT AIR TEMPERATURE:');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('DiagnosticElement', () => {
|
|
|
|
beforeEach(() => d = new Diagnostic(_.get(apiResponse, 'commandResponse.body.diagnosticResponse[8]')));
|
|
|
|
it('should parse a diagnostic element', () => {
|
|
|
|
assert.strictEqual(d.name, 'TIRE PRESSURE');
|
|
|
|
assert.ok(_.isArray(d.diagnosticElements));
|
2021-06-11 14:15:14 +00:00
|
|
|
assert.strictEqual(d.diagnosticElements.length, 12);
|
2020-11-30 21:26:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should toString() correctly', () => {
|
|
|
|
const output = d.toString().trimEnd();
|
|
|
|
const lines = output.split(/\r\n|\r|\n/);
|
2021-06-11 14:15:14 +00:00
|
|
|
assert.strictEqual(lines.length, 13);
|
2020-11-30 21:26:14 +00:00
|
|
|
assert.strictEqual(lines[0], 'TIRE PRESSURE:');
|
|
|
|
assert.strictEqual(lines[1], ' TIRE PRESSURE LF: 240.0kPa');
|
|
|
|
});
|
2021-06-11 14:15:14 +00:00
|
|
|
|
|
|
|
it('should strip non-alpha chars', () => {
|
|
|
|
assert.strictEqual(DiagnosticElement.convertName('TEMP', '°F'), 'TEMP F');
|
|
|
|
});
|
2020-11-30 21:26:14 +00:00
|
|
|
});
|
|
|
|
});
|