@gisce/ooui 2.14.0-alpha.1 → 2.14.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.14.0-alpha.1",
3
+ "version": "2.14.0-alpha.3",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
@@ -0,0 +1,7 @@
1
+ import CodeEditor from "./CodeEditor";
2
+
3
+ class JSONField extends CodeEditor {
4
+ _lang = "json";
5
+ }
6
+
7
+ export default JSONField;
@@ -38,6 +38,7 @@ import Avatar from "./Avatar";
38
38
  import Time from "./Time";
39
39
  import Alert from "./Alert";
40
40
  import Comments from "./Comments";
41
+ import JSONField from "./JSONField";
41
42
 
42
43
  class WidgetFactory {
43
44
  /**
@@ -173,12 +174,19 @@ class WidgetFactory {
173
174
  this._widgetClass = Comments;
174
175
  break;
175
176
 
177
+ case "json":
178
+ this._widgetClass = JSONField;
179
+ break;
180
+ case "arrow_steps":
181
+ this._widgetClass = JSONField;
182
+ break;
176
183
  default:
177
184
  break;
178
185
  }
179
186
  }
180
187
 
181
188
  createWidget(type: string, props: any) {
189
+ this._widgetClass = undefined;
182
190
  let finalType = type;
183
191
 
184
192
  this.setWidgetClass(type);
package/src/index.ts CHANGED
@@ -50,6 +50,7 @@ import Time from "./Time";
50
50
  import HTMLPreview from "./HTMLPreview";
51
51
  import Alert from "./Alert";
52
52
  import Comments from "./Comments";
53
+ import JSONField from "./JSONField";
53
54
 
54
55
  import {
55
56
  Graph,
@@ -136,4 +137,5 @@ export {
136
137
  YAxisOpts,
137
138
  MinMaxValues,
138
139
  Comments,
140
+ JSONField,
139
141
  };
@@ -5975,4 +5975,34 @@ describe("A Form", () => {
5975
5975
  const field_char = form.findById("field_char");
5976
5976
  expect(field_char!.domain!).toBe("[('value', '=', 'form')]");
5977
5977
  });
5978
+ it("a field with no supported type should fallback to field generic widget", () => {
5979
+ const fields = {
5980
+ field_char: {
5981
+ digits: [16, 2],
5982
+ is_function: true,
5983
+ readonly: 1,
5984
+ string: "Etapa",
5985
+ type: "json",
5986
+ views: {},
5987
+ widget: "arrow_steps",
5988
+ },
5989
+ };
5990
+
5991
+ const xmlViewForm = `<?xml version="1.0"?>
5992
+ <form string="Form1">
5993
+ <field name="field_char" widget="arrow_steps" colspan="4" nolabel="1"/>
5994
+ </form>`;
5995
+
5996
+ const form = new Form(fields);
5997
+ form.parse(xmlViewForm, {
5998
+ values: {
5999
+ field_char: "test",
6000
+ },
6001
+ });
6002
+
6003
+ const field_char = form.findById("field_char") as Field;
6004
+ expect(field_char).toBeDefined();
6005
+ expect(field_char?.type).toBe("arrow_steps");
6006
+ expect(field_char?.id).toBe("field_char");
6007
+ });
5978
6008
  });
@@ -0,0 +1,22 @@
1
+ import WidgetFactory from "../WidgetFactory";
2
+ import JSONField from "../JSONField";
3
+ import { it, expect, describe } from "vitest";
4
+
5
+ describe("A Json field", () => {
6
+ it("should be created by the widget factory", () => {
7
+ const widgetFactory = new WidgetFactory();
8
+ const props = {
9
+ name: "json_field",
10
+ };
11
+ const widget = widgetFactory.createWidget("json", props);
12
+ expect(widget).toBeInstanceOf(JSONField);
13
+ });
14
+ it("should have lang set to json as default", () => {
15
+ const widgetFactory = new WidgetFactory();
16
+ const props = {
17
+ name: "json_field",
18
+ };
19
+ const widget = widgetFactory.createWidget("json", props);
20
+ expect(widget.lang).toBe("json");
21
+ });
22
+ });
@@ -14,6 +14,7 @@ import {
14
14
  Time,
15
15
  HTMLPreview,
16
16
  Comments,
17
+ JSONField,
17
18
  } from "..";
18
19
 
19
20
  describe("A WidgetFactory", () => {
@@ -120,11 +121,19 @@ describe("A WidgetFactory", () => {
120
121
  expect(widget).toBeInstanceOf(HTMLPreview);
121
122
  expect(widget.type).toBe("html_preview");
122
123
  });
123
- it("should be albe to Comments type", () => {
124
+ it("should be able to Comments type", () => {
124
125
  const widgetFactory = new WidgetFactory();
125
126
  const props = {};
126
127
  const widget = widgetFactory.createWidget("comments_timeline", props);
127
128
  expect(widget).toBeInstanceOf(Comments);
128
129
  expect(widget.type).toBe("comments_timeline");
129
130
  });
131
+ // Add a test for JSON field type
132
+ it("should be able to retrieve JSON type", () => {
133
+ const widgetFactory = new WidgetFactory();
134
+ const props = {};
135
+ const widget = widgetFactory.createWidget("json", props);
136
+ expect(widget).toBeInstanceOf(JSONField);
137
+ expect(widget.type).toBe("json");
138
+ });
130
139
  });