index.spec.tsx 2.7 KB

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