index.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {browserHistory} from 'react-router';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  5. import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import selectEvent from 'sentry-test/selectEvent';
  7. import ProjectsStore from 'sentry/stores/projectsStore';
  8. import ManageDashboards from 'sentry/views/dashboards/manage';
  9. const FEATURES = [
  10. 'global-views',
  11. 'dashboards-basic',
  12. 'dashboards-edit',
  13. 'discover-query',
  14. ];
  15. describe('Dashboards > Detail', function () {
  16. const mockUnauthorizedOrg = OrganizationFixture({
  17. features: ['global-views', 'dashboards-basic', 'discover-query'],
  18. });
  19. const mockAuthorizedOrg = OrganizationFixture({
  20. features: FEATURES,
  21. });
  22. beforeEach(function () {
  23. act(() => ProjectsStore.loadInitialData([ProjectFixture()]));
  24. MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/projects/',
  26. body: [],
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/dashboards/',
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/dashboards/?sort=name&per_page=9',
  34. body: [],
  35. });
  36. });
  37. afterEach(function () {
  38. MockApiClient.clearMockResponses();
  39. });
  40. it('denies access on missing feature', function () {
  41. render(
  42. <ManageDashboards
  43. {...RouteComponentPropsFixture()}
  44. organization={mockUnauthorizedOrg}
  45. />
  46. );
  47. expect(screen.getByText("You don't have access to this feature")).toBeInTheDocument();
  48. });
  49. it('denies access on no projects', function () {
  50. act(() => ProjectsStore.loadInitialData([]));
  51. render(
  52. <ManageDashboards
  53. {...RouteComponentPropsFixture()}
  54. organization={mockAuthorizedOrg}
  55. />
  56. );
  57. expect(
  58. screen.getByText('You need at least one project to use this view')
  59. ).toBeInTheDocument();
  60. });
  61. it('creates new dashboard', async function () {
  62. const org = OrganizationFixture({features: FEATURES});
  63. render(<ManageDashboards {...RouteComponentPropsFixture()} organization={org} />);
  64. await userEvent.click(screen.getByTestId('dashboard-create'));
  65. expect(browserHistory.push).toHaveBeenCalledWith({
  66. pathname: '/organizations/org-slug/dashboards/new/',
  67. query: {},
  68. });
  69. });
  70. it('can sort', async function () {
  71. const org = OrganizationFixture({features: FEATURES});
  72. render(<ManageDashboards {...RouteComponentPropsFixture()} organization={org} />);
  73. await selectEvent.select(
  74. screen.getByRole('button', {name: /sort by/i}),
  75. 'Dashboard Name (A-Z)'
  76. );
  77. await waitFor(() => {
  78. expect(browserHistory.push).toHaveBeenCalledWith(
  79. expect.objectContaining({query: {sort: 'title'}})
  80. );
  81. });
  82. });
  83. });