fix(ui): Disable ability to export data when user does not have the correct permission (#28429)

This commit is contained in:
Ed Jannoo
2024-06-20 16:26:51 +01:00
committed by GitHub
parent 313ee596f5
commit 70f6f5f3ef
22 changed files with 253 additions and 30 deletions

View File

@@ -394,11 +394,25 @@ describe('Additional actions tests', () => {
spyExportChart.restore();
});
test('Should export to JSON', async () => {
test('Should not export to JSON if canDownload=false', async () => {
const props = createProps();
render(<ExploreHeader {...props} />, {
useRedux: true,
});
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.hover(screen.getByText('Download'));
const exportJsonElement = await screen.findByText('Export to .JSON');
userEvent.click(exportJsonElement);
expect(spyExportChart.callCount).toBe(0);
spyExportChart.restore();
});
test('Should export to JSON if canDownload=true', async () => {
const props = createProps();
props.canDownload = true;
render(<ExploreHeader {...props} />, {
useRedux: true,
});
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.hover(screen.getByText('Download'));
@@ -407,6 +421,22 @@ describe('Additional actions tests', () => {
expect(spyExportChart.callCount).toBe(1);
});
test('Should not export to pivoted CSV if canDownloadCSV=false and viz_type=pivot_table_v2', async () => {
const props = createProps();
props.chart.latestQueryFormData.viz_type = 'pivot_table_v2';
render(<ExploreHeader {...props} />, {
useRedux: true,
});
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.hover(screen.getByText('Download'));
const exportCSVElement = await screen.findByText(
'Export to pivoted .CSV',
);
userEvent.click(exportCSVElement);
expect(spyExportChart.callCount).toBe(0);
});
test('Should export to pivoted CSV if canDownloadCSV=true and viz_type=pivot_table_v2', async () => {
const props = createProps();
props.canDownload = true;
@@ -423,5 +453,31 @@ describe('Additional actions tests', () => {
userEvent.click(exportCSVElement);
expect(spyExportChart.callCount).toBe(1);
});
test('Should not export to Excel if canDownload=false', async () => {
const props = createProps();
render(<ExploreHeader {...props} />, {
useRedux: true,
});
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.hover(screen.getByText('Download'));
const exportExcelElement = await screen.findByText('Export to Excel');
userEvent.click(exportExcelElement);
expect(spyExportChart.callCount).toBe(0);
spyExportChart.restore();
});
test('Should export to Excel if canDownload=true', async () => {
const props = createProps();
props.canDownload = true;
render(<ExploreHeader {...props} />, {
useRedux: true,
});
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.hover(screen.getByText('Download'));
const exportExcelElement = await screen.findByText('Export to Excel');
userEvent.click(exportExcelElement);
expect(spyExportChart.callCount).toBe(1);
});
});
});