Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(js): Convert ManageDashboards test to RTL #41352

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 20 additions & 49 deletions static/app/views/dashboardsV2/manage/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {browserHistory} from 'react-router';
import selectEvent from 'react-select-event';

import {mountWithTheme} from 'sentry-test/enzyme';
import {act} from 'sentry-test/reactTestingLibrary';
import {triggerPress} from 'sentry-test/utils';
import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import ManageDashboards from 'sentry/views/dashboardsV2/manage';
Expand Down Expand Up @@ -43,43 +42,39 @@ describe('Dashboards > Detail', function () {
});

it('denies access on missing feature', function () {
const wrapper = mountWithTheme(
render(
<ManageDashboards
organization={mockUnauthorizedOrg}
location={{query: {}}}
router={{}}
/>
);

const content = wrapper.find('PageContent');
expect(content.text()).toContain("You don't have access to this feature");
expect(screen.getByText("You don't have access to this feature")).toBeInTheDocument();
});

it('denies access on no projects', function () {
act(() => ProjectsStore.loadInitialData([]));

const wrapper = mountWithTheme(
render(
<ManageDashboards
organization={mockAuthorizedOrg}
location={{query: {}}}
router={{}}
/>
);

const content = wrapper.find('HelpMessage');
expect(content.text()).toContain('You need at least one project to use this view');
expect(
screen.getByText('You need at least one project to use this view')
).toBeInTheDocument();
});

it('creates new dashboard', async function () {
it('creates new dashboard', function () {
const org = TestStubs.Organization({features: FEATURES});

const wrapper = mountWithTheme(
<ManageDashboards organization={org} location={{query: {}}} router={{}} />
);
await tick();
render(<ManageDashboards organization={org} location={{query: {}}} router={{}} />);

wrapper.find('Button[data-test-id="dashboard-create"]').simulate('click');
await tick();
userEvent.click(screen.getByTestId('dashboard-create'));

expect(browserHistory.push).toHaveBeenCalledWith({
pathname: '/organizations/org-slug/dashboards/new/',
Expand All @@ -90,41 +85,17 @@ describe('Dashboards > Detail', function () {
it('can sort', async function () {
const org = TestStubs.Organization({features: FEATURES});

const wrapper = mountWithTheme(
<ManageDashboards organization={org} location={{query: {}}} router={{}} />
);
await tick();

// Open sort menu
await act(async () => {
triggerPress(wrapper.find('CompactSelect Button'));

await tick();
wrapper.update();
});

const dropdownItems = wrapper.find('MenuItemWrap');
expect(dropdownItems).toHaveLength(6);
render(<ManageDashboards organization={org} location={{query: {}}} router={{}} />);

const expectedSorts = [
'My Dashboards',
'Dashboard Name (A-Z)',
'Date Created (Newest)',
'Date Created (Oldest)',
'Most Popular',
'Recently Viewed',
];

expect(dropdownItems.children().map(element => element.text())).toEqual(
expectedSorts
await selectEvent.select(
screen.getByRole('button', {name: /sort by/i}),
'Dashboard Name (A-Z)'
);

dropdownItems.at(1).simulate('click');

await tick();

expect(browserHistory.push).toHaveBeenCalledWith(
expect.objectContaining({query: {sort: 'title'}})
);
await waitFor(() => {
expect(browserHistory.push).toHaveBeenCalledWith(
expect.objectContaining({query: {sort: 'title'}})
);
});
});
});