@@ -3,7 +3,7 @@ import { mount } from '@vue/test-utils';
33import * as events from 'devextreme/events' ;
44import config from 'devextreme/core/config' ;
55import {
6- App , createVNode , defineComponent , h , nextTick , renderSlot ,
6+ App , createVNode , defineComponent , h , nextTick , renderSlot , ref ,
77} from 'vue' ;
88import { createRouter , createWebHistory } from 'vue-router' ;
99
@@ -18,8 +18,8 @@ import { getNodeOptions } from '../vue-helper';
1818import {
1919 prepareComponentConfig ,
2020 prepareExtensionComponentConfig ,
21- prepareConfigurationComponentConfig
22- } from " ../index" ;
21+ prepareConfigurationComponentConfig ,
22+ } from ' ../index' ;
2323
2424interface CustomApp extends App {
2525 test : string ;
@@ -156,6 +156,111 @@ describe('component rendering', () => {
156156 expect ( wrapper . element . className ) . toBe ( 'my-class my-class2' ) ;
157157 } ) ;
158158
159+ describe ( 'correctly forwards classes' , ( ) => {
160+ it ( 'forwards correct attrs in the render method' , async ( ) => {
161+ const component = defineComponent ( {
162+ template :
163+ `
164+ <test-component id="component" class="custom-class" :class="{'dx-chat-disabled': isDisabled}"></test-component>
165+ <button @click="toggleDisabledState($event)">Click me</button>
166+ ` ,
167+ components : { TestComponent } ,
168+ setup ( ) {
169+ const isDisabled = ref ( false ) ;
170+
171+ function toggleDisabledState ( ) {
172+ isDisabled . value = ! isDisabled . value ;
173+ }
174+
175+ return { isDisabled, toggleDisabledState } ;
176+ } ,
177+ } ) ;
178+
179+ const wrapper = mount ( component ) ;
180+
181+ const componentContainer = wrapper . find ( '#component' ) ;
182+
183+ await wrapper . find ( 'button' ) . trigger ( 'click' ) ;
184+
185+ expect ( componentContainer . element . className ) . toBe ( 'custom-class dx-chat-disabled' ) ;
186+
187+ const attrsPassedToVNodeInRenderMethod = wrapper . vm . $ . subTree ?. children ?. [ 0 ] ?. component ?. subTree ?. props ?. class ;
188+
189+ const expectedClasses = 'custom-class dx-chat-disabled' ;
190+
191+ expect ( attrsPassedToVNodeInRenderMethod ) . toBe ( expectedClasses ) ;
192+ expect ( componentContainer . element . className ) . toBe ( expectedClasses ) ;
193+ } ) ;
194+
195+ it ( 'forwards correct classes when a dynamic and static attrs were defined' , async ( ) => {
196+ const component = defineComponent ( {
197+ template :
198+ `
199+ <test-component id="component" class="custom-class" :class="{'dx-chat-disabled': isDisabled}"></test-component>
200+ <button @click="toggleDisabledState($event)">Click me</button>
201+ ` ,
202+ components : { TestComponent } ,
203+ setup ( ) {
204+ const isDisabled = ref ( false ) ;
205+
206+ function toggleDisabledState ( ) {
207+ isDisabled . value = ! isDisabled . value ;
208+ }
209+
210+ return { isDisabled, toggleDisabledState } ;
211+ } ,
212+ } ) ;
213+
214+ const wrapper = mount ( component ) ;
215+
216+ const componentContainer = wrapper . find ( '#component' ) ;
217+
218+ componentContainer . element . classList . add ( 'should-be-removed-class' , 'dx-chat' , 'dx-hover' ) ;
219+
220+ await wrapper . find ( 'button' ) . trigger ( 'click' ) ;
221+
222+ expect ( componentContainer . element . className ) . toBe ( 'custom-class dx-chat dx-hover dx-chat-disabled' ) ;
223+
224+ await wrapper . find ( 'button' ) . trigger ( 'click' ) ;
225+
226+ expect ( componentContainer . element . className ) . toBe ( 'custom-class dx-chat dx-hover' ) ;
227+ } ) ;
228+
229+ it ( 'forwards correct classes when only a dynamic attr was defined' , async ( ) => {
230+ const component = defineComponent ( {
231+ template :
232+ `
233+ <test-component id="component" :class="{'dx-chat-disabled': isDisabled}"></test-component>
234+ <button @click="toggleDisabledState($event)">Click me</button>
235+ ` ,
236+ components : { TestComponent } ,
237+ setup ( ) {
238+ const isDisabled = ref ( false ) ;
239+
240+ function toggleDisabledState ( ) {
241+ isDisabled . value = ! isDisabled . value ;
242+ }
243+
244+ return { isDisabled, toggleDisabledState } ;
245+ } ,
246+ } ) ;
247+
248+ const wrapper = mount ( component ) ;
249+
250+ const componentContainer = wrapper . find ( '#component' ) ;
251+
252+ componentContainer . element . classList . add ( 'should-be-removed-class' , 'dx-chat' , 'dx-hover' ) ;
253+
254+ await wrapper . find ( 'button' ) . trigger ( 'click' ) ;
255+
256+ expect ( componentContainer . element . className ) . toBe ( 'dx-chat dx-hover dx-chat-disabled' ) ;
257+
258+ await wrapper . find ( 'button' ) . trigger ( 'click' ) ;
259+
260+ expect ( componentContainer . element . className ) . toBe ( 'dx-chat dx-hover' ) ;
261+ } ) ;
262+ } ) ;
263+
159264 it ( 'passes styles to element' , ( ) => {
160265 const vm = defineComponent ( {
161266 template : '<test-component style=\'height: 10px; width: 20px;\'/>' ,
@@ -1213,9 +1318,9 @@ describe('component rendering', () => {
12131318
12141319 mount ( vm ) ;
12151320
1216- const container = document . createElement ( " div" ) ;
1321+ const container = document . createElement ( ' div' ) ;
12171322 renderItemTemplate ( { } , container ) ;
1218- events . triggerHandler ( container . children [ 0 ] , " dxremove" ) ;
1323+ events . triggerHandler ( container . children [ 0 ] , ' dxremove' ) ;
12191324
12201325 expect ( container . children . length ) . toEqual ( 0 ) ;
12211326 } ) ;
@@ -1234,9 +1339,9 @@ describe('component rendering', () => {
12341339
12351340 mount ( vm ) ;
12361341
1237- const container = document . createElement ( " div" ) ;
1342+ const container = document . createElement ( ' div' ) ;
12381343 renderItemTemplate ( { } , container ) ;
1239- events . triggerHandler ( container . children [ 0 ] , " dxremove" ) ;
1344+ events . triggerHandler ( container . children [ 0 ] , ' dxremove' ) ;
12401345
12411346 expect ( container . children . length ) . toEqual ( 0 ) ;
12421347 } ) ;
@@ -1371,7 +1476,7 @@ describe('component rendering', () => {
13711476 const vm = defineComponent ( {
13721477 template : `<test-component>
13731478 <template #item="{ data }">
1374- <div class='custom -class'></div>
1479+ <div class='should-be-removed -class'></div>
13751480 </template>
13761481 </test-component>` ,
13771482 components : {
@@ -1382,7 +1487,7 @@ describe('component rendering', () => {
13821487 mount ( vm ) ;
13831488 const renderedTemplate = renderItemTemplate ( { } ) ;
13841489
1385- expect ( renderedTemplate . className ) . toBe ( `custom -class ${ DX_TEMPLATE_WRAPPER } ` ) ;
1490+ expect ( renderedTemplate . className ) . toBe ( `should-be-removed -class ${ DX_TEMPLATE_WRAPPER } ` ) ;
13861491 } ) ;
13871492
13881493 it ( 'preserves custom-attrs' , ( ) => {
0 commit comments