fix: show Import button only if has perms (#16763)

* fix: show Import button only if has perms

* Fix tests
This commit is contained in:
Beto Dealmeida 2021-09-23 14:55:21 -07:00 committed by GitHub
parent 4086bedb68
commit 6921d94861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 57 deletions

View File

@ -190,7 +190,7 @@ describe('RTL', () => {
}); });
it('renders an "Import Chart" tooltip under import button', async () => { it('renders an "Import Chart" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton); userEvent.hover(importButton);
await screen.findByRole('tooltip'); await screen.findByRole('tooltip');

View File

@ -586,21 +586,22 @@ function ChartList(props: ChartListProps) {
window.location.assign('/chart/add'); window.location.assign('/chart/add');
}, },
}); });
}
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) { if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({ subMenuButtons.push({
name: ( name: (
<Tooltip <Tooltip
id="import-tooltip" id="import-tooltip"
title={t('Import charts')} title={t('Import charts')}
placement="bottomRight" placement="bottomRight"
> >
<Icons.Import data-test="import-button" /> <Icons.Import data-test="import-button" />
</Tooltip> </Tooltip>
), ),
buttonStyle: 'link', buttonStyle: 'link',
onClick: openChartImportModal, onClick: openChartImportModal,
}); });
}
} }
return ( return (
<> <>

View File

@ -211,7 +211,7 @@ describe('RTL', () => {
}); });
it('renders an "Import Dashboard" tooltip under import button', async () => { it('renders an "Import Dashboard" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton); userEvent.hover(importButton);
await screen.findByRole('tooltip'); await screen.findByRole('tooltip');

View File

@ -553,21 +553,22 @@ function DashboardList(props: DashboardListProps) {
window.location.assign('/dashboard/new'); window.location.assign('/dashboard/new');
}, },
}); });
}
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) { if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({ subMenuButtons.push({
name: ( name: (
<Tooltip <Tooltip
id="import-tooltip" id="import-tooltip"
title={t('Import dashboards')} title={t('Import dashboards')}
placement="bottomRight" placement="bottomRight"
> >
<Icons.Import data-test="import-button" /> <Icons.Import data-test="import-button" />
</Tooltip> </Tooltip>
), ),
buttonStyle: 'link', buttonStyle: 'link',
onClick: openDashboardImportModal, onClick: openDashboardImportModal,
}); });
}
} }
return ( return (
<> <>

View File

@ -211,7 +211,7 @@ describe('RTL', () => {
}); });
it('renders an "Import Database" tooltip under import button', async () => { it('renders an "Import Database" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton); userEvent.hover(importButton);
await screen.findByRole('tooltip'); await screen.findByRole('tooltip');

View File

@ -211,7 +211,7 @@ describe('RTL', () => {
}); });
it('renders an "Import Dataset" tooltip under import button', async () => { it('renders an "Import Dataset" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton); userEvent.hover(importButton);
await screen.findByRole('tooltip'); await screen.findByRole('tooltip');

View File

@ -512,22 +512,22 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
onClick: () => setDatasetAddModalOpen(true), onClick: () => setDatasetAddModalOpen(true),
buttonStyle: 'primary', buttonStyle: 'primary',
}); });
}
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) { if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
buttonArr.push({ buttonArr.push({
name: ( name: (
<Tooltip <Tooltip
id="import-tooltip" id="import-tooltip"
title={t('Import datasets')} title={t('Import datasets')}
placement="bottomRight" placement="bottomRight"
> >
<Icons.Import data-test="import-button" /> <Icons.Import data-test="import-button" />
</Tooltip> </Tooltip>
), ),
buttonStyle: 'link', buttonStyle: 'link',
onClick: openDatasetImportModal, onClick: openDatasetImportModal,
}); });
}
} }
menuData.buttons = buttonArr; menuData.buttons = buttonArr;

View File

@ -284,14 +284,14 @@ describe('RTL', () => {
expect(exportTooltip).toBeInTheDocument(); expect(exportTooltip).toBeInTheDocument();
}); });
it('renders an import button in the submenu', () => { it('renders an import button in the submenu', async () => {
// Grab and assert that import saved query button is visible // Grab and assert that import saved query button is visible
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
expect(importButton).toBeVisible(); expect(importButton).toBeVisible();
}); });
it('renders an "Import Saved Query" tooltip under import button', async () => { it('renders an "Import Saved Query" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton); userEvent.hover(importButton);
waitFor(() => { waitFor(() => {
expect(importButton).toHaveClass('ant-tooltip-open'); expect(importButton).toHaveClass('ant-tooltip-open');
@ -303,9 +303,9 @@ describe('RTL', () => {
}); });
}); });
it('renders an import model when import button is clicked', async () => { it('renders an import modal when import button is clicked', async () => {
// Grab and click import saved query button to reveal modal // Grab and click import saved query button to reveal modal
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.click(importButton); userEvent.click(importButton);
// Grab and assert that saved query import modal's heading is visible // Grab and assert that saved query import modal's heading is visible
@ -315,9 +315,9 @@ describe('RTL', () => {
expect(importSavedQueryModalHeading).toBeVisible(); expect(importSavedQueryModalHeading).toBeVisible();
}); });
it('imports a saved query', () => { it('imports a saved query', async () => {
// Grab and click import saved query button to reveal modal // Grab and click import saved query button to reveal modal
const importButton = screen.getByTestId('import-button'); const importButton = await screen.findByTestId('import-button');
userEvent.click(importButton); userEvent.click(importButton);
// Grab "Choose File" input from import modal // Grab "Choose File" input from import modal

View File

@ -133,6 +133,7 @@ function SavedQueryList({
refreshData(); refreshData();
}; };
const canCreate = hasPerm('can_write');
const canEdit = hasPerm('can_write'); const canEdit = hasPerm('can_write');
const canDelete = hasPerm('can_write'); const canDelete = hasPerm('can_write');
const canExport = const canExport =
@ -185,7 +186,7 @@ function SavedQueryList({
buttonStyle: 'primary', buttonStyle: 'primary',
}); });
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) { if (canCreate && isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({ subMenuButtons.push({
name: ( name: (
<Tooltip <Tooltip