Skip to content

Commit

Permalink
feat(autorefresh): set property as boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
ecarreras committed Nov 27, 2024
1 parent 5f2cbcf commit 70a6880
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
13 changes: 6 additions & 7 deletions src/Field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Widget from "./Widget";
import { replaceEntities, isTrue } from "./helpers/attributeParser";
import { parseBoolAttribute } from "./helpers/nodeParser";

class Field extends Widget {
/**
Expand Down Expand Up @@ -125,12 +126,12 @@ class Field extends Widget {
return this._fieldType;
}

_autoRefresh?: number = undefined;
get autoRefresh(): number | undefined {
return this._autoRefresh;
_autoRefresh?: boolean = false;
get autoRefresh(): boolean {
return this._autoRefresh ?? false;
}

set autoRefresh(value: number | undefined) {
set autoRefresh(value: boolean) {
this._autoRefresh = value;
}

Expand Down Expand Up @@ -202,9 +203,7 @@ class Field extends Widget {
this.tooltipInline = isTrue(props.help_inline);
}
if (props.autorefresh) {
this.autoRefresh = isNaN(+props.autorefresh)
? undefined
: +props.autorefresh;
this.autoRefresh = parseBoolAttribute(props.autorefresh);
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/spec/Field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@ import Field from "../Field";

describe("Field", () => {
describe("with the autoRefresh property", () => {
it("should work with integer", () => {
const props = {
autorefresh: 10,
};
it("should be false as default", () => {
const props = {};
const field = new Field(props);
expect(field.autoRefresh).toBe(10);
expect(field.autoRefresh).toBe(false);
});
it("should work with text", () => {
const props = {
autorefresh: "10",
autorefresh: "1",
};
const field = new Field(props);
expect(field.autoRefresh).toBe(10);
expect(field.autoRefresh).toBe(true);
});
describe("if autorefresh is not a valid number", () => {
it("should return undefined", () => {
describe("if autorefresh is not a valid boold", () => {
it("should return false", () => {
const props = {
autorefresh: "abc",
};
const field = new Field(props);
expect(field.autoRefresh).toBe(undefined);
expect(field.autoRefresh).toBe(false);
});
});
it("should return true for readOnly if autoRefresh is set", () => {
const props = {
autorefresh: 10,
autorefresh: true,
};
const field = new Field(props);
expect(field.readOnly).toBe(true);
Expand Down

0 comments on commit 70a6880

Please sign in to comment.