index.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/dashboardsV2/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. organization={mockUnauthorizedOrg}
  41. location={{query: {}}}
  42. router={{}}
  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. organization={mockAuthorizedOrg}
  52. location={{query: {}}}
  53. router={{}}
  54. />
  55. );
  56. expect(
  57. screen.getByText('You need at least one project to use this view')
  58. ).toBeInTheDocument();
  59. });
  60. it('creates new dashboard', function () {
  61. const org = TestStubs.Organization({features: FEATURES});
  62. render(<ManageDashboards organization={org} location={{query: {}}} router={{}} />);
  63. userEvent.click(screen.getByTestId('dashboard-create'));
  64. expect(browserHistory.push).toHaveBeenCalledWith({
  65. pathname: '/organizations/org-slug/dashboards/new/',
  66. query: {},
  67. });
  68. });
  69. it('can sort', async function () {
  70. const org = TestStubs.Organization({features: FEATURES});
  71. render(<ManageDashboards organization={org} location={{query: {}}} router={{}} />);
  72. await selectEvent.select(
  73. screen.getByRole('button', {name: /sort by/i}),
  74. 'Dashboard Name (A-Z)'
  75. );
  76. await waitFor(() => {
  77. expect(browserHistory.push).toHaveBeenCalledWith(
  78. expect.objectContaining({query: {sort: 'title'}})
  79. );
  80. });
  81. });
  82. });