Files
docx-js/src/file/checkbox/checkbox.spec.ts
dependabot[bot] 2381ba8a05 build(deps-dev): bump eslint from 8.57.1 to 9.13.0 (#2792)
* build(deps-dev): bump eslint from 8.57.1 to 9.13.0

Bumps [eslint](https://github.com/eslint/eslint) from 8.57.1 to 9.13.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.57.1...v9.13.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Upgrade EsLint

* Fix all new lint errors

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
2024-10-21 03:57:15 +01:00

215 lines
8.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { CheckBox } from "./checkbox";
describe("CheckBox", () => {
describe("#constructor()", () => {
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);
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 CheckBox with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => {
const checkBox = new CheckBox({
alias: "Custom 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": [
{
"w:alias": {
_attr: {
"w:val": "Custom Checkbox",
},
},
},
{
"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 CheckBox with proper root, custom state, and no alias", () => {
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",
},
},
},
],
},
],
},
],
});
});
});
});