mirror of
https://github.com/apache/superset.git
synced 2024-09-07 06:17:45 -04:00
test: Fix act errors in Menu test (#21391)
This commit is contained in:
parent
feb581046f
commit
ec3b3601d8
@ -252,27 +252,28 @@ beforeEach(() => {
|
|||||||
useSelectorMock.mockClear();
|
useSelectorMock.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render', () => {
|
test('should render', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
const { container } = render(<Menu {...mockedProps} />, {
|
const { container } = render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByText(/sources/i)).toBeInTheDocument();
|
||||||
expect(container).toBeInTheDocument();
|
expect(container).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the navigation', () => {
|
test('should render the navigation', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
render(<Menu {...mockedProps} />, {
|
render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
expect(screen.getByRole('navigation')).toBeInTheDocument();
|
expect(await screen.findByRole('navigation')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the brand', () => {
|
test('should render the brand', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
const {
|
const {
|
||||||
data: {
|
data: {
|
||||||
@ -284,20 +285,21 @@ test('should render the brand', () => {
|
|||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByAltText(alt)).toBeInTheDocument();
|
||||||
const image = screen.getByAltText(alt);
|
const image = screen.getByAltText(alt);
|
||||||
expect(image).toHaveAttribute('src', icon);
|
expect(image).toHaveAttribute('src', icon);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the environment tag', () => {
|
test('should render the environment tag', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
const {
|
const {
|
||||||
data: { environment_tag },
|
data: { environment_tag },
|
||||||
} = mockedProps;
|
} = mockedProps;
|
||||||
render(<Menu {...mockedProps} />, { useRedux: true });
|
render(<Menu {...mockedProps} />, { useRedux: true, useQueryParams: true });
|
||||||
expect(screen.getByText(environment_tag.text)).toBeInTheDocument();
|
expect(await screen.findByText(environment_tag.text)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render all the top navbar menu items', () => {
|
test('should render all the top navbar menu items', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
const {
|
const {
|
||||||
data: { menu },
|
data: { menu },
|
||||||
@ -307,6 +309,7 @@ test('should render all the top navbar menu items', () => {
|
|||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByText(menu[0].label)).toBeInTheDocument();
|
||||||
menu.forEach(item => {
|
menu.forEach(item => {
|
||||||
expect(screen.getByText(item.label)).toBeInTheDocument();
|
expect(screen.getByText(item.label)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
@ -401,23 +404,24 @@ test('should render the Settings dropdown child menu items', async () => {
|
|||||||
expect(listUsers).toHaveAttribute('href', settings[0].childs[0].url);
|
expect(listUsers).toHaveAttribute('href', settings[0].childs[0].url);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the plus menu (+) when user is not anonymous', () => {
|
test('should render the plus menu (+) when user is not anonymous', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
render(<Menu {...notanonProps} />, {
|
render(<Menu {...notanonProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
expect(screen.getByTestId('new-dropdown')).toBeInTheDocument();
|
expect(await screen.findByTestId('new-dropdown')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should NOT render the plus menu (+) when user is anonymous', () => {
|
test('should NOT render the plus menu (+) when user is anonymous', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
render(<Menu {...mockedProps} />, {
|
render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByText(/sources/i)).toBeInTheDocument();
|
||||||
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -445,13 +449,14 @@ test('should render the user actions when user is not anonymous', async () => {
|
|||||||
expect(logout).toHaveAttribute('href', user_logout_url);
|
expect(logout).toHaveAttribute('href', user_logout_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should NOT render the user actions when user is anonymous', () => {
|
test('should NOT render the user actions when user is anonymous', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
render(<Menu {...mockedProps} />, {
|
render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByText(/sources/i)).toBeInTheDocument();
|
||||||
expect(screen.queryByText('User')).not.toBeInTheDocument();
|
expect(screen.queryByText('User')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -532,7 +537,7 @@ test('should render the Bug Report link when available', async () => {
|
|||||||
expect(bugReport).toHaveAttribute('href', bug_report_url);
|
expect(bugReport).toHaveAttribute('href', bug_report_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the Login link when user is anonymous', () => {
|
test('should render the Login link when user is anonymous', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
const {
|
const {
|
||||||
data: {
|
data: {
|
||||||
@ -545,37 +550,43 @@ test('should render the Login link when user is anonymous', () => {
|
|||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
const login = screen.getByText('Login');
|
const login = await screen.findByText('Login');
|
||||||
expect(login).toHaveAttribute('href', user_login_url);
|
expect(login).toHaveAttribute('href', user_login_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render the Language Picker', () => {
|
test('should render the Language Picker', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: user.roles });
|
useSelectorMock.mockReturnValue({ roles: user.roles });
|
||||||
render(<Menu {...mockedProps} />, {
|
render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
expect(screen.getByLabelText('Languages')).toBeInTheDocument();
|
expect(await screen.findByLabelText('Languages')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should hide create button without proper roles', () => {
|
test('should hide create button without proper roles', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: [] });
|
useSelectorMock.mockReturnValue({ roles: [] });
|
||||||
render(<Menu {...mockedProps} />, {
|
render(<Menu {...mockedProps} />, {
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
useQueryParams: true,
|
useQueryParams: true,
|
||||||
useRouter: true,
|
useRouter: true,
|
||||||
});
|
});
|
||||||
|
expect(await screen.findByText(/sources/i)).toBeInTheDocument();
|
||||||
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render without QueryParamProvider', () => {
|
test('should render without QueryParamProvider', async () => {
|
||||||
useSelectorMock.mockReturnValue({ roles: [] });
|
useSelectorMock.mockReturnValue({ roles: [] });
|
||||||
render(<Menu {...mockedProps} />, { useRedux: true, useRouter: true });
|
render(<Menu {...mockedProps} />, {
|
||||||
|
useRedux: true,
|
||||||
|
useRouter: true,
|
||||||
|
useQueryParams: true,
|
||||||
|
});
|
||||||
|
expect(await screen.findByText(/sources/i)).toBeInTheDocument();
|
||||||
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render an extension component if one is supplied', () => {
|
test('should render an extension component if one is supplied', async () => {
|
||||||
const extensionsRegistry = getExtensionsRegistry();
|
const extensionsRegistry = getExtensionsRegistry();
|
||||||
|
|
||||||
extensionsRegistry.set('navbar.right', () => (
|
extensionsRegistry.set('navbar.right', () => (
|
||||||
@ -584,9 +595,9 @@ test('should render an extension component if one is supplied', () => {
|
|||||||
|
|
||||||
setupExtensions();
|
setupExtensions();
|
||||||
|
|
||||||
render(<Menu {...mockedProps} />, { useRouter: true });
|
render(<Menu {...mockedProps} />, { useRouter: true, useQueryParams: true });
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText('navbar.right extension component'),
|
await screen.findByText('navbar.right extension component'),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user