123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
- import {
- render,
- screen,
- userEvent,
- waitFor,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import ConfigStore from 'sentry/stores/configStore';
- import {Commit, Repository, User} from 'sentry/types';
- import {EventData} from 'sentry/utils/discover/eventView';
- import {ContextType, QuickContextHoverWrapper} from './quickContext';
- const defaultRow: EventData = {
- id: '6b43e285de834ec5b5fe30d62d549b20',
- issue: 'SENTRY-VVY',
- release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
- title: 'error: Error -3 while decompressing data: invalid stored block lengths',
- 'issue.id': 3512441874,
- 'project.name': 'sentry',
- };
- let mockedGroup = TestStubs.Group({
- id: '3512441874',
- project: {
- id: '1',
- slug: 'cool-team',
- },
- status: 'ignored',
- assignedTo: {
- id: '12312',
- name: 'ingest',
- type: 'team',
- },
- });
- const mockedCommit: Commit = {
- dateCreated: '2020-11-30T18:46:31Z',
- id: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
- message: 'ref(commitRow): refactor to fc\n',
- author: {
- id: '0',
- username: 'author',
- ip_address: '192.168.1.1',
- email: 'author@commit.com',
- name: 'Author',
- } as User,
- repository: {
- id: '1',
- integrationId: '2',
- name: 'getsentry/sentry',
- dateCreated: '2019-11-30T18:46:31Z',
- } as Repository,
- releases: [],
- };
- const mockedUser1 = {
- id: '2',
- username: 'author456',
- ip_address: '192.168.1.1',
- email: 'author1@commit.com',
- name: 'Key Name',
- } as User;
- const mockedUser2 = {
- id: '3',
- username: 'author123',
- ip_address: '192.168.1.3',
- email: 'author2@commit.com',
- name: 'Value Name',
- } as User;
- const mockedReleaseWithHealth = TestStubs.Release({
- id: '1',
- shortVersion: 'sentry-android-shop@1.2.0',
- version: 'sentry-android-shop@1.2.0',
- dateCreated: '2010-05-17T02:41:20Z',
- lastEvent: '2011-10-17T02:41:20Z',
- firstEvent: '2010-05-17T02:41:20Z',
- status: 'open',
- commitCount: 4,
- lastCommit: mockedCommit,
- newGroups: 21,
- authors: [mockedUser1, mockedUser2],
- });
- const queryClient = new QueryClient();
- const renderQuickContextContent = (
- dataRow: EventData = defaultRow,
- contextType: ContextType = ContextType.ISSUE
- ) => {
- const organization = TestStubs.Organization();
- render(
- <QueryClientProvider client={queryClient}>
- <QuickContextHoverWrapper
- dataRow={dataRow}
- contextType={contextType}
- organization={organization}
- >
- Text from Child
- </QuickContextHoverWrapper>
- </QueryClientProvider>,
- {organization}
- );
- };
- describe('Quick Context', function () {
- describe('Quick Context default behaviour', function () {
- afterEach(() => {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- });
- it('Renders child and trigger icon.', async () => {
- renderQuickContextContent();
- expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-hover-trigger')).toBeInTheDocument();
- });
- it('Renders quick context hover body', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByTestId('quick-context-hover-body')).toBeInTheDocument();
- });
- it('Renders quick context failure message', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- statusCode: 400,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- // Error is expected, do not fail when calling console.error
- jest.spyOn(console, 'error').mockImplementation();
- expect(
- await screen.findByText(/Failed to load context for column./i)
- ).toBeInTheDocument();
- });
- });
- describe('Quick Context Content Issue Column', function () {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- });
- afterEach(function () {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- });
- it('Renders ignored Issue status context when data is loaded', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Ignored/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-ignored-icon')).toBeInTheDocument();
- });
- it('Renders resolved Issue status context when data is loaded', async () => {
- mockedGroup = {...mockedGroup, status: 'resolved'};
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Resolved/i)).toBeInTheDocument();
- expect(screen.getByTestId('icon-check-mark')).toBeInTheDocument();
- });
- it('Renders unresolved Issue status context when data is loaded', async () => {
- mockedGroup = {...mockedGroup, status: 'unresolved'};
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Unresolved/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-unresolved-icon')).toBeInTheDocument();
- });
- it('Renders assigned To context when data is loaded', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Assigned To/i)).toBeInTheDocument();
- expect(screen.getByText(/#ingest/i)).toBeInTheDocument();
- });
- it('Does not render suspect commit to context when row lacks event id', async () => {
- const dataRowWithoutId: unknown = {
- issue: 'SENTRY-VVY',
- release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
- title: 'error: Error -3 while decompressing data: invalid stored block lengths',
- 'issue.id': 3512441874,
- 'project.name': 'sentry',
- };
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent(dataRowWithoutId as EventData);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- await waitFor(() => {
- expect(
- screen.queryByTestId('quick-context-suspect-commits-container')
- ).not.toBeInTheDocument();
- });
- });
- it('Renders Suspect Commits', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: {
- committers: [
- {
- author: {name: 'Max Bittker', id: '1'},
- commits: [
- {
- message: 'feat: Added new feature',
- score: 4,
- id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
- repository: TestStubs.Repository(),
- dateCreated: '2018-03-02T18:30:26Z',
- pullRequest: {
- externalUrl: 'url',
- },
- },
- ],
- },
- ],
- },
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Suspect Commits/i)).toBeInTheDocument();
- expect(screen.getByText(/MB/i)).toBeInTheDocument();
- expect(screen.getByText(/View commit/i)).toBeInTheDocument();
- expect(screen.getByText(/by/i)).toBeInTheDocument();
- expect(screen.getByText(/You/i)).toBeInTheDocument();
- });
- });
- describe('Quick Context Content Release Column', function () {
- afterEach(() => {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- });
- it('Renders Release details for active release', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Release Details/i)).toBeInTheDocument();
- const definitions = screen.getAllByRole('definition');
- const terms = screen.getAllByRole('term');
- expect(within(terms[0]).getByText(/Status/i)).toBeInTheDocument();
- expect(within(definitions[0]).getByText(/Active/i)).toBeInTheDocument();
- expect(within(terms[1]).getByText(/Created/i)).toBeInTheDocument();
- expect(within(definitions[1]).getByText(/7 years ago/i)).toBeInTheDocument();
- expect(within(terms[2]).getByText(/First Event/i)).toBeInTheDocument();
- expect(within(definitions[2]).getByText(/7 years ago/i)).toBeInTheDocument();
- expect(within(terms[3]).getByText(/Last Event/i)).toBeInTheDocument();
- expect(within(definitions[3]).getByText(/6 years ago/i)).toBeInTheDocument();
- });
- it('Renders Release details for archived release', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: {...mockedReleaseWithHealth, status: 'closed'},
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Release Details/i)).toBeInTheDocument();
- expect(screen.getByText(/Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Archived/i)).toBeInTheDocument();
- expect(screen.queryByText(/Created/i)).not.toBeInTheDocument();
- expect(screen.queryByText(/First Event/i)).not.toBeInTheDocument();
- expect(screen.queryByText(/Last Event/i)).not.toBeInTheDocument();
- });
- it('Renders Last Commit', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/Last Commit/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-commit-row')).toBeInTheDocument();
- });
- it('Renders New Issues Count', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/New Issues/i)).toBeInTheDocument();
- expect(screen.getByText(/21/i)).toBeInTheDocument();
- });
- it('Renders Commit Count and Author when user is NOT in list of authors', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/4/i)).toBeInTheDocument();
- expect(screen.getByText(/commits by/i)).toBeInTheDocument();
- expect(screen.getAllByText(/2/i)).toHaveLength(2);
- expect(screen.getByText(/authors/i)).toBeInTheDocument();
- expect(screen.getByText(/KN/i)).toBeInTheDocument();
- expect(screen.getByText(/VN/i)).toBeInTheDocument();
- });
- it('Renders Commit Count and Author when user is in list of authors', async () => {
- jest.spyOn(ConfigStore, 'get').mockImplementation(() => mockedUser1);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
- expect(await screen.findByText(/4/i)).toBeInTheDocument();
- expect(screen.getByText(/commits by you and/i)).toBeInTheDocument();
- expect(screen.getAllByText(/1/i)).toHaveLength(2);
- expect(screen.getByText(/other/i)).toBeInTheDocument();
- expect(screen.getByText(/KN/i)).toBeInTheDocument();
- expect(screen.getByText(/VN/i)).toBeInTheDocument();
- });
- });
- });
|