index.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {browserHistory} from 'react-router';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {act} from 'sentry-test/reactTestingLibrary';
  4. import {triggerPress} from 'sentry-test/utils';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import ManageDashboards from 'sentry/views/dashboardsV2/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 = TestStubs.Organization({
  15. features: ['global-views', 'dashboards-basic', 'discover-query'],
  16. });
  17. const mockAuthorizedOrg = TestStubs.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. const wrapper = mountWithTheme(
  40. <ManageDashboards
  41. organization={mockUnauthorizedOrg}
  42. location={{query: {}}}
  43. router={{}}
  44. />
  45. );
  46. const content = wrapper.find('PageContent');
  47. expect(content.text()).toContain("You don't have access to this feature");
  48. });
  49. it('denies access on no projects', function () {
  50. act(() => ProjectsStore.loadInitialData([]));
  51. const wrapper = mountWithTheme(
  52. <ManageDashboards
  53. organization={mockAuthorizedOrg}
  54. location={{query: {}}}
  55. router={{}}
  56. />
  57. );
  58. const content = wrapper.find('HelpMessage');
  59. expect(content.text()).toContain('You need at least one project to use this view');
  60. });
  61. it('creates new dashboard', async function () {
  62. const org = TestStubs.Organization({features: FEATURES});
  63. const wrapper = mountWithTheme(
  64. <ManageDashboards organization={org} location={{query: {}}} router={{}} />
  65. );
  66. await tick();
  67. wrapper.find('Button[data-test-id="dashboard-create"]').simulate('click');
  68. await tick();
  69. expect(browserHistory.push).toHaveBeenCalledWith({
  70. pathname: '/organizations/org-slug/dashboards/new/',
  71. query: {},
  72. });
  73. });
  74. it('can sort', async function () {
  75. const org = TestStubs.Organization({features: FEATURES});
  76. const wrapper = mountWithTheme(
  77. <ManageDashboards organization={org} location={{query: {}}} router={{}} />
  78. );
  79. await tick();
  80. // Open sort menu
  81. await act(async () => {
  82. triggerPress(wrapper.find('CompactSelect Button'));
  83. await tick();
  84. wrapper.update();
  85. });
  86. const dropdownItems = wrapper.find('MenuItemWrap');
  87. expect(dropdownItems).toHaveLength(6);
  88. const expectedSorts = [
  89. 'My Dashboards',
  90. 'Dashboard Name (A-Z)',
  91. 'Date Created (Newest)',
  92. 'Date Created (Oldest)',
  93. 'Most Popular',
  94. 'Recently Viewed',
  95. ];
  96. expect(dropdownItems.children().map(element => element.text())).toEqual(
  97. expectedSorts
  98. );
  99. dropdownItems.at(1).simulate('click');
  100. await tick();
  101. expect(browserHistory.push).toHaveBeenCalledWith(
  102. expect.objectContaining({query: {sort: 'title'}})
  103. );
  104. });
  105. });