Skip to content

Commit

Permalink
Renovation: add onContentReady property to button and widget (#12174)
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyLahtak authored Mar 3, 2020
1 parent ace3c9f commit 7c5b50c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions js/renovation/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const viewFunction = (viewModel: ButtonViewModel) => {
hint={viewModel.hint}
hoverStateEnabled={viewModel.hoverStateEnabled}
onActive={viewModel.onActive}
onContentReady={viewModel.onContentReady}
onClick={viewModel.onWidgetClick}
onInactive={viewModel.onInactive}
onKeyPress={viewModel.onWidgetKeyPress}
Expand Down
4 changes: 4 additions & 0 deletions js/renovation/dist/button.j.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Button extends Widget {
}
});

props.onContentReady = this._createActionByOption('onContentReady', {
excludeValidators: ['disabled', 'readOnly']
});

return props;
}

Expand Down
7 changes: 0 additions & 7 deletions js/renovation/dist/widget.j.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ class Widget extends WidgetBase {

getProps(isFirstRender) {
const props = super.getProps(isFirstRender);
props.onClick = this._createActionByOption('onClick', {
excludeValidators: ['readOnly'],
afterExecute: () => {
const { useSubmitBehavior } = this.option();

useSubmitBehavior && setTimeout(() => this._submitInput().click());
}
});
return props;
}

Expand Down
12 changes: 11 additions & 1 deletion js/renovation/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const viewModelFunction = ({
tabIndex,
visible,
width,
onContentReady,
onVisibilityChange,
},

Expand All @@ -117,6 +118,7 @@ export const viewModelFunction = ({
disabled,
focusStateEnabled,
hoverStateEnabled,
onContentReady,
styles,
tabIndex: focusStateEnabled && !disabled && tabIndex,
title: hint,
Expand Down Expand Up @@ -160,7 +162,8 @@ export class WidgetInput {
@OneWay() hoverStateEnabled?: boolean = false;
@OneWay() name?: string = '';
@OneWay() onActive?: (e: any) => any = (() => undefined);
@Event() onClick?: (e: any) => void = (() => { });
@Event() onClick?: (e: any) => void = (() => {});
@Event() onContentReady?: (e: any) => any = (() => {});
@OneWay() onDimensionChanged?: () => any = (() => undefined);
@OneWay() onInactive?: (e: any) => any = (() => undefined);
@OneWay() onKeyboardHandled?: (args: any) => any | undefined;
Expand Down Expand Up @@ -254,6 +257,13 @@ export default class Widget extends JSXComponent<WidgetInput> {
return () => dxClick.off(this.widgetRef, { namespace });
}

@Effect()
contentReadyEffect() {
const { onContentReady } = this.props;

onContentReady?.({});
}

@Effect()
focusEffect() {
const { disabled, focusStateEnabled, name } = this.props;
Expand Down
35 changes: 22 additions & 13 deletions testing/tests/Renovation/button.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ QUnit.module('regressions', {
});

QUnit.module('contentReady', {}, () => {
// TODO
QUnit.skip('T355000 - the \'onContentReady\' action should be fired after widget is rendered entirely', function(assert) {
QUnit.test('T355000 - the \'onContentReady\' action should be fired after widget is rendered entirely', function(assert) {
const done = assert.async();
const buttonConfig = {
text: 'Test button',
icon: 'trash'
Expand Down Expand Up @@ -341,6 +341,7 @@ QUnit.module('contentReady', {}, () => {
$('#button').Button($.extend({}, buttonConfig, {
onContentReady(e) {
assert.ok(areElementsEqual($firstButton, $(e.element)), 'rendered widget and widget with fired action are equals');
done();
}
}));
});
Expand Down Expand Up @@ -735,8 +736,8 @@ QUnit.module('templates', () => {
});

QUnit.module('events subscriptions', () => {
// TODO
QUnit.skip('click', function(assert) {
QUnit.test('click', function(assert) {
const done = assert.async();
const clickHandler = sinon.spy();
const $button = $('#button').Button({
text: 'test'
Expand All @@ -745,28 +746,36 @@ QUnit.module('events subscriptions', () => {

button.on('click', clickHandler);

$button.trigger('dxclick');
setTimeout(() => {
$button.trigger('dxclick');

assert.ok(clickHandler.calledOnce, 'Handler should be called');
const params = clickHandler.getCall(0).args[0];
assert.ok(params, 'Event params should be passed');
assert.ok(params.event, 'Event should be passed');
assert.ok(params.validationGroup, 'validationGroup should be passed');
setTimeout(() => {
assert.ok(clickHandler.calledOnce, 'Handler should be called');
const params = clickHandler.getCall(0).args[0];
assert.ok(params, 'Event params should be passed');
assert.ok(params.event, 'Event should be passed');
// TODO
// assert.ok(params.validationGroup, 'validationGroup should be passed');

done();
}, 100);
}, 100);
});

// TODO
QUnit.skip('contentReady', function(assert) {
QUnit.test('contentReady', function(assert) {
const done = assert.async();
assert.expect(3);

const button = $('#button').Button({
text: 'test'
}).Button('instance');

// NOTE: now we shouldn't call repaint, because we call onContentReady async
button.on('contentReady', (e) => {
assert.ok(e.component, 'Component info should be passed');
assert.ok(e.element, 'Element info should be passed');
assert.strictEqual($(e.element).text(), 'test', 'Text is rendered to the element');
done();
});
button.repaint();
});
});

0 comments on commit 7c5b50c

Please sign in to comment.