Skip to content

Commit b01068c

Browse files
committed
Convert form/field/AfterSetValueSequence.mjs Test from Siesta to Playwright #7281
1 parent ed6dc7b commit b01068c

3 files changed

Lines changed: 122 additions & 3 deletions

File tree

.github/ISSUE/epic-enhance-workflow-with-mandatory-unit-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The primary goal is to prevent regressions, especially in the complex core modul
8282
- **Done:** ticket-convert-config-memoryleak-test.md
8383
- **Done:** ticket-convert-config-multilevelhierarchy-test.md
8484
- **Done:** ticket-convert-core-effectbatching-test.md
85-
- **To Do:** ticket-convert-form-field-aftersetvaluesequence-test.md
85+
- **Done:** ticket-convert-form-field-aftersetvaluesequence-test.md
8686
- **To Do:** ticket-convert-functional-button-test.md
8787
- **To Do:** ticket-convert-functional-htmltemplatecomponent-test.md
8888
- **To Do:** ticket-convert-functional-parse5processor-test.md

.github/ISSUE/ticket-convert-form-field-aftersetvaluesequence-test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
GH ticket id: #7281
44

5-
**Assignee:**
6-
**Status:** To Do
5+
**Assignee:** tobiu
6+
**Status:** Done
77

88
**Parent Epic:** epic-enhance-workflow-with-mandatory-unit-testing.md
99

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { setup } from '../../../setup.mjs';
2+
3+
const appName = 'AfterSetValueSequence';
4+
5+
setup({
6+
appConfig: {
7+
name: appName
8+
}
9+
});
10+
11+
import { test, expect } from '@playwright/test';
12+
13+
import Neo from '../../../../../src/Neo.mjs';
14+
import * as core from '../../../../../src/core/_export.mjs';
15+
import InstanceManager from '../../../../../src/manager/Instance.mjs';
16+
import ComboBox from '../../../../../src/form/field/ComboBox.mjs';
17+
import Text from '../../../../../src/form/field/Text.mjs';
18+
19+
class MyComboBox extends ComboBox {
20+
static config = {
21+
className: 'Test.MyComboBox',
22+
23+
displayField: 'country',
24+
valueField : 'country',
25+
value : 'Angola', // Initial value
26+
store: {
27+
keyProperty: 'country',
28+
model: {
29+
fields: [
30+
{name: 'country', type: 'String'}
31+
]
32+
},
33+
data : [
34+
{country: 'Angola'},
35+
{country: 'Algeria'}
36+
]
37+
}
38+
}
39+
40+
afterSetValue(value, oldValue) {
41+
this.executionOrder.push('MyComboBox.afterSetValue');
42+
super.afterSetValue(value, oldValue);
43+
}
44+
}
45+
MyComboBox = Neo.setupClass(MyComboBox);
46+
47+
class MyTextField extends Text {
48+
static config = {
49+
className: 'Test.MyTextField'
50+
}
51+
52+
afterSetValue(value, oldValue) {
53+
this.executionOrder.push('MyTextField.afterSetValue');
54+
super.afterSetValue(value, oldValue);
55+
}
56+
}
57+
MyTextField = Neo.setupClass(MyTextField);
58+
59+
60+
test.describe('Neo.form.field.AfterSetValueSequence', () => {
61+
test('TextField afterSetValue sequence should fire change event after the full method chain', async () => {
62+
const executionOrder = [];
63+
64+
const field = Neo.create(MyTextField, {
65+
// pass array to instance so it's available in afterSetValue
66+
executionOrder
67+
});
68+
69+
field.on('change', (changeEvent) => {
70+
executionOrder.push('change event');
71+
expect(changeEvent.value).toBe('new value');
72+
});
73+
74+
// Trigger the change
75+
field.value = 'new value';
76+
77+
// Assert the order
78+
expect(executionOrder).toEqual(['MyTextField.afterSetValue', 'MyTextField.afterSetValue', 'change event']);
79+
expect(field.value).toBe('new value');
80+
81+
field.destroy();
82+
});
83+
84+
test('ComboBox afterSetValue sequence should fire change event after the full method chain', async () => {
85+
const executionOrder = [];
86+
87+
const field = Neo.create(MyComboBox, {
88+
// pass array to instance so it's available in afterSetValue
89+
executionOrder
90+
});
91+
92+
expect(Neo.isRecord(field.value)).toBe(true);
93+
expect(field.value.country).toBe('Angola');
94+
95+
field.on('change', (changeEvent) => {
96+
executionOrder.push('combo change event');
97+
98+
expect(Neo.isRecord(field.value)).toBe(true);
99+
expect(field.value.country).toBe('Algeria');
100+
});
101+
102+
// Trigger the change
103+
field.value = 'Algeria';
104+
105+
expect(Neo.isRecord(field.value)).toBe(true);
106+
expect(field.value.country).toBe('Algeria');
107+
108+
// Required since change events are delayed in ComboBox
109+
await field.timeout(35);
110+
111+
// Assert the order
112+
expect(executionOrder).toEqual(['MyComboBox.afterSetValue', 'MyComboBox.afterSetValue', 'combo change event']);
113+
114+
expect(Neo.isRecord(field.value)).toBe(true);
115+
expect(field.value.country).toBe('Algeria');
116+
117+
field.destroy();
118+
});
119+
});

0 commit comments

Comments
 (0)