Skip to content

Commit f2291b6

Browse files
authored
Navigation: get rid of outdated toSelector utility in tests (DevExpress#30454)
1 parent 79974b5 commit f2291b6

File tree

7 files changed

+101
-120
lines changed

7 files changed

+101
-120
lines changed

packages/devextreme/testing/tests/DevExpress.knockout/list.tests.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ const LIST_CLASS = 'dx-list';
3636
const LIST_ITEM_CLASS = 'dx-list-item';
3737
const LIST_ITEM_SELECTED_CLASS = 'dx-list-item-selected';
3838

39-
const toSelector = function(cssClass) {
40-
return '.' + cssClass;
41-
};
42-
4339
const moduleSetup = {
4440
beforeEach: function() {
4541
executeAsyncMock.setup();
@@ -70,7 +66,7 @@ QUnit.test('default with ko approach', function(assert) {
7066

7167
assert.ok($element.hasClass(LIST_CLASS));
7268

73-
const items = $element.find(toSelector(LIST_ITEM_CLASS));
69+
const items = $element.find(`.${LIST_ITEM_CLASS}`);
7470
assert.equal(items.length, 2);
7571
assert.ok(items.eq(0).hasClass(LIST_ITEM_CLASS));
7672
assert.ok(items.eq(1).hasClass(LIST_ITEM_CLASS));
@@ -121,11 +117,11 @@ QUnit.test('observableArray.push must refresh', function(assert) {
121117
this.element.attr('data-bind', 'dxList: { dataSource: data }');
122118
ko.applyBindings(vm, this.element[0]);
123119

124-
assert.equal(this.element.find(toSelector(LIST_ITEM_CLASS)).length, 1);
120+
assert.equal(this.element.find(`.${LIST_ITEM_CLASS}`).length, 1);
125121
assert.equal(this.element.dxList('instance').option('items').length, 1);
126122

127123
vm.data.push(2);
128-
assert.equal(this.element.find(toSelector(LIST_ITEM_CLASS)).length, 2);
124+
assert.equal(this.element.find(`.${LIST_ITEM_CLASS}`).length, 2);
129125
assert.equal(this.element.dxList('instance').option('items').length, 2);
130126
});
131127

@@ -211,7 +207,7 @@ QUnit.test('grouped list should respond on outside selectedItems changes', funct
211207
unselectActionFired += args.removedItems.length;
212208
});
213209

214-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
210+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
215211

216212
vm.selectedItems([
217213
{

packages/devextreme/testing/tests/DevExpress.ui.widgets/list.markup.tests.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ const LIST_GROUP_HEADER_CLASS = 'dx-list-group-header';
2727
const LIST_GROUP_BODY_CLASS = 'dx-list-group-body';
2828
const LIST_ITEM_BEFORE_BAG_CLASS = 'dx-list-item-before-bag';
2929

30-
const toSelector = cssClass => {
31-
return '.' + cssClass;
32-
};
33-
3430
QUnit.module('List markup', {}, () => {
3531
QUnit.test('rendering empty message for empty list', function(assert) {
3632
const element = $('#list').dxList();
@@ -41,7 +37,7 @@ QUnit.module('List markup', {}, () => {
4137
const element = $('#list').dxList({ items: ['0', '1'] });
4238
assert.ok(element.hasClass(LIST_CLASS));
4339

44-
const items = element.find(toSelector(LIST_ITEM_CLASS));
40+
const items = element.find(`.${LIST_ITEM_CLASS}`);
4541
assert.equal(items.length, 2);
4642
assert.ok(items.eq(0).hasClass(LIST_ITEM_CLASS));
4743
assert.ok(items.eq(1).hasClass(LIST_ITEM_CLASS));
@@ -56,7 +52,7 @@ QUnit.module('List markup', {}, () => {
5652
}
5753
});
5854

59-
const item = element.find(toSelector(LIST_ITEM_CLASS));
55+
const item = element.find(`.${LIST_ITEM_CLASS}`);
6056

6157
assert.equal(item.eq(0).text(), '0: a');
6258
assert.equal(item.eq(1).text(), '1: b');
@@ -70,7 +66,7 @@ QUnit.module('List markup', {}, () => {
7066
}
7167
});
7268

73-
const item = element.find(toSelector(LIST_ITEM_CLASS));
69+
const item = element.find(`.${LIST_ITEM_CLASS}`);
7470

7571
assert.equal(item.eq(0).text(), '0: a');
7672
assert.equal(item.eq(1).text(), '1: b');
@@ -110,16 +106,16 @@ QUnit.module('List markup', {}, () => {
110106
grouped: true
111107
});
112108

113-
const groups = element.find(toSelector(LIST_GROUP_CLASS));
109+
const groups = element.find(`.${LIST_GROUP_CLASS}`);
114110
assert.equal(groups.length, 2);
115111

116-
const groupHeaders = element.find(toSelector(LIST_GROUP_HEADER_CLASS));
112+
const groupHeaders = element.find(`.${LIST_GROUP_HEADER_CLASS}`);
117113
assert.equal(groupHeaders.length, 2);
118114

119115
assert.equal(groupHeaders.eq(0).text(), 'group1');
120116
assert.equal(groupHeaders.eq(1).text(), 'group2');
121117

122-
const items = element.find(toSelector(LIST_ITEM_CLASS));
118+
const items = element.find(`.${LIST_ITEM_CLASS}`);
123119
assert.equal(items.length, 3);
124120
});
125121

@@ -144,7 +140,7 @@ QUnit.module('List markup', {}, () => {
144140
}
145141
});
146142

147-
const groupHeaders = element.find(toSelector(LIST_GROUP_HEADER_CLASS));
143+
const groupHeaders = element.find(`.${LIST_GROUP_HEADER_CLASS}`);
148144
assert.equal(groupHeaders.eq(0).text(), '0: a');
149145
assert.equal(groupHeaders.eq(1).text(), '1: b');
150146
});
@@ -166,7 +162,7 @@ QUnit.module('List markup', {}, () => {
166162
}
167163
});
168164

169-
const groupHeaders = element.find(toSelector(LIST_GROUP_HEADER_CLASS));
165+
const groupHeaders = element.find(`.${LIST_GROUP_HEADER_CLASS}`);
170166
assert.ok(groupHeaders.find('span').length);
171167
});
172168

@@ -451,14 +447,14 @@ QUnit.module('decorators markup', {}, () => {
451447
itemDeleteMode: 'static'
452448
}));
453449

454-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
450+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
455451
const $item = $items.eq(0);
456452

457-
const $button = $item.find(toSelector(STATIC_DELETE_BUTTON_CLASS));
453+
const $button = $item.find(`.${STATIC_DELETE_BUTTON_CLASS}`);
458454

459455
assert.equal($button.length, 1, 'delete button was rendered');
460456
assert.ok($button.parent().hasClass(STATIC_DELETE_BUTTON_CONTAINER_CLASS), 'delete button was rendered in correct container');
461-
assert.equal($list.find(toSelector(STATIC_DELETE_BUTTON_CLASS)).length, 3, 'delete button was rendered for all items');
457+
assert.equal($list.find(`.${STATIC_DELETE_BUTTON_CLASS}`).length, 3, 'delete button was rendered for all items');
462458
});
463459

464460
QUnit.test('list item markup, toggle delete decorator', function(assert) {
@@ -468,12 +464,12 @@ QUnit.module('decorators markup', {}, () => {
468464
itemDeleteMode: 'toggle'
469465
}));
470466

471-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
467+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
472468
const $item = $items.eq(0);
473469

474-
const $deleteToggle = $item.children(toSelector(LIST_ITEM_BEFORE_BAG_CLASS)).children(toSelector(TOGGLE_DELETE_SWITCH_CLASS));
470+
const $deleteToggle = $item.children(`.${LIST_ITEM_BEFORE_BAG_CLASS}`).children(`.${TOGGLE_DELETE_SWITCH_CLASS}`);
475471
assert.ok($deleteToggle.length, 'toggle generated');
476-
assert.ok($deleteToggle.find(toSelector(TOGGLE_DELETE_SWITCH_ICON_CLASS)).length, 'toggle icon generated');
472+
assert.ok($deleteToggle.find(`.${TOGGLE_DELETE_SWITCH_ICON_CLASS}`).length, 'toggle icon generated');
477473
});
478474

479475
QUnit.test('list item delete icon is visible when showSelectionControls=true (T966717)', function(assert) {
@@ -579,10 +575,10 @@ QUnit.module('decorators markup', {}, () => {
579575
selectionMode: 'multiple'
580576
}));
581577

582-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
578+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
583579
const $item = $items.eq(0);
584-
const $checkboxContainer = $item.children(toSelector(LIST_ITEM_BEFORE_BAG_CLASS));
585-
const $checkbox = $checkboxContainer.children(toSelector(SELECT_CHECKBOX_CLASS));
580+
const $checkboxContainer = $item.children(`.${LIST_ITEM_BEFORE_BAG_CLASS}`);
581+
const $checkbox = $checkboxContainer.children(`.${SELECT_CHECKBOX_CLASS}`);
586582

587583
assert.ok($checkboxContainer.hasClass(SELECT_CHECKBOX_CONTAINER_CLASS), 'container has proper class');
588584
assert.ok($checkbox.hasClass('dx-checkbox'), 'select generated');
@@ -595,10 +591,10 @@ QUnit.module('decorators markup', {}, () => {
595591
selectionMode: 'single'
596592
}));
597593

598-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
594+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
599595
const $item = $items.eq(0);
600-
const $radioButtonContainer = $item.children(toSelector(SELECT_RADIO_BUTTON_CONTAINER_CLASS));
601-
const $radioButton = $radioButtonContainer.children(toSelector(SELECT_RADIO_BUTTON_CLASS));
596+
const $radioButtonContainer = $item.children(`.${SELECT_RADIO_BUTTON_CONTAINER_CLASS}`);
597+
const $radioButton = $radioButtonContainer.children(`.${SELECT_RADIO_BUTTON_CLASS}`);
602598

603599
assert.ok($radioButton.hasClass('dx-radiobutton'), 'radio button generated');
604600
});
@@ -611,7 +607,7 @@ QUnit.module('decorators markup', {}, () => {
611607
selectAllText: 'Test'
612608
}));
613609

614-
const $multipleContainer = $list.find(toSelector(SELECT_ALL_CLASS));
610+
const $multipleContainer = $list.find(`.${SELECT_ALL_CLASS}`);
615611
assert.equal($multipleContainer.length, 1, 'container for SelectAll rendered');
616612
assert.equal($multipleContainer.text(), 'Test', 'select all rendered');
617613
const $checkbox = $multipleContainer.find('.dx-checkbox');
@@ -632,8 +628,8 @@ QUnit.module('decorators markup', {}, () => {
632628
selectionMode: 'all',
633629
}));
634630

635-
const $selectAllCheckBox = $list.find(toSelector(SELECT_ALL_CHECKBOX_CLASS));
636-
const $multipleContainer = $list.find(toSelector(SELECT_ALL_CLASS));
631+
const $selectAllCheckBox = $list.find(`.${SELECT_ALL_CHECKBOX_CLASS}`);
632+
const $multipleContainer = $list.find(`.${SELECT_ALL_CLASS}`);
637633

638634
assert.strictEqual($selectAllCheckBox.attr('aria-label'), localizedSelectAllText, 'selectAll checkbox aria-label should be equal to localized text');
639635

@@ -667,10 +663,10 @@ QUnit.module('decorators markup', {}, () => {
667663
}
668664
}));
669665

670-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
666+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
671667
const $item = $items.eq(0);
672-
const $handleContainer = $item.children(toSelector(REORDER_HANDLE_CONTAINER_CLASS));
673-
const $handle = $handleContainer.children(toSelector(REORDER_HANDLE_CLASS));
668+
const $handleContainer = $item.children(`.${REORDER_HANDLE_CONTAINER_CLASS}`);
669+
const $handle = $handleContainer.children(`.${REORDER_HANDLE_CLASS}`);
674670

675671
assert.equal($handleContainer.length, 1, 'container generated');
676672
assert.equal($handle.length, 1, 'handle generated');
@@ -682,7 +678,7 @@ QUnit.module('decorators markup', {}, () => {
682678
displayExpr: 'name'
683679
});
684680

685-
const $items = $list.find(toSelector(LIST_ITEM_CLASS));
681+
const $items = $list.find(`.${LIST_ITEM_CLASS}`);
686682

687683
assert.strictEqual($items.text(), 'Item 1', 'displayExpr works');
688684
});

packages/devextreme/testing/tests/DevExpress.ui.widgets/menu.markup.tests.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ const createMenu = (options) => {
3030
return { instance: menuInstance, element: $menu };
3131
};
3232

33-
const toSelector = cssClass => '.' + cssClass;
34-
3533
QUnit.module('Menu rendering', {
3634
beforeEach: function() {
3735
fx.off = true;
@@ -55,10 +53,10 @@ QUnit.module('Menu rendering', {
5553
itemsExpr: 'child',
5654
showFirstSubmenuMode: 'onClick'
5755
});
58-
const $item1 = $(menu.element).find(toSelector(DX_MENU_ITEM_CLASS)).eq(0);
56+
const $item1 = $(menu.element).find(`.${DX_MENU_ITEM_CLASS}`).eq(0);
5957

6058
assert.equal($item1.text(), 'item 1', 'root item rendered correct');
61-
assert.ok($item1.find(toSelector(DX_MENU_ITEM_POPOUT_CLASS)).length, 'popout was rendered');
59+
assert.ok($item1.find(`.${DX_MENU_ITEM_POPOUT_CLASS}`).length, 'popout was rendered');
6260
});
6361

6462
QUnit.test('Check default css class', function(assert) {
@@ -69,7 +67,7 @@ QUnit.module('Menu rendering', {
6967

7068
QUnit.test('Do not render menu with empty items', function(assert) {
7169
const menu = createMenu({ items: [] });
72-
const root = $(menu.element).find(toSelector(DX_MENU_HORIZONTAL));
70+
const root = $(menu.element).find(`.${DX_MENU_HORIZONTAL}`);
7371

7472
assert.ok(menu);
7573
assert.equal(root.length, 0, 'no root');
@@ -101,7 +99,7 @@ QUnit.module('Menu - selection', {
10199
items: [{ text: 'root', selected: true }],
102100
selectionMode: 'single'
103101
});
104-
const item1 = $(menu.element).find(toSelector(DX_MENU_ITEM_CLASS)).eq(0);
102+
const item1 = $(menu.element).find(`.${DX_MENU_ITEM_CLASS}`).eq(0);
105103
assert.ok(item1.hasClass(DX_MENU_ITEM_SELECTED_CLASS));
106104
});
107105
});
@@ -131,7 +129,7 @@ QUnit.module('Menu with templates', {
131129
itemTemplate: $template
132130
};
133131
const menu = createMenu(options);
134-
const $item = $(menu.element).find(toSelector(DX_MENU_ITEM_CLASS)).eq(1);
132+
const $item = $(menu.element).find(`.${DX_MENU_ITEM_CLASS}`).eq(1);
135133

136134
$($item).trigger('dxclick');
137135

packages/devextreme/testing/tests/DevExpress.ui.widgets/multiView.markup.tests.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ const MULTIVIEW_ITEM_CLASS = 'dx-multiview-item';
2525
const MULTIVIEW_ITEM_CONTENT_CLASS = 'dx-multiview-item-content';
2626
const MULTIVIEW_ITEM_HIDDEN_CLASS = 'dx-multiview-item-hidden';
2727

28-
const toSelector = function(cssClass) {
29-
return '.' + cssClass;
30-
};
31-
3228
QUnit.module('markup', () => {
3329
QUnit.test('widget should be rendered', function(assert) {
3430
const $multiView = $('#multiView').dxMultiView();
@@ -38,15 +34,15 @@ QUnit.module('markup', () => {
3834

3935
QUnit.test('wrapper should be rendered', function(assert) {
4036
const $multiView = $('#multiView').dxMultiView();
41-
const $wrapper = $multiView.children(toSelector(MULTIVIEW_WRAPPER_CLASS));
37+
const $wrapper = $multiView.children(`.${MULTIVIEW_WRAPPER_CLASS}`);
4238

4339
assert.equal($wrapper.length, 1, 'wrapper was rendered');
4440
});
4541

4642
QUnit.test('item container should be rendered', function(assert) {
4743
const $multiView = $('#multiView').dxMultiView();
48-
const $wrapper = $multiView.children(toSelector(MULTIVIEW_WRAPPER_CLASS));
49-
const $itemContainer = $wrapper.children(toSelector(MULTIVIEW_ITEM_CONTAINER_CLASS));
44+
const $wrapper = $multiView.children(`.${MULTIVIEW_WRAPPER_CLASS}`);
45+
const $itemContainer = $wrapper.children(`.${MULTIVIEW_ITEM_CONTAINER_CLASS}`);
5046

5147
assert.equal($itemContainer.length, 1, 'item container was rendered');
5248
});
@@ -56,12 +52,12 @@ QUnit.module('markup', () => {
5652
items: [1, 2],
5753
selectedIndex: 0
5854
});
59-
const $itemContainer = $multiView.find(toSelector(MULTIVIEW_ITEM_CONTAINER_CLASS));
60-
const $items = $itemContainer.children(toSelector(MULTIVIEW_ITEM_CLASS));
55+
const $itemContainer = $multiView.find(`.${MULTIVIEW_ITEM_CONTAINER_CLASS}`);
56+
const $items = $itemContainer.children(`.${MULTIVIEW_ITEM_CLASS}`);
6157

6258
assert.equal($items.length, 2, 'items was rendered');
63-
assert.equal($items.eq(0).find(toSelector(MULTIVIEW_ITEM_CONTENT_CLASS)).length, 1, 'rendered item has item content inside');
64-
assert.equal($items.eq(1).find(toSelector(MULTIVIEW_ITEM_CONTENT_CLASS)).length, 0, 'second item has no item content because deferRendering is true');
59+
assert.equal($items.eq(0).find(`.${MULTIVIEW_ITEM_CONTENT_CLASS}`).length, 1, 'rendered item has item content inside');
60+
assert.equal($items.eq(1).find(`.${MULTIVIEW_ITEM_CONTENT_CLASS}`).length, 0, 'second item has no item content because deferRendering is true');
6561
});
6662

6763
QUnit.test('item templates should be applied', function(assert) {
@@ -70,8 +66,8 @@ QUnit.module('markup', () => {
7066
selectedIndex: 1,
7167
deferRendering: false
7268
});
73-
const $itemContainer = $multiView.find(toSelector(MULTIVIEW_ITEM_CONTAINER_CLASS));
74-
const $items = $itemContainer.children(toSelector(MULTIVIEW_ITEM_CLASS));
69+
const $itemContainer = $multiView.find(`.${MULTIVIEW_ITEM_CONTAINER_CLASS}`);
70+
const $items = $itemContainer.children(`.${MULTIVIEW_ITEM_CLASS}`);
7571

7672
assert.equal($items.eq(0).text(), 'Test1', 'element has correct content');
7773
assert.equal($items.eq(1).text(), 'Test2', 'element has correct content');
@@ -87,9 +83,9 @@ QUnit.module('markup', () => {
8783
});
8884
}
8985
});
90-
const $itemContainer = $multiView.find(toSelector(MULTIVIEW_ITEM_CONTAINER_CLASS));
86+
const $itemContainer = $multiView.find(`.${MULTIVIEW_ITEM_CONTAINER_CLASS}`);
9187

92-
const $items = $itemContainer.children(toSelector(MULTIVIEW_ITEM_CLASS));
88+
const $items = $itemContainer.children(`.${MULTIVIEW_ITEM_CLASS}`);
9389
assert.ok(!$items.eq(3).hasClass(MULTIVIEW_ITEM_HIDDEN_CLASS), 'correct item selected');
9490
});
9591

@@ -98,7 +94,7 @@ QUnit.module('markup', () => {
9894
items: [1, 2, 3],
9995
selectedIndex: 0
10096
});
101-
const $items = $multiView.find(toSelector(MULTIVIEW_ITEM_CLASS));
97+
const $items = $multiView.find(`.${MULTIVIEW_ITEM_CLASS}`);
10298

10399
assert.ok(!$items.eq(0).hasClass(MULTIVIEW_ITEM_HIDDEN_CLASS));
104100
assert.ok($items.eq(1).hasClass(MULTIVIEW_ITEM_HIDDEN_CLASS));

0 commit comments

Comments
 (0)