mirror of
https://github.com/apache/superset.git
synced 2026-04-26 19:44:58 +00:00
fix(sqllab): remove link to sqllab if missing perms (#22566)
This commit is contained in:
@@ -20,13 +20,13 @@
|
||||
import React from 'react';
|
||||
import { render, screen, act, waitFor } from 'spec/helpers/testing-library';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { SupersetClient, DatasourceType } from '@superset-ui/core';
|
||||
import { DatasourceType, JsonObject, SupersetClient } from '@superset-ui/core';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import DatasourceControl from '.';
|
||||
|
||||
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
|
||||
|
||||
const createProps = () => ({
|
||||
const createProps = (overrides: JsonObject = {}) => ({
|
||||
hovered: false,
|
||||
type: 'DatasourceControl',
|
||||
label: 'Datasource',
|
||||
@@ -64,6 +64,7 @@ const createProps = () => ({
|
||||
},
|
||||
onChange: jest.fn(),
|
||||
onDatasourceSave: jest.fn(),
|
||||
...overrides,
|
||||
});
|
||||
|
||||
async function openAndSaveChanges(datasource: any) {
|
||||
@@ -104,6 +105,52 @@ test('Should open a menu', async () => {
|
||||
expect(screen.getByText('View in SQL Lab')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Should not show SQL Lab for non sql_lab role', async () => {
|
||||
const props = createProps({
|
||||
user: {
|
||||
createdOn: '2021-04-27T18:12:38.952304',
|
||||
email: 'gamma',
|
||||
firstName: 'gamma',
|
||||
isActive: true,
|
||||
lastName: 'gamma',
|
||||
permissions: {},
|
||||
roles: { Gamma: [] },
|
||||
userId: 2,
|
||||
username: 'gamma',
|
||||
},
|
||||
});
|
||||
render(<DatasourceControl {...props} />);
|
||||
|
||||
userEvent.click(screen.getByTestId('datasource-menu-trigger'));
|
||||
|
||||
expect(await screen.findByText('Edit dataset')).toBeInTheDocument();
|
||||
expect(screen.getByText('Swap dataset')).toBeInTheDocument();
|
||||
expect(screen.queryByText('View in SQL Lab')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Should show SQL Lab for sql_lab role', async () => {
|
||||
const props = createProps({
|
||||
user: {
|
||||
createdOn: '2021-04-27T18:12:38.952304',
|
||||
email: 'sql',
|
||||
firstName: 'sql',
|
||||
isActive: true,
|
||||
lastName: 'sql',
|
||||
permissions: {},
|
||||
roles: { Gamma: [], sql_lab: [] },
|
||||
userId: 2,
|
||||
username: 'sql',
|
||||
},
|
||||
});
|
||||
render(<DatasourceControl {...props} />);
|
||||
|
||||
userEvent.click(screen.getByTestId('datasource-menu-trigger'));
|
||||
|
||||
expect(await screen.findByText('Edit dataset')).toBeInTheDocument();
|
||||
expect(screen.getByText('Swap dataset')).toBeInTheDocument();
|
||||
expect(screen.getByText('View in SQL Lab')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Click on Swap dataset option', async () => {
|
||||
const props = createProps();
|
||||
SupersetClientGet.mockImplementation(
|
||||
|
||||
Reference in New Issue
Block a user