@arquimedes.co/eureka-forms 3.0.54 → 3.0.55

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.
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,78 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import { describe, expect, it } from 'vitest';
4
+ import '@testing-library/jest-dom';
5
+ import App from './App';
6
+ import CBRFormStepTypes from '../constants/CBRFormStepTypes';
7
+ const INCIDENT = {
8
+ idSpaceStep: 'CBR_TIPO_ESPACIO-PYDqn',
9
+ idElementStep: 'CBR_LOCATIVAS-fp6xL',
10
+ idCommentStep: 'CBR_COMENTARIO-sQjpP',
11
+ num: 1,
12
+ };
13
+ const ID_SUB_ELEMENT_STEP = 'CBR_LOCATIVAS-G4S0r';
14
+ /** Shaped after a real posventa ticket: incidents are stored flat, keyed by generated step ids. */
15
+ const POSVENTA_VALUES = {
16
+ CBR_INCIDENCIAS: [INCIDENT],
17
+ [INCIDENT.idSpaceStep]: { id: '35365', label: 'Zona de Oficios' },
18
+ [INCIDENT.idCommentStep]: 'GRAN HUMEDAD!!!',
19
+ [INCIDENT.idElementStep]: { id: '06', label: 'CIELOS', subStep: ID_SUB_ELEMENT_STEP },
20
+ [ID_SUB_ELEMENT_STEP]: { id: '0601', label: 'Cielo Falso' },
21
+ };
22
+ const POSVENTA_FORM = {
23
+ name: 'Formulario PosVenta',
24
+ firstSection: 'FIRST',
25
+ sections: {
26
+ FIRST: { id: 'FIRST', name: '', nextSection: null, steps: ['CBR_INCIDENCIAS'] },
27
+ },
28
+ steps: {
29
+ CBR_INCIDENCIAS: {
30
+ id: 'CBR_INCIDENCIAS',
31
+ type: CBRFormStepTypes.CBR_INCIDENCIAS,
32
+ label: 'Incidencias',
33
+ description: null,
34
+ addBtnLabel: 'Agregar Incidencia',
35
+ required: true,
36
+ unitLabel: 'Incidencia',
37
+ dependencies: ['CBR_PROYECTO'],
38
+ spaceStep: {
39
+ label: 'Espacio',
40
+ description: null,
41
+ size: 1,
42
+ required: true,
43
+ showIcon: true,
44
+ searchable: true,
45
+ },
46
+ commentStep: { label: 'Comentario', description: null, size: 1, required: true },
47
+ elementStep: {
48
+ label: 'Elemento',
49
+ description: null,
50
+ size: 1,
51
+ required: true,
52
+ showIcon: true,
53
+ searchable: true,
54
+ subStep: {
55
+ label: 'Elemento Hijo',
56
+ description: null,
57
+ size: 1,
58
+ required: true,
59
+ showIcon: true,
60
+ searchable: true,
61
+ },
62
+ },
63
+ },
64
+ },
65
+ size: { blockNum: 4, blockSize: 210, spacingSize: 20 },
66
+ };
67
+ describe('CBR posventa postview', () => {
68
+ it('renders the submitted incidents read-only', async () => {
69
+ const { container } = render(_jsx(App, { formData: POSVENTA_FORM, valuesData: POSVENTA_VALUES, idOrganization: 'melendez', postview: true, internal: true, isWidget: true, editable: false }));
70
+ await waitFor(() => {
71
+ expect(container.textContent).toContain('Incidencia 1');
72
+ });
73
+ expect(container.textContent).toContain('GRAN HUMEDAD!!!');
74
+ expect(screen.getByDisplayValue('Zona de Oficios')).toBeInTheDocument();
75
+ expect(screen.getByDisplayValue('CIELOS')).toBeInTheDocument();
76
+ expect(screen.getByDisplayValue('Cielo Falso')).toBeInTheDocument();
77
+ });
78
+ });
@@ -1,17 +1,19 @@
1
1
  import CBRFormStepTypes from '../constants/CBRFormStepTypes';
2
2
  export const calcCbrForm = (form, formValues) => {
3
+ /** Callers pass the form straight out of `createNextState`, whose result Immer deep-freezes. */
4
+ const steps = { ...form.steps };
3
5
  for (const step of Object.values(form.steps)) {
4
6
  if (step.type === CBRFormStepTypes.CBR_INCIDENCIAS) {
5
7
  const incidentStep = step;
6
8
  const incValue = formValues[incidentStep.id ?? ''];
7
9
  if (incValue) {
8
10
  for (const incident of incValue) {
9
- handleAddIncident(incident, incidentStep, form.steps, formValues);
11
+ handleAddIncident(incident, incidentStep, steps, formValues);
10
12
  }
11
13
  }
12
14
  }
13
15
  }
14
- return form;
16
+ return { ...form, steps };
15
17
  };
16
18
  const handleAddIncident = (incident, step, steps, formValues) => {
17
19
  const spaceStep = {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,123 @@
1
+ import { createNextState } from '@reduxjs/toolkit';
2
+ import { describe, expect, test } from 'vitest';
3
+ import CBRFormStepTypes from '../constants/CBRFormStepTypes';
4
+ import { calcCbrForm } from './CBRFunctions';
5
+ const INCIDENT = {
6
+ idSpaceStep: 'CBR_TIPO_ESPACIO-space1',
7
+ idElementStep: 'CBR_LOCATIVAS-element1',
8
+ idCommentStep: 'CBR_COMENTARIO-comment1',
9
+ num: 1,
10
+ };
11
+ /** Second element level, reached through the element value's `subStep` pointer. */
12
+ const ID_SUB_ELEMENT_STEP = 'CBR_LOCATIVAS-subElement1';
13
+ const FORM_VALUES = {
14
+ CBR_INCIDENCIAS: [INCIDENT],
15
+ [INCIDENT.idSpaceStep]: { id: '35362', label: 'Sala' },
16
+ [INCIDENT.idCommentStep]: 'GRAN HUMEDAD',
17
+ [INCIDENT.idElementStep]: {
18
+ id: '06',
19
+ label: 'CIELOS',
20
+ subStep: ID_SUB_ELEMENT_STEP,
21
+ },
22
+ [ID_SUB_ELEMENT_STEP]: { id: '0601', label: 'Cielo Falso' },
23
+ };
24
+ function buildForm() {
25
+ return {
26
+ name: 'Formulario PosVenta',
27
+ firstSection: 'FIRST',
28
+ sections: {
29
+ FIRST: {
30
+ id: 'FIRST',
31
+ name: '',
32
+ nextSection: null,
33
+ steps: ['CBR_INCIDENCIAS'],
34
+ },
35
+ },
36
+ steps: {
37
+ CBR_INCIDENCIAS: {
38
+ id: 'CBR_INCIDENCIAS',
39
+ type: CBRFormStepTypes.CBR_INCIDENCIAS,
40
+ label: 'Incidencias',
41
+ description: null,
42
+ addBtnLabel: 'Agregar',
43
+ required: true,
44
+ unitLabel: 'Incidencia',
45
+ dependencies: ['CBR_PROYECTO'],
46
+ spaceStep: {
47
+ label: 'Espacio',
48
+ description: null,
49
+ size: 1,
50
+ required: true,
51
+ showIcon: true,
52
+ searchable: true,
53
+ },
54
+ commentStep: {
55
+ label: 'Comentario',
56
+ description: null,
57
+ size: 1,
58
+ required: true,
59
+ },
60
+ elementStep: {
61
+ label: 'Elemento',
62
+ description: null,
63
+ size: 1,
64
+ required: true,
65
+ showIcon: true,
66
+ searchable: true,
67
+ subStep: {
68
+ label: 'Elemento Hijo',
69
+ description: null,
70
+ size: 1,
71
+ required: true,
72
+ showIcon: true,
73
+ searchable: true,
74
+ },
75
+ },
76
+ },
77
+ },
78
+ size: { blockNum: 4, blockSize: 210, spacingSize: 20 },
79
+ };
80
+ }
81
+ describe('calcCbrForm', function () {
82
+ test('expands every incident into its own space, comment and element steps', () => {
83
+ const result = calcCbrForm(buildForm(), FORM_VALUES);
84
+ expect(result.steps[INCIDENT.idSpaceStep]).toMatchObject({
85
+ id: INCIDENT.idSpaceStep,
86
+ type: CBRFormStepTypes.CBR_TIPO_ESPACIO,
87
+ });
88
+ expect(result.steps[INCIDENT.idCommentStep]).toMatchObject({
89
+ id: INCIDENT.idCommentStep,
90
+ type: CBRFormStepTypes.CBR_COMENTARIO,
91
+ });
92
+ expect(result.steps[INCIDENT.idElementStep]).toMatchObject({
93
+ id: INCIDENT.idElementStep,
94
+ type: CBRFormStepTypes.CBR_LOCATIVAS,
95
+ subStep: ID_SUB_ELEMENT_STEP,
96
+ });
97
+ expect(result.steps[ID_SUB_ELEMENT_STEP]).toMatchObject({
98
+ id: ID_SUB_ELEMENT_STEP,
99
+ type: CBRFormStepTypes.CBR_LOCATIVAS,
100
+ });
101
+ });
102
+ test('leaves the form it was given untouched', () => {
103
+ const form = buildForm();
104
+ calcCbrForm(form, FORM_VALUES);
105
+ expect(Object.keys(form.steps)).toEqual(['CBR_INCIDENCIAS']);
106
+ });
107
+ /**
108
+ * The caller hands the form straight out of `createNextState`, whose result Immer deep-freezes, so
109
+ * expanding the incidents by writing into that same `steps` object throws and leaves the form stuck
110
+ * loading forever.
111
+ */
112
+ test('expands a form frozen by createNextState', () => {
113
+ const frozenForm = createNextState(buildForm(), (draft) => {
114
+ draft.steps.CBR_INCIDENCIAS.idSection = 'FIRST';
115
+ });
116
+ expect(Object.isFrozen(frozenForm.steps)).toBe(true);
117
+ const result = calcCbrForm(frozenForm, FORM_VALUES);
118
+ expect(result.steps[INCIDENT.idSpaceStep]).toBeDefined();
119
+ expect(result.steps[INCIDENT.idCommentStep]).toBeDefined();
120
+ expect(result.steps[INCIDENT.idElementStep]).toBeDefined();
121
+ expect(result.steps[ID_SUB_ELEMENT_STEP]).toBeDefined();
122
+ });
123
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "3.0.54",
4
+ "version": "3.0.55",
5
5
  "scripts": {
6
6
  "watch": "tsgo --noEmit --watch --project tsconfig.app.json",
7
7
  "start": "vite",