-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit tests for dumpFileFormatter class
- Loading branch information
Showing
9 changed files
with
7,783 additions
and
2,603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
["@babel/preset-env", { targets: { node: "current" } }], | ||
"@babel/preset-typescript", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const path = require("path"); | ||
/** @type {import('jest').Config} */ | ||
const config = { | ||
roots: [ | ||
"<rootDir>/src/test/nodeTest" | ||
], | ||
globals: { | ||
__DEV__: true | ||
}, | ||
}; | ||
|
||
module.exports = config; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { IExportDumpData } from "../../db/oe"; | ||
import { DumpFileFormatter } from "../../webview/DumpFileFormatter"; | ||
|
||
export class DumpFileFormatterTest extends DumpFileFormatter { | ||
public dumpData: string = super.dumpData; | ||
public trailerInfo: string = super.trailerInfo; | ||
public dumpFile: string = super.dumpFile; | ||
|
||
public combineDumpFile() { | ||
return super.combineDumpFile(); | ||
} | ||
|
||
public formatDumpData(data: IExportDumpData) { | ||
return super.formatDumpData(data); | ||
} | ||
|
||
public formatTrailerInfo( | ||
data: any, | ||
fileName: string, | ||
dbName: string, | ||
recordNum: number | ||
) { | ||
return super.formatTrailerInfo(data, fileName, dbName, recordNum); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { expect, jest, test } from "@jest/globals"; | ||
import { assert } from "console"; | ||
import { | ||
testObjInput, | ||
testOutputDumpData, | ||
testOutputTrailerInfo, | ||
} from "./testObjects"; | ||
import { DumpFileFormatterTest } from "./DumpFileFormatterTest"; | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test("formatDumpFile calls other methods ", () => { | ||
const dumpFileFormatterTest = new DumpFileFormatterTest(); | ||
let spyDumpData = jest.spyOn(dumpFileFormatterTest, "formatDumpData"); | ||
let spyTrailerInfo = jest.spyOn(dumpFileFormatterTest, "formatTrailerInfo"); | ||
let spyDumpFile = jest.spyOn(dumpFileFormatterTest, "combineDumpFile"); | ||
|
||
dumpFileFormatterTest.formatDumpFile(testObjInput, "test", "test"); | ||
expect(spyDumpData).toHaveBeenCalled(); | ||
expect(spyTrailerInfo).toHaveBeenCalled(); | ||
expect(spyDumpFile).toHaveBeenCalled(); | ||
}); | ||
|
||
test("getDumpFile method returns dumpFile", () => { | ||
const dumpFileFormatterTest = new DumpFileFormatterTest(); | ||
dumpFileFormatterTest.dumpFile = "dumpFile"; | ||
assert("dumpFile", dumpFileFormatterTest.getDumpFile()); | ||
}); | ||
|
||
test("combineDumpFile combines data to dump file in right format", () => { | ||
const dumpFileFormatterTest = new DumpFileFormatterTest(); | ||
dumpFileFormatterTest.dumpData = "test dump Data"; | ||
dumpFileFormatterTest.trailerInfo = "test trailer info"; | ||
dumpFileFormatterTest.combineDumpFile(); | ||
|
||
const testReturnValue = | ||
"test dump Data\r\n" + | ||
".\r\n" + | ||
"test trailer info\r\n" + | ||
".\r\n" + | ||
"0000000021"; | ||
|
||
assert(testReturnValue, dumpFileFormatterTest.dumpFile); | ||
}); | ||
|
||
test("formatDumpData formatted correctly with add data types", () => { | ||
const dumpFileFormatterTest = new DumpFileFormatterTest(); | ||
dumpFileFormatterTest.formatDumpData(testObjInput); | ||
assert(testOutputDumpData, dumpFileFormatterTest.dumpData); | ||
}); | ||
|
||
test("formatTrailerInfo formatted correctly", () => { | ||
const dumpFileFormatterTest = new DumpFileFormatterTest(); | ||
dumpFileFormatterTest.formatTrailerInfo(testObjInput.psc, "testing", "testDb", 4); | ||
assert(testOutputTrailerInfo, dumpFileFormatterTest.trailerInfo); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { IExportDumpData } from "../../db/oe"; | ||
|
||
export const testObjInput: IExportDumpData = { | ||
columns: [ | ||
{ | ||
name: "ROWID", | ||
key: "ROWID", | ||
label: "ROWID", | ||
type: "ROWID", | ||
format: null, | ||
}, | ||
{ | ||
name: "testCharacter", | ||
key: "testCharacter", | ||
label: "testCharacter", | ||
type: "character", | ||
format: "x(10)", | ||
}, | ||
{ | ||
name: "testDecimal", | ||
key: "testDecimal", | ||
label: "testDecimal", | ||
type: "decimal", | ||
format: "->,>>>,>>9.99", | ||
}, | ||
{ | ||
name: "testInt", | ||
key: "testInt", | ||
label: "testInt", | ||
type: "integer", | ||
format: ">>9", | ||
}, | ||
{ | ||
name: "testIntPercent", | ||
key: "testIntPercent", | ||
label: "testIntPercent", | ||
type: "integer", | ||
format: ">>9%", | ||
}, | ||
{ | ||
name: "testInt64", | ||
key: "testInt64", | ||
label: "testInt64", | ||
type: "int64", | ||
format: ">>>>>>>>>>>>>>>>>>9", | ||
}, | ||
{ | ||
name: "testRaw", | ||
key: "testRaw", | ||
label: "testRaw", | ||
type: "raw", | ||
format: "x(8)", | ||
}, | ||
{ | ||
name: "testDate", | ||
key: "testDate", | ||
label: "testDate", | ||
type: "date", | ||
format: "99/99/9999", | ||
}, | ||
{ | ||
name: "testDatetime", | ||
key: "testDatetime", | ||
label: "testDatetime", | ||
type: "datetime", | ||
format: "99/99/9999 HH:MM:SS", | ||
}, | ||
{ | ||
name: "testLogical", | ||
key: "testLogical", | ||
label: "testLogical", | ||
type: "logical", | ||
format: "TRUE/FALSE", | ||
}, | ||
], | ||
psc: { | ||
cpstream: "UTF-8", | ||
dateformat: "mdy-1950", | ||
numformat: "44,46", | ||
timestamp: "2023/02/20-15:36:36", | ||
}, | ||
rawData: [ | ||
{ | ||
ROWID: "0x0000000000002c01", | ||
testCharacter: "record no.1", | ||
testDecimal: 0.01, | ||
testInt: 123, | ||
testIntPercent: 15, | ||
testInt64: 12345678901234567890, | ||
testRaw: "AAMBAQEBAQEBAQEBAQA=", | ||
testDate: "2023-02-20", | ||
testDatetime: "2023-02-20T11:11:11.111", | ||
testLogical: true, | ||
}, | ||
{ | ||
ROWID: "0x0000000000002c02", | ||
testCharacter: "record no.2", | ||
testDecimal: 0.11, | ||
testInt: 123, | ||
testIntPercent: 15, | ||
testInt64: 12345678901234567890, | ||
testRaw: "AAMBAQEBAQEBAQEBAQA=", | ||
testDate: "2023-02-20", | ||
testDatetime: "2023-02-20T11:11:11.111", | ||
testLogical: false, | ||
}, | ||
{ | ||
ROWID: "0x0000000000002c03", | ||
testCharacter: "record no.3", | ||
testDecimal: 0.22, | ||
testInt: -123, | ||
testIntPercent: 15, | ||
testInt64: 12345678901234567890, | ||
testRaw: "AAMBAQEBAQEBAQEBAQA=", | ||
testDate: "2023-02-20", | ||
testDatetime: "2023-02-20T11:11:11.111", | ||
testLogical: true, | ||
}, | ||
{ | ||
ROWID: "0x0000000000002c04", | ||
testCharacter: "record no.4", | ||
testDecimal: 0.33, | ||
testInt: 123, | ||
testIntPercent: 15, | ||
testInt64: 12345678901234567890, | ||
testRaw: "AAMBAQEBAQEBAQEBAQA=", | ||
testDate: "2023-02-20", | ||
testDatetime: "2023-02-20T11:11:11.111", | ||
testLogical: false, | ||
}, | ||
], | ||
}; | ||
|
||
export const testOutputDumpData: string = | ||
'"record no.1" .01 123 15 12345678901234567000 "AAMBAQEBAQEBAQEBAQA=" 02/20/23 2023-02-20T11:11:11.111 yes\r\n' + | ||
'"record no.2" .11 123 0.15 12345678901234567000 "AAMBAQEBAQEBAQEBAQA=" 02/20/23 2023-02-20T11:11:11.111 no\r\n' + | ||
'"record no.3" .22 -123 15 12345678901234567000 "AAMBAQEBAQEBAQEBAQA=" 02/20/23 2023-02-20T11:11:11.111 yes\r\n' + | ||
'"record no.4" .33 123 15 12345678901234567000 "AAMBAQEBAQEBAQEBAQA=" 02/20/23 2023-02-20T11:11:11.111 no\r\n'; | ||
|
||
export const testOutputTrailerInfo: string = | ||
"PSC\r\n" + | ||
"filename=testing\r\n" + | ||
"records=0000000000004\r\n" + | ||
"ldbname=testDb\r\n" + | ||
"timestamp=2023/02/20-15:36:36\r\n" + | ||
"numformat=44,46\r\n" + | ||
"dateformat=mdy-1950\r\n" + | ||
"map=NO-MAP\r\n" + | ||
"cpstream=UTF-8\r\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters