Skip to content

Commit 7ef5699

Browse files
authored
CardView - contentView - hotfixes (#30170)
1 parent aef37ed commit 7ef5699

File tree

92 files changed

+793
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+793
-249
lines changed
118 Bytes
-1.06 KB
118 Bytes
-1.06 KB
-24 Bytes
17 Bytes
-94 Bytes
337 Bytes
-2.59 KB
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/* eslint-disable no-plusplus */
2+
import CardView from 'devextreme-testcafe-models/cardView';
3+
import { ClientFunction } from 'testcafe';
4+
import url from '../../helpers/getPageUrl';
5+
import { createWidget } from '../../helpers/createWidget';
6+
7+
fixture.disablePageReloads`CardView - ContentView - events`
8+
.page(url(__dirname, '../container.html'));
9+
10+
const CARD_VIEW_SELECTOR = '#container';
11+
12+
declare global {
13+
interface Window {
14+
dxCardViewEventTest: any;
15+
}
16+
}
17+
18+
const CONFIG = {
19+
dataSource: [
20+
{ caption1: 'value11', caption2: 'value21', caption3: 'value31' },
21+
{ caption1: 'value12', caption2: 'value22', caption3: 'value32' },
22+
{ caption1: 'value13', caption2: 'value23', caption3: 'value33' },
23+
{ caption1: 'value14', caption2: 'value24', caption3: 'value34' },
24+
{ caption1: 'value15', caption2: 'value25', caption3: 'value35' },
25+
],
26+
onCardClick(e) {
27+
window.dxCardViewEventTest ??= {};
28+
window.dxCardViewEventTest.onCardClick ??= [];
29+
window.dxCardViewEventTest.onCardClick.push(e);
30+
},
31+
onCardDblClick(e) {
32+
window.dxCardViewEventTest ??= {};
33+
window.dxCardViewEventTest.onCardDblClick ??= [];
34+
window.dxCardViewEventTest.onCardDblClick.push(e);
35+
},
36+
onCardPrepared(e) {
37+
window.dxCardViewEventTest ??= {};
38+
window.dxCardViewEventTest.onCardPrepared ??= [];
39+
window.dxCardViewEventTest.onCardPrepared.push(e);
40+
},
41+
onFieldCaptionClick(e) {
42+
window.dxCardViewEventTest ??= {};
43+
window.dxCardViewEventTest.onFieldCaptionClick ??= [];
44+
window.dxCardViewEventTest.onFieldCaptionClick.push(e);
45+
},
46+
onFieldCaptionDblClick(e) {
47+
window.dxCardViewEventTest ??= {};
48+
window.dxCardViewEventTest.onFieldCaptionDblClick ??= [];
49+
window.dxCardViewEventTest.onFieldCaptionDblClick.push(e);
50+
},
51+
onFieldCaptionPrepared(e) {
52+
window.dxCardViewEventTest ??= {};
53+
window.dxCardViewEventTest.onFieldCaptionPrepared ??= [];
54+
window.dxCardViewEventTest.onFieldCaptionPrepared.push(e);
55+
},
56+
onFieldValueClick(e) {
57+
window.dxCardViewEventTest ??= {};
58+
window.dxCardViewEventTest.onFieldValueClick ??= [];
59+
window.dxCardViewEventTest.onFieldValueClick.push(e);
60+
},
61+
onFieldValueDblClick(e) {
62+
window.dxCardViewEventTest ??= {};
63+
window.dxCardViewEventTest.onFieldValueDblClick ??= [];
64+
window.dxCardViewEventTest.onFieldValueDblClick.push(e);
65+
},
66+
onFieldValuePrepared(e) {
67+
window.dxCardViewEventTest ??= {};
68+
window.dxCardViewEventTest.onFieldValuePrepared ??= [];
69+
window.dxCardViewEventTest.onFieldValuePrepared.push(e);
70+
},
71+
onCardHoverChanged(e) {
72+
window.dxCardViewEventTest ??= {};
73+
window.dxCardViewEventTest.onCardHoverChanged ??= [];
74+
window.dxCardViewEventTest.onCardHoverChanged.push(e);
75+
},
76+
onDisposing() {
77+
delete window.dxCardViewEventTest;
78+
},
79+
};
80+
81+
interface TestModel {
82+
eventName: string;
83+
84+
action: (t: TestController, cardView: CardView) => Promise<void>;
85+
86+
additionalAssertOnClient?: (event: any) => boolean;
87+
88+
eventCount?: number;
89+
}
90+
91+
function testFactory({
92+
eventName,
93+
action,
94+
additionalAssertOnClient,
95+
eventCount = 1,
96+
}: TestModel) {
97+
test(eventName, async (t) => {
98+
const cardView = new CardView(CARD_VIEW_SELECTOR);
99+
100+
await action(t, cardView);
101+
102+
const actualEventCount = await ClientFunction(
103+
() => window.dxCardViewEventTest[eventName].length,
104+
{ dependencies: { eventName } },
105+
)();
106+
107+
await t.expect(actualEventCount).eql(eventCount);
108+
109+
if (additionalAssertOnClient) {
110+
const result = await ClientFunction(
111+
() => additionalAssertOnClient(
112+
window.dxCardViewEventTest[eventName][0],
113+
),
114+
{ dependencies: { additionalAssertOnClient, eventName } },
115+
)();
116+
117+
await t.expect(result).ok();
118+
}
119+
}).before(async () => createWidget('dxCardView', CONFIG));
120+
}
121+
122+
function assertCardInfo(event) {
123+
if (event.card.index !== 0) {
124+
return false;
125+
}
126+
127+
if (!event.cardElement) {
128+
return false;
129+
}
130+
131+
return true;
132+
}
133+
134+
testFactory({
135+
eventName: 'onCardClick',
136+
async action(t, cardView) {
137+
await t.click(cardView.getCard(0).element);
138+
},
139+
additionalAssertOnClient: assertCardInfo,
140+
});
141+
testFactory({
142+
eventName: 'onCardDblClick',
143+
async action(t, cardView) {
144+
await t.doubleClick(cardView.getCard(0).element);
145+
},
146+
additionalAssertOnClient: assertCardInfo,
147+
});
148+
testFactory({
149+
eventName: 'onCardPrepared',
150+
async action() {
151+
// pass (we just need render)
152+
},
153+
additionalAssertOnClient: assertCardInfo,
154+
eventCount: 5,
155+
});
156+
157+
function assertFieldCaptionInfo(event) {
158+
if (event.field.index !== 0) {
159+
return false;
160+
}
161+
162+
if (event.field.card.index !== 0) {
163+
return false;
164+
}
165+
166+
if (!event.fieldCaptionElement) {
167+
return false;
168+
}
169+
170+
return true;
171+
}
172+
173+
testFactory({
174+
eventName: 'onFieldCaptionClick',
175+
async action(t, cardView) {
176+
await t.click(cardView.getCard(0).getFieldCaptionCell('Caption 1'));
177+
},
178+
additionalAssertOnClient: assertFieldCaptionInfo,
179+
});
180+
testFactory({
181+
eventName: 'onFieldCaptionDblClick',
182+
async action(t, cardView) {
183+
await t.doubleClick(cardView.getCard(0).getFieldCaptionCell('Caption 1'));
184+
},
185+
additionalAssertOnClient: assertFieldCaptionInfo,
186+
});
187+
testFactory({
188+
eventName: 'onFieldCaptionPrepared',
189+
async action() {
190+
// pass (we just need render)
191+
},
192+
additionalAssertOnClient: assertFieldCaptionInfo,
193+
eventCount: 15,
194+
});
195+
196+
function assertFieldValueInfo(event) {
197+
if (event.field.index !== 0) {
198+
return false;
199+
}
200+
201+
if (event.field.card.index !== 0) {
202+
return false;
203+
}
204+
205+
if (!event.fieldValueElement) {
206+
return false;
207+
}
208+
209+
return true;
210+
}
211+
212+
testFactory({
213+
eventName: 'onFieldValueClick',
214+
async action(t, cardView) {
215+
await t.click(cardView.getCard(0).getFieldValueCell('Caption 1'));
216+
},
217+
additionalAssertOnClient: assertFieldValueInfo,
218+
});
219+
testFactory({
220+
eventName: 'onFieldValueDblClick',
221+
async action(t, cardView) {
222+
await t.doubleClick(cardView.getCard(0).getFieldValueCell('Caption 1'));
223+
},
224+
additionalAssertOnClient: assertFieldValueInfo,
225+
});
226+
testFactory({
227+
eventName: 'onFieldValuePrepared',
228+
async action() {
229+
// pass (we just need render)
230+
},
231+
additionalAssertOnClient: assertFieldValueInfo,
232+
eventCount: 15,
233+
});

0 commit comments

Comments
 (0)