Unit tests for description of bilirubin result

This commit is contained in:
RunasSudo 2024-08-27 18:00:37 +10:00
parent 030609b45e
commit 74ea5172c8
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

86
tests/describe.test.js Normal file
View File

@ -0,0 +1,86 @@
/*
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Import bilirubin_lib.js
const fs = require('fs');
eval(fs.readFileSync('src/bilirubin_lib.js').toString());
const assert = require('node:assert');
const { suite, test } = require('node:test');
suite('Describe bilirubin result', () => {
const dateBirth = new Date(2024, 11, 24, 4, 20, 31, 415);
const dateMeasurement = new Date(2024, 11, 25, 4, 20, 31, 415);
const gestation = 38;
test('Well below phototherapy threshold', () => {
const bilirubin = 20;
const expectedText = 'Bilirubin of 20 at 1 day, 0 hours is <span class="font-bold">180 below</span> the phototherapy threshold.';
const expectedColour = 'sky';
let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin);
assert.equal(d, 1);
assert.equal(result_text, expectedText);
assert.equal(text_colour, 'text-' + expectedColour + '-800');
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
});
test('Within 50 of phototherapy threshold', () => {
const bilirubin = 160;
const expectedText = 'Bilirubin of 160 at 1 day, 0 hours is <span class="font-bold">40 below</span> the phototherapy threshold.';
const expectedColour = 'yellow';
let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin);
assert.equal(d, 1);
assert.equal(result_text, expectedText);
assert.equal(text_colour, 'text-' + expectedColour + '-800');
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
});
test('Above phototherapy threshold', () => {
const bilirubin = 220;
const expectedText = 'Bilirubin of 220 at 1 day, 0 hours is <span class="font-bold">20 above</span> the phototherapy threshold, 80 below the exchange transfusion threshold.';
const expectedColour = 'orange';
let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin);
assert.equal(d, 1);
assert.equal(result_text, expectedText);
assert.equal(text_colour, 'text-' + expectedColour + '-800');
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
});
test('Above exchange transfusion threshold', () => {
const bilirubin = 350;
const expectedText = 'Bilirubin of 350 at 1 day, 0 hours is 50 above the <span class="font-bold">exchange transfusion</span> threshold.';
const expectedColour = 'red';
let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin);
assert.equal(d, 1);
assert.equal(result_text, expectedText);
assert.equal(text_colour, 'text-' + expectedColour + '-800');
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
});
});