context.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import ProjectsStore from 'sentry/stores/projectsStore';
  3. import {Coverage, Frame, LineCoverage} from 'sentry/types';
  4. import Context, {getCoverageColorClass} from './context';
  5. describe('Frame - Context', function () {
  6. const org = TestStubs.Organization();
  7. const project = TestStubs.Project({});
  8. const event = TestStubs.Event({projectID: project.id});
  9. const integration = TestStubs.GitHubIntegration();
  10. const repo = TestStubs.Repository({integrationId: integration.id});
  11. const frame = {filename: '/sentry/app.py', lineNo: 233} as Frame;
  12. const config = TestStubs.RepositoryProjectPathConfig({project, repo, integration});
  13. beforeEach(function () {
  14. jest.clearAllMocks();
  15. MockApiClient.clearMockResponses();
  16. ProjectsStore.loadInitialData([project]);
  17. });
  18. const lines: Array<[number, string]> = [
  19. [231, 'this is line 231'],
  20. [232, 'this is line 232'],
  21. [233, 'this is line 233'],
  22. [234, 'this is line 234'],
  23. ];
  24. const lineCoverage: LineCoverage[] = [
  25. [230, Coverage.PARTIAL],
  26. [231, Coverage.PARTIAL],
  27. [232, Coverage.COVERED],
  28. [234, Coverage.NOT_COVERED],
  29. ];
  30. const primaryLineNumber = 233;
  31. it('converts coverage data to the right colors', function () {
  32. expect(getCoverageColorClass(lines, lineCoverage, primaryLineNumber)).toEqual([
  33. ['partial', 'covered', 'active', 'uncovered'],
  34. true,
  35. ]);
  36. });
  37. it("doesn't query stacktrace link if the flag is off", function () {
  38. const mock = MockApiClient.addMockResponse({
  39. url: `/projects/${org.slug}/${project.slug}/stacktrace-link/`,
  40. body: {
  41. config,
  42. sourceUrl: null,
  43. integrations: [integration],
  44. },
  45. });
  46. render(
  47. <Context
  48. frame={frame}
  49. event={event}
  50. organization={org}
  51. registers={{}}
  52. components={[]}
  53. />,
  54. {
  55. context: TestStubs.routerContext([{organization: org}]),
  56. organization: org,
  57. project,
  58. }
  59. );
  60. expect(mock).not.toHaveBeenCalled();
  61. });
  62. });