Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioGroup: add some event tests #11866

Merged
merged 4 commits into from
Feb 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions testing/tests/DevExpress.ui.widgets.editors/radioGroup.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ module('buttons group rendering', () => {
instance.option('dataSource', [1, 2, 3]);
assert.strictEqual(onContentReadyHandler.callCount, 2);
});

test('onContentReady - subscription using "on" method', function(assert) {
const onContentReadyHandler = sinon.stub();

const instance = getInstance(
createRadioGroup({
dataSource: ['str1', 'str2', 'str3']
})
);

instance.on('contentReady', onContentReadyHandler);
DokaRus marked this conversation as resolved.
Show resolved Hide resolved

instance.option('dataSource', [1, 2, 3]);
assert.strictEqual(onContentReadyHandler.callCount, 1, 'contentReady is fired');
});
});

module('layout', moduleConfig, () => {
Expand Down Expand Up @@ -341,6 +356,19 @@ module('value', moduleConfig, () => {
assert.equal(value, 1, 'value changed');
});

test('value is changed on item click - subscription using "on" method', function(assert) {
const handler = sinon.spy();
const $radioGroup = createRadioGroup({
items: [1, 2, 3]
});
const radioGroup = getInstance($radioGroup);

radioGroup.on('valueChanged', handler);
$(radioGroup.itemElements()).first().trigger('dxclick');

assert.ok(handler.calledOnce, 'value changed');
ksercs marked this conversation as resolved.
Show resolved Hide resolved
});

test('onValueChanged option should get jQuery event as a parameter', function(assert) {
let jQueryEvent;
const $radioGroup = createRadioGroup({
Expand Down Expand Up @@ -640,6 +668,46 @@ module('focus policy', moduleConfig, () => {
});

module('option changed', () => {
test('focusStateEnabled option change', function(assert) {
const $radioGroup = createRadioGroup({
focusStateEnabled: true
});
const instance = getInstance($radioGroup);

instance.option('focusStateEnabled', false);
assert.strictEqual(instance.$element().attr('tabindex'), undefined, 'element is not focusable');

instance.option('focusStateEnabled', true);
assert.strictEqual(instance.$element().attr('tabindex'), '0', 'element is focusable');
});

test('items option change', function(assert) {
const $radioGroup = createRadioGroup({
items: [1, 2, 3]
});
const instance = getInstance($radioGroup);

assert.equal($(instance.itemElements()).eq(0).text(), '1', 'item is correct');
instance.option('items', [4, 5, 6]);
assert.equal($(instance.itemElements()).eq(0).text(), '4', 'item is correct');
});

test('displayExpr option change', function(assert) {
const radioGroup = getInstance(
createRadioGroup({
dataSource: [{ id: 1, name: 'Item 1' }],
valueExpr: 'id',
displayExpr: 'id',
value: 1
})
);

radioGroup.option('displayExpr', 'name');

const $item = $(radioGroup.itemElements()).eq(0);
assert.strictEqual($item.text(), 'Item 1', 'displayExpr works');
});

test('items from the getDataSource method are wrong when the dataSource option is changed', function(assert) {
const instance = getInstance(
createRadioGroup({
Expand Down