From fa400bcf39fb50f4d6cdb1038732e9f6c4ca8d6a Mon Sep 17 00:00:00 2001 From: Juan D Date: Fri, 23 Jun 2023 13:06:18 -0400 Subject: [PATCH] update CheckBox and tests to handle optional alias field --- src/file/checkbox/checkbox.spec.ts | 24 +++++------------------- src/file/checkbox/checkbox.ts | 4 ++-- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/file/checkbox/checkbox.spec.ts b/src/file/checkbox/checkbox.spec.ts index 98e96e582b..a2df7819be 100644 --- a/src/file/checkbox/checkbox.spec.ts +++ b/src/file/checkbox/checkbox.spec.ts @@ -4,7 +4,7 @@ import { CheckBox } from "."; describe("CheckBox", () => { describe("#constructor()", () => { - it("should create a CheckBoxUtil with proper root and default values", () => { + it("should create a CheckBox with proper root and default values (no alias, no custom state)", () => { const checkBox = new CheckBox(); const tree = new Formatter().format(checkBox); @@ -13,13 +13,6 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ - { - "w:alias": { - _attr: { - "w:val": "Checkbox", - }, - }, - }, { "w14:checkbox": [ { @@ -73,7 +66,7 @@ describe("CheckBox", () => { ["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({ + const checkBox = new CheckBox("Custom Checkbox", { checked: true, checkedState: { value: inputChar, @@ -94,7 +87,7 @@ describe("CheckBox", () => { { "w:alias": { _attr: { - "w:val": "Checkbox", + "w:val": "Custom Checkbox", }, }, }, @@ -147,8 +140,8 @@ describe("CheckBox", () => { }); }); - it("should create a CheckBoxUtil with proper root and custom values", () => { - const checkBox = new CheckBox({ + it("should create a CheckBoxUtil with proper root, custom state, and no alias", () => { + const checkBox = new CheckBox(undefined, { checked: false, checkedState: { value: "2713", @@ -166,13 +159,6 @@ describe("CheckBox", () => { "w:sdt": [ { "w:sdtPr": [ - { - "w:alias": { - _attr: { - "w:val": "Checkbox", - }, - }, - }, { "w14:checkbox": [ { diff --git a/src/file/checkbox/checkbox.ts b/src/file/checkbox/checkbox.ts index f3ba88113c..c60690e3af 100644 --- a/src/file/checkbox/checkbox.ts +++ b/src/file/checkbox/checkbox.ts @@ -9,10 +9,10 @@ export class CheckBox extends XmlComponent { private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610"; private readonly DEFAULT_CHECKED_SYMBOL: string = "2612"; private readonly DEFAULT_FONT: string = "MS Gothic"; - public constructor(options?: ICheckboxSymbolOptions) { + public constructor(alias?: string, options?: ICheckboxSymbolOptions) { super("w:sdt"); - const properties = new StructuredDocumentTagProperties("Checkbox"); + const properties = new StructuredDocumentTagProperties(alias); properties.addChildElement(new CheckBoxUtil(options)); this.root.push(properties);