123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- import {Fragment} from 'react';
- import {browserHistory} from 'react-router';
- import {
- render,
- screen,
- userEvent,
- waitFor,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import GlobalModal from 'sentry/components/globalModal';
- import ConfigStore from 'sentry/stores/configStore';
- import ModalStore from 'sentry/stores/modalStore';
- import {IssueCategory} from 'sentry/types';
- import * as analytics from 'sentry/utils/analytics';
- import GroupActions from 'sentry/views/issueDetails/actions';
- const project = TestStubs.ProjectDetails({
- id: '2448',
- name: 'project name',
- slug: 'project',
- });
- const group = TestStubs.Group({
- id: '1337',
- pluginActions: [],
- pluginIssues: [],
- issueCategory: IssueCategory.ERROR,
- project,
- });
- const organization = TestStubs.Organization({
- id: '4660',
- slug: 'org',
- features: ['reprocessing-v2'],
- });
- describe('GroupActions', function () {
- const analyticsSpy = jest.spyOn(analytics, 'trackAnalytics');
- beforeEach(function () {
- ConfigStore.init();
- jest.spyOn(ConfigStore, 'get').mockImplementation(() => []);
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- });
- describe('render()', function () {
- it('renders correctly', function () {
- const wrapper = render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- disabled={false}
- />
- );
- expect(wrapper.container).toSnapshot();
- });
- });
- describe('subscribing', function () {
- let issuesApi: any;
- beforeEach(function () {
- issuesApi = MockApiClient.addMockResponse({
- url: '/projects/org/project/issues/',
- method: 'PUT',
- body: TestStubs.Group({isSubscribed: false}),
- });
- });
- it('can subscribe', async function () {
- render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- disabled={false}
- />
- );
- await userEvent.click(screen.getByRole('button', {name: 'Subscribe'}));
- expect(issuesApi).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: {isSubscribed: true},
- })
- );
- });
- });
- describe('bookmarking', function () {
- let issuesApi: any;
- beforeEach(function () {
- issuesApi = MockApiClient.addMockResponse({
- url: '/projects/org/project/issues/',
- method: 'PUT',
- body: TestStubs.Group({isBookmarked: false}),
- });
- });
- it('can bookmark', async function () {
- render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- disabled={false}
- />
- );
- await userEvent.click(screen.getByLabelText('More Actions'));
- const bookmark = await screen.findByTestId('bookmark');
- await userEvent.click(bookmark);
- expect(issuesApi).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: {isBookmarked: true},
- })
- );
- });
- });
- describe('reprocessing', function () {
- it('renders ReprocessAction component if org has feature flag reprocessing-v2 and native exception event', async function () {
- const event = TestStubs.EventStacktraceException({
- platform: 'native',
- });
- render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- event={event}
- disabled={false}
- />
- );
- await userEvent.click(screen.getByLabelText('More Actions'));
- const reprocessActionButton = await screen.findByTestId('reprocess');
- expect(reprocessActionButton).toBeInTheDocument();
- });
- it('open dialog by clicking on the ReprocessAction component', async function () {
- const event = TestStubs.EventStacktraceException({
- platform: 'native',
- });
- render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- event={event}
- disabled={false}
- />
- );
- const onReprocessEventFunc = jest.spyOn(ModalStore, 'openModal');
- await userEvent.click(screen.getByLabelText('More Actions'));
- const reprocessActionButton = await screen.findByTestId('reprocess');
- expect(reprocessActionButton).toBeInTheDocument();
- await userEvent.click(reprocessActionButton);
- await waitFor(() => expect(onReprocessEventFunc).toHaveBeenCalled());
- });
- });
- it('opens share modal from more actions dropdown', async () => {
- const org = {
- ...organization,
- features: ['shared-issues'],
- };
- const updateMock = MockApiClient.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/issues/`,
- method: 'PUT',
- body: {},
- });
- render(
- <Fragment>
- <GlobalModal />
- <GroupActions
- group={group}
- project={project}
- organization={org}
- disabled={false}
- />
- </Fragment>,
- {organization: org}
- );
- await userEvent.click(screen.getByLabelText('More Actions'));
- await userEvent.click(await screen.findByText('Share'));
- const modal = screen.getByRole('dialog');
- expect(within(modal).getByText('Share Issue')).toBeInTheDocument();
- expect(updateMock).toHaveBeenCalled();
- });
- it('opens delete confirm modal from more actions dropdown', async () => {
- const org = {
- ...organization,
- access: [...organization.access, 'event:admin'],
- };
- MockApiClient.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/issues/`,
- method: 'PUT',
- body: {},
- });
- const deleteMock = MockApiClient.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/issues/`,
- method: 'DELETE',
- body: {},
- });
- render(
- <Fragment>
- <GlobalModal />
- <GroupActions
- group={group}
- project={project}
- organization={org}
- disabled={false}
- />
- </Fragment>,
- {organization: org}
- );
- await userEvent.click(screen.getByLabelText('More Actions'));
- await userEvent.click(await screen.findByRole('menuitemradio', {name: 'Delete'}));
- const modal = screen.getByRole('dialog');
- expect(
- within(modal).getByText(/Deleting this issue is permanent/)
- ).toBeInTheDocument();
- await userEvent.click(within(modal).getByRole('button', {name: 'Delete'}));
- expect(deleteMock).toHaveBeenCalled();
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: `/organizations/${organization.slug}/issues/`,
- query: {project: project.id},
- });
- });
- it('resolves and unresolves issue', async () => {
- const issuesApi = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/project/issues/`,
- method: 'PUT',
- body: {...group, status: 'resolved'},
- });
- const {rerender} = render(
- <GroupActions
- group={group}
- project={project}
- organization={organization}
- disabled={false}
- />,
- {organization}
- );
- await userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
- expect(issuesApi).toHaveBeenCalledWith(
- `/projects/${organization.slug}/project/issues/`,
- expect.objectContaining({
- data: {status: 'resolved', statusDetails: {}, substatus: null},
- })
- );
- expect(analyticsSpy).toHaveBeenCalledWith(
- 'issue_details.action_clicked',
- expect.objectContaining({
- action_type: 'resolved',
- })
- );
- rerender(
- <GroupActions
- group={{...group, status: 'resolved'}}
- project={project}
- organization={organization}
- disabled={false}
- />
- );
- await userEvent.click(screen.getByRole('button', {name: 'Resolved'}));
- expect(issuesApi).toHaveBeenCalledWith(
- `/projects/${organization.slug}/project/issues/`,
- expect.objectContaining({
- data: {status: 'unresolved', statusDetails: {}, substatus: 'ongoing'},
- })
- );
- });
- it('can archive issue', async () => {
- const org = {...organization, features: ['escalating-issues']};
- const issuesApi = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/project/issues/`,
- method: 'PUT',
- body: {...group, status: 'resolved'},
- });
- render(
- <GroupActions
- group={group}
- project={project}
- organization={org}
- disabled={false}
- />,
- {organization: org}
- );
- await userEvent.click(await screen.findByRole('button', {name: 'Archive'}));
- expect(issuesApi).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: {
- status: 'ignored',
- statusDetails: {},
- substatus: 'archived_until_escalating',
- },
- })
- );
- expect(analyticsSpy).toHaveBeenCalledWith(
- 'issue_details.action_clicked',
- expect.objectContaining({
- action_substatus: 'archived_until_escalating',
- action_type: 'ignored',
- })
- );
- });
- });
|