projectQuickLinks.spec.tsx 2.4 KB

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