Skip to content

Commit

Permalink
✅ Add download unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Nov 20, 2020
1 parent 5749f32 commit 4674a83
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,71 @@ describe('Lens App', () => {
});
});

describe('download button', () => {
function getButton(inst: ReactWrapper): TopNavMenuData {
return (inst
.find('[data-test-subj="lnsApp_topNav"]')
.prop('config') as TopNavMenuData[]).find(
(button) => button.testId === 'lnsApp_downloadCSVButton'
)!;
}

it('should be disabled when no data is available', async () => {
const { component, frame } = mountWith({});
const onChange = frame.mount.mock.calls[0][1].onChange;
await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({} as unknown) as Document,
isSaveable: true,
})
);
component.update();
expect(getButton(component).disableButton).toEqual(true);
});

it('should disable download when not saveable', async () => {
const { component, frame } = mountWith({});
const onChange = frame.mount.mock.calls[0][1].onChange;

await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({} as unknown) as Document,
isSaveable: false,
activeData: { layer1: { type: 'datatable', columns: [], rows: [] } },
})
);

component.update();
expect(getButton(component).disableButton).toEqual(true);
});

it('should still be enabled even if the user is missing save permissions', async () => {
const services = makeDefaultServices();
services.application = {
...services.application,
capabilities: {
...services.application.capabilities,
visualize: { save: false, saveQuery: false, show: true },
},
};

const { component, frame } = mountWith({ services });
const onChange = frame.mount.mock.calls[0][1].onChange;
await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({} as unknown) as Document,
isSaveable: true,
activeData: { layer1: { type: 'datatable', columns: [], rows: [] } },
})
);
component.update();
expect(getButton(component).disableButton).toEqual(false);
});
});

describe('query bar state management', () => {
it('uses the default time and query language settings', () => {
const { frame } = mountWith({});
Expand Down

0 comments on commit 4674a83

Please sign in to comment.