projectQuickLinks.spec.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ProjectQuickLinks from 'sentry/views/projectDetail/projectQuickLinks';
  4. describe('ProjectDetail > ProjectQuickLinks', function () {
  5. const {organization, router, routerContext} = initializeOrg({
  6. organization: {features: ['performance-view']},
  7. });
  8. afterEach(() => {
  9. jest.clearAllMocks();
  10. });
  11. it('renders a list', async function () {
  12. render(
  13. <ProjectQuickLinks
  14. organization={organization}
  15. location={router.location}
  16. project={TestStubs.Project()}
  17. />,
  18. {context: routerContext}
  19. );
  20. expect(screen.getByRole('heading', {name: 'Quick Links'})).toBeInTheDocument();
  21. expect(screen.getAllByRole('link')).toHaveLength(3);
  22. const userFeedback = screen.getByRole('link', {name: 'User Feedback'});
  23. const keyTransactions = screen.getByRole('link', {name: 'View Transactions'});
  24. const mostChangedTransactions = screen.getByRole('link', {
  25. name: 'Most Improved/Regressed Transactions',
  26. });
  27. await userEvent.click(userFeedback);
  28. expect(router.push).toHaveBeenCalledWith({
  29. pathname: '/organizations/org-slug/user-feedback/',
  30. query: {project: '2'},
  31. });
  32. await userEvent.click(keyTransactions);
  33. expect(router.push).toHaveBeenCalledWith({
  34. pathname: '/organizations/org-slug/performance/',
  35. query: {project: '2'},
  36. });
  37. await userEvent.click(mostChangedTransactions);
  38. expect(router.push).toHaveBeenCalledWith({
  39. pathname: '/organizations/org-slug/performance/trends/',
  40. query: {
  41. cursor: undefined,
  42. project: '2',
  43. query: 'tpm():>0.01 transaction.duration:>0 transaction.duration:<15min',
  44. },
  45. });
  46. });
  47. it('disables link if feature is missing', async function () {
  48. render(
  49. <ProjectQuickLinks
  50. organization={{...organization, features: []}}
  51. location={router.location}
  52. project={TestStubs.Project()}
  53. />,
  54. {context: routerContext}
  55. );
  56. const keyTransactions = screen.getByText('View Transactions');
  57. await userEvent.click(keyTransactions);
  58. expect(router.push).toHaveBeenCalledTimes(0);
  59. await userEvent.hover(keyTransactions);
  60. expect(
  61. await screen.findByText("You don't have access to this feature")
  62. ).toBeInTheDocument();
  63. });
  64. });