From 44c3bcb8fc6985154444dddc0ec9fe95bd6bc45a Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Oct 2023 11:32:01 -0400 Subject: [PATCH] fixing for windows, and such, more test splitting --- benchtop-fe/src/parsers/Transducer.js | 6 ++-- .../parsers/__tests__/parseHardware.test.js | 2 +- .../parsers/__tests__/parseTransducer.test.js | 29 ++++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/benchtop-fe/src/parsers/Transducer.js b/benchtop-fe/src/parsers/Transducer.js index d33f996..07da1ae 100644 --- a/benchtop-fe/src/parsers/Transducer.js +++ b/benchtop-fe/src/parsers/Transducer.js @@ -43,10 +43,12 @@ export default function parseTransducer(fileName, content, accuracy){ [, value, unit] = match; value = parseInt(value); } - if (unit === "SCCM") { + // SCCM and LPM are Flow + if (unit === "SCCM" || unit === "LPM") { transducerType = "Flow"; } - if (unit === "PSIA") { + // PSIA and PSID are pressure + if (unit === "PSIA" || unit === "PSID") { transducerType = "Pressure"; } } diff --git a/benchtop-fe/src/parsers/__tests__/parseHardware.test.js b/benchtop-fe/src/parsers/__tests__/parseHardware.test.js index d598d9a..56d2d4a 100644 --- a/benchtop-fe/src/parsers/__tests__/parseHardware.test.js +++ b/benchtop-fe/src/parsers/__tests__/parseHardware.test.js @@ -5,5 +5,5 @@ const file = fs.readFileSync("src/parsers/__tests__/hardware_calibration.txt", ' test('parseHardwareCalibration', () => { const hardware = parseHardwareCalibration(file, 0.05) - console.log(hardware) + // console.log(hardware) }); \ No newline at end of file diff --git a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js index e274f50..f82c1eb 100644 --- a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js +++ b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js @@ -1,3 +1,5 @@ +import {tr} from "date-fns/locale"; + const fs = require('fs'); const path = require('path'); import parseTransducer from "../Transducer" @@ -20,20 +22,25 @@ function readFiles(dir) { files.push({ filepath, name, ext, stat, content }); } }); - - files.sort((a, b) => { - // natural sort alphanumeric strings - // https://stackoverflow.com/a/38641281 - return a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }); - }); - return files; } -test('Can parse any Transducer Verify file', () => { +describe("Test for all files", () => { let files = readFiles("src/parsers/__tests__/transducer_verify/"); for (const file of files) { - const transducer = parseTransducer(file.name, file.content, 0.05) - console.log(transducer) + test(`Can parse ${file.name}`, () => { + const transducers = parseTransducer(file.name, file.content, 0.05) + + expect(transducers.length).toBeGreaterThan(0) + for (const transducer of transducers) { + expect(transducer).toHaveProperty("Part Number") + expect(transducer).toHaveProperty("Transducer Name") + expect(transducer).toHaveProperty("Gauge Reading") + expect(transducer).toHaveProperty("Master Value") + + expect(transducer["Gauge Reading"].length).toBeGreaterThan(1); + expect(transducer["Master Value"].length).toBe(transducer["Gauge Reading"].length); + } + }); } -}); \ No newline at end of file +});