index.spec.tsx 2.7 KB

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