From cad4a5510bf981cd73f1b813933641f1ec8f68e6 Mon Sep 17 00:00:00 2001 From: Juan D Date: Thu, 22 Jun 2023 14:50:07 -0400 Subject: [PATCH] Create test files for CheckBox and CheckBoxUtil --- src/file/checkbox/checkbox-util.spec.ts | 85 ++++++++++ src/file/checkbox/checkbox.spec.ts | 204 ++++++++++++++++++++++++ 2 files changed, 289 insertions(+) create mode 100644 src/file/checkbox/checkbox-util.spec.ts create mode 100644 src/file/checkbox/checkbox.spec.ts diff --git a/src/file/checkbox/checkbox-util.spec.ts b/src/file/checkbox/checkbox-util.spec.ts new file mode 100644 index 0000000000..74fc74b820 --- /dev/null +++ b/src/file/checkbox/checkbox-util.spec.ts @@ -0,0 +1,85 @@ +import { describe, expect, it } from "vitest"; +import { Formatter } from "@export/formatter"; +import { CheckBoxUtil } from "."; + +describe("CheckBoxUtil", () => { + describe("#constructor()", () => { + it("should create a CheckBoxUtil with proper root and default values", () => { + const checkBoxUtil = new CheckBoxUtil(); + + const tree = new Formatter().format(checkBoxUtil); + + expect(tree).to.deep.equal({ + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2612", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2610", + }, + }, + }, + ], + }); + }); + + it("should create a CheckBoxUtil with proper structure and custom values", () => { + const checkBoxUtil = new CheckBoxUtil({ + checked: true, + checkedState: { + value: "2713", + font: "Segoe UI Symbol", + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBoxUtil); + + expect(tree).to.deep.equal({ + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "1", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2713", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts new file mode 100644 index 0000000000..6e00b100a0 --- /dev/null +++ b/src/file/checkbox/checkbox.spec.ts @@ -0,0 +1,204 @@ +import { describe, expect, it } from "vitest"; +import { Formatter } from "@export/formatter"; +import { CheckBox } from "."; + +describe("CheckBox", () => { + describe("#constructor()", () => { + it("should create a CheckBoxUtil with proper root and default values", () => { + const checkBox = new CheckBox(); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2612", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "MS Gothic", + "w14:val": "2610", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": "2610", + "w:font": "MS Gothic", + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it.each([ + ["2713", "Segoe UI Symbol", "2713", "Segoe UI Symbol"], + [undefined, undefined, "2612", "MS Gothic"], + ])("should create a CheckBoxUtil with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => { + const checkBox = new CheckBox({ + checked: true, + checkedState: { + value: inputChar, + font: inputFont, + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "1", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": actualFont, + "w14:val": actualChar, + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": actualChar, + "w:font": actualFont, + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it("should create a CheckBoxUtil with proper root and custom values", () => { + const checkBox = new CheckBox({ + checked: false, + checkedState: { + value: "2713", + font: "Segoe UI Symbol", + }, + uncheckedState: { + value: "2705", + font: "Segoe UI Symbol", + }, + }); + + const tree = new Formatter().format(checkBox); + + expect(tree).to.deep.equal({ + "w:sdt": [ + { + "w:sdtPr": [ + { + "w14:checkbox": [ + { + "w14:checked": { + _attr: { + "w14:val": "0", + }, + }, + }, + { + "w14:checkedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2713", + }, + }, + }, + { + "w14:uncheckedState": { + _attr: { + "w14:font": "Segoe UI Symbol", + "w14:val": "2705", + }, + }, + }, + ], + }, + ], + }, + { + "w:sdtContent": [ + { + "w:r": [ + { + "w:sym": { + _attr: { + "w:char": "2705", + "w:font": "Segoe UI Symbol", + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); + }); +});