Skip to content

Commit

Permalink
fix: Revert "fix: RBAC hide right menu (apache#16902)" (apache#16968)
Browse files Browse the repository at this point in the history
* Revert "fix: RBAC hide right menu (apache#16902)"

This reverts commit 87baac7.

* fix failing test

(cherry picked from commit 5866d5e)
  • Loading branch information
eschutho committed Oct 27, 2021
1 parent 083ff12 commit a6a3ced
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/
import React from 'react';
import { render } from 'spec/helpers/testing-library';
import { shallow } from 'enzyme';

import HoverMenu from 'src/dashboard/components/menu/HoverMenu';

describe('HoverMenu', () => {
it('should render a hover menu', () => {
const rendered = render(<HoverMenu />);
const hoverMenu = rendered.container.querySelector('.hover-menu');
expect(hoverMenu).toBeVisible();
it('should render a div.hover-menu', () => {
const wrapper = shallow(<HoverMenu />);
expect(wrapper.find('.hover-menu')).toExist();
});
});
52 changes: 0 additions & 52 deletions superset-frontend/src/components/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,12 @@
* under the License.
*/
import React from 'react';
import * as reactRedux from 'react-redux';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import { Menu } from './Menu';
import { dropdownItems } from './MenuRight';

const user = {
createdOn: '2021-04-27T18:12:38.952304',
email: 'admin',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
roles: {
Admin: [
['can_sqllab', 'Superset'],
['can_write', 'Dashboard'],
['can_write', 'Chart'],
],
},
userId: 1,
username: 'admin',
};

const mockedProps = {
user,
data: {
menu: [
{
Expand Down Expand Up @@ -156,27 +136,17 @@ const notanonProps = {
},
};

const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');

beforeEach(() => {
// setup a DOM element as a render target
useSelectorMock.mockClear();
});

test('should render', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const { container } = render(<Menu {...mockedProps} />);
expect(container).toBeInTheDocument();
});

test('should render the navigation', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
expect(screen.getByRole('navigation')).toBeInTheDocument();
});

test('should render the brand', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
brand: { alt, icon },
Expand All @@ -188,7 +158,6 @@ test('should render the brand', () => {
});

test('should render all the top navbar menu items', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: { menu },
} = mockedProps;
Expand All @@ -199,7 +168,6 @@ test('should render all the top navbar menu items', () => {
});

test('should render the top navbar child menu items', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: { menu },
} = mockedProps;
Expand All @@ -216,7 +184,6 @@ test('should render the top navbar child menu items', async () => {
});

test('should render the dropdown items', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...notanonProps} />);
const dropdown = screen.getByTestId('new-dropdown-icon');
userEvent.hover(dropdown);
Expand Down Expand Up @@ -244,22 +211,19 @@ test('should render the dropdown items', async () => {
});

test('should render the Settings', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
const settings = await screen.findByText('Settings');
expect(settings).toBeInTheDocument();
});

test('should render the Settings menu item', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
userEvent.hover(screen.getByText('Settings'));
const label = await screen.findByText('Security');
expect(label).toBeInTheDocument();
});

test('should render the Settings dropdown child menu items', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: { settings },
} = mockedProps;
Expand All @@ -270,19 +234,16 @@ test('should render the Settings dropdown child menu items', async () => {
});

test('should render the plus menu (+) when user is not anonymous', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...notanonProps} />);
expect(screen.getByTestId('new-dropdown')).toBeInTheDocument();
});

test('should NOT render the plus menu (+) when user is anonymous', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
});

test('should render the user actions when user is not anonymous', async () => {
useSelectorMock.mockReturnValue({ roles: mockedProps.user.roles });
const {
data: {
navbar_right: { user_info_url, user_logout_url },
Expand All @@ -302,13 +263,11 @@ test('should render the user actions when user is not anonymous', async () => {
});

test('should NOT render the user actions when user is anonymous', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
expect(screen.queryByText('User')).not.toBeInTheDocument();
});

test('should render the Profile link when available', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
navbar_right: { user_profile_url },
Expand All @@ -323,7 +282,6 @@ test('should render the Profile link when available', async () => {
});

test('should render the About section and version_string, sha or build_number when available', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
navbar_right: { version_sha, version_string, build_number },
Expand All @@ -343,7 +301,6 @@ test('should render the About section and version_string, sha or build_number wh
});

test('should render the Documentation link when available', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
navbar_right: { documentation_url },
Expand All @@ -356,7 +313,6 @@ test('should render the Documentation link when available', async () => {
});

test('should render the Bug Report link when available', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
navbar_right: { bug_report_url },
Expand All @@ -369,7 +325,6 @@ test('should render the Bug Report link when available', async () => {
});

test('should render the Login link when user is anonymous', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
navbar_right: { user_login_url },
Expand All @@ -382,13 +337,6 @@ test('should render the Login link when user is anonymous', () => {
});

test('should render the Language Picker', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
render(<Menu {...mockedProps} />);
expect(screen.getByLabelText('Languages')).toBeInTheDocument();
});

test('should hide create button without proper roles', () => {
useSelectorMock.mockReturnValue({ roles: [] });
render(<Menu {...notanonProps} />);
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
});
Loading

0 comments on commit a6a3ced

Please sign in to comment.