Skip to content

Commit

Permalink
make sure to render once (#93786)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Mar 9, 2021
1 parent d657118 commit 35d01f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,46 @@ describe('embeddable', () => {
| expression`);
});

it('should render once even if reload is called before embeddable is fully initialized', async () => {
const embeddable = new Embeddable(
{
timefilter: dataPluginMock.createSetupContract().query.timefilter.timefilter,
attributeService,
expressionRenderer,
basePath,
indexPatternService: {} as IndexPatternsContract,
editable: true,
getTrigger,
documentToExpression: () =>
Promise.resolve({
ast: {
type: 'expression',
chain: [
{ type: 'function', function: 'my', arguments: {} },
{ type: 'function', function: 'expression', arguments: {} },
],
},
errors: undefined,
}),
},
{
timeRange: {
from: 'now-15m',
to: 'now',
},
} as LensEmbeddableInput
);
await embeddable.reload();
expect(expressionRenderer).toHaveBeenCalledTimes(0);
embeddable.render(mountpoint);
expect(expressionRenderer).toHaveBeenCalledTimes(0);

// wait one tick to give embeddable time to initialize
await new Promise((resolve) => setTimeout(resolve, 0));

expect(expressionRenderer).toHaveBeenCalledTimes(1);
});

it('should not render the visualization if any error arises', async () => {
const embeddable = new Embeddable(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ export class Embeddable
};

async reload() {
if (!this.savedVis || !this.isInitialized) {
return;
}
this.handleContainerStateChanged(this.input);
if (this.domNode) {
this.render(this.domNode);
Expand Down

0 comments on commit 35d01f5

Please sign in to comment.