123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import React from 'react';
- import moment from 'moment';
- import {mount} from 'enzyme';
- import EventCauseEmpty from 'app/components/events/eventCauseEmpty';
- import {trackAdhocEvent, trackAnalyticsEvent} from 'app/utils/analytics';
- jest.mock('app/utils/analytics');
- describe('EventCauseEmpty', function() {
- let putMock;
- const routerContext = TestStubs.routerContext();
- const organization = TestStubs.Organization();
- const project = TestStubs.Project({platform: 'javascript'});
- beforeEach(function() {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/releases/completion/',
- body: [{step: 'commit', complete: false}],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/promptsactivity/',
- body: {},
- });
- putMock = MockApiClient.addMockResponse({
- method: 'PUT',
- url: '/promptsactivity/',
- });
- });
- it('renders', async function() {
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(true);
- expect(trackAdhocEvent).toHaveBeenCalledWith({
- eventKey: 'event_cause.viewed',
- org_id: parseInt(organization.id, 10),
- project_id: parseInt(project.id, 10),
- platform: project.platform,
- });
- });
- it('can be snoozed', async function() {
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- wrapper
- .find('[data-test-id="snoozed"]')
- .first()
- .simulate('click');
- expect(putMock).toHaveBeenCalledWith(
- '/promptsactivity/',
- expect.objectContaining({
- method: 'PUT',
- data: {
- organization_id: organization.id,
- project_id: project.id,
- feature: 'suspect_commits',
- status: 'snoozed',
- },
- })
- );
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
- expect(trackAnalyticsEvent).toHaveBeenCalledWith({
- eventKey: 'event_cause.snoozed',
- eventName: 'Event Cause Snoozed',
- organization_id: parseInt(organization.id, 10),
- project_id: parseInt(project.id, 10),
- platform: project.platform,
- });
- });
- it('does not render when snoozed', async function() {
- const snoozed_ts = moment()
- .subtract(1, 'day')
- .unix();
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/promptsactivity/',
- body: {data: {snoozed_ts}},
- });
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
- });
- it('renders when snoozed more than 7 days ago', async function() {
- const snoozed_ts = moment()
- .subtract(9, 'day')
- .unix();
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/promptsactivity/',
- body: {data: {snoozed_ts}},
- });
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(true);
- });
- it('can be dismissed', async function() {
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- wrapper
- .find('[data-test-id="dismissed"]')
- .first()
- .simulate('click');
- expect(putMock).toHaveBeenCalledWith(
- '/promptsactivity/',
- expect.objectContaining({
- method: 'PUT',
- data: {
- organization_id: organization.id,
- project_id: project.id,
- feature: 'suspect_commits',
- status: 'dismissed',
- },
- })
- );
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
- expect(trackAnalyticsEvent).toHaveBeenCalledWith({
- eventKey: 'event_cause.dismissed',
- eventName: 'Event Cause Dismissed',
- organization_id: parseInt(organization.id, 10),
- project_id: parseInt(project.id, 10),
- platform: project.platform,
- });
- });
- it('does not render when dismissed', async function() {
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/promptsactivity/',
- body: {data: {dismissed_ts: moment().unix()}},
- });
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
- });
- it('can capture analytics on docs click', async function() {
- const wrapper = mount(
- <EventCauseEmpty organization={organization} project={project} />,
- routerContext
- );
- await tick();
- wrapper.update();
- wrapper
- .find('[data-test-id="read-the-docs"]')
- .first()
- .simulate('click');
- expect(trackAnalyticsEvent).toHaveBeenCalledWith({
- eventKey: 'event_cause.docs_clicked',
- eventName: 'Event Cause Docs Clicked',
- organization_id: parseInt(organization.id, 10),
- project_id: parseInt(project.id, 10),
- platform: project.platform,
- });
- });
- });
|