diff options
Diffstat (limited to 'spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js')
-rw-r--r-- | spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js | 131 |
1 files changed, 98 insertions, 33 deletions
diff --git a/spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js b/spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js index f26cdcb8b20..e08bd80b18e 100644 --- a/spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js +++ b/spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js @@ -1,7 +1,11 @@ import { mount } from '@vue/test-utils'; + import { stubTransition } from 'helpers/stub_transition'; import { createMockDirective } from 'helpers/vue_mock_directive'; import TimeTracker from '~/sidebar/components/time_tracking/time_tracker.vue'; +import SidebarEventHub from '~/sidebar/event_hub'; + +import { issuableTimeTrackingResponse } from '../../mock_data'; describe('Issuable Time Tracker', () => { let wrapper; @@ -13,21 +17,39 @@ describe('Issuable Time Tracker', () => { const findReportLink = () => findByTestId('reportLink'); const defaultProps = { - timeEstimate: 10_000, // 2h 46m - timeSpent: 5_000, // 1h 23m - humanTimeEstimate: '2h 46m', - humanTimeSpent: '1h 23m', limitToHours: false, + fullPath: 'gitlab-org/gitlab-test', + issuableIid: '1', + initialTimeTracking: { + ...issuableTimeTrackingResponse.data.workspace.issuable, + }, }; - const mountComponent = ({ props = {} } = {}) => - mount(TimeTracker, { + const issuableTimeTrackingRefetchSpy = jest.fn(); + + const mountComponent = ({ props = {}, issuableType = 'issue', loading = false } = {}) => { + return mount(TimeTracker, { propsData: { ...defaultProps, ...props }, directives: { GlTooltip: createMockDirective() }, stubs: { transition: stubTransition(), }, + provide: { + issuableType, + }, + mocks: { + $apollo: { + queries: { + issuableTimeTracking: { + loading, + refetch: issuableTimeTrackingRefetchSpy, + query: jest.fn().mockResolvedValue(issuableTimeTrackingResponse), + }, + }, + }, + }, }); + }; afterEach(() => { wrapper.destroy(); @@ -44,13 +66,13 @@ describe('Issuable Time Tracker', () => { it('should correctly render timeEstimate', () => { expect(findByTestId('timeTrackingComparisonPane').html()).toContain( - defaultProps.humanTimeEstimate, + defaultProps.initialTimeTracking.humanTimeEstimate, ); }); - it('should correctly render time_spent', () => { + it('should correctly render totalTimeSpent', () => { expect(findByTestId('timeTrackingComparisonPane').html()).toContain( - defaultProps.humanTimeSpent, + defaultProps.initialTimeTracking.humanTotalTimeSpent, ); }); }); @@ -78,10 +100,12 @@ describe('Issuable Time Tracker', () => { beforeEach(() => { wrapper = mountComponent({ props: { - timeEstimate: 100_000, // 1d 3h - timeSpent: 5_000, // 1h 23m - humanTimeEstimate: '1d 3h', - humanTimeSpent: '1h 23m', + initialTimeTracking: { + timeEstimate: 100_000, // 1d 3h + totalTimeSpent: 5_000, // 1h 23m + humanTimeEstimate: '1d 3h', + humanTotalTimeSpent: '1h 23m', + }, }, }); }); @@ -108,8 +132,11 @@ describe('Issuable Time Tracker', () => { it('should display the remaining meter with the correct background color when over estimate', () => { wrapper = mountComponent({ props: { - timeEstimate: 10_000, // 2h 46m - timeSpent: 20_000_000, // 231 days + initialTimeTracking: { + ...defaultProps.initialTimeTracking, + timeEstimate: 10_000, // 2h 46m + totalTimeSpent: 20_000_000, // 231 days + }, }, }); @@ -122,8 +149,11 @@ describe('Issuable Time Tracker', () => { beforeEach(async () => { wrapper = mountComponent({ props: { - timeEstimate: 100_000, // 1d 3h limitToHours: true, + initialTimeTracking: { + ...defaultProps.initialTimeTracking, + timeEstimate: 100_000, // 1d 3h + }, }, }); }); @@ -140,10 +170,12 @@ describe('Issuable Time Tracker', () => { beforeEach(async () => { wrapper = mountComponent({ props: { - timeEstimate: 10_000, // 2h 46m - timeSpent: 0, - timeEstimateHumanReadable: '2h 46m', - timeSpentHumanReadable: '', + initialTimeTracking: { + timeEstimate: 10_000, // 2h 46m + totalTimeSpent: 0, + humanTimeEstimate: '2h 46m', + humanTotalTimeSpent: '', + }, }, }); await wrapper.vm.$nextTick(); @@ -159,10 +191,12 @@ describe('Issuable Time Tracker', () => { beforeEach(() => { wrapper = mountComponent({ props: { - timeEstimate: 0, - timeSpent: 5_000, // 1h 23m - timeEstimateHumanReadable: '2h 46m', - timeSpentHumanReadable: '1h 23m', + initialTimeTracking: { + timeEstimate: 0, + totalTimeSpent: 5_000, // 1h 23m + humanTimeEstimate: '2h 46m', + humanTotalTimeSpent: '1h 23m', + }, }, }); }); @@ -177,10 +211,12 @@ describe('Issuable Time Tracker', () => { beforeEach(() => { wrapper = mountComponent({ props: { - timeEstimate: 0, - timeSpent: 0, - timeEstimateHumanReadable: '', - timeSpentHumanReadable: '', + initialTimeTracking: { + timeEstimate: 0, + totalTimeSpent: 0, + humanTimeEstimate: '', + humanTotalTimeSpent: '', + }, }, }); }); @@ -198,8 +234,11 @@ describe('Issuable Time Tracker', () => { beforeEach(() => { wrapper = mountComponent({ props: { - timeSpent: 0, - timeSpentHumanReadable: '', + initialTimeTracking: { + ...defaultProps.initialTimeTracking, + totalTimeSpent: 0, + humanTotalTimeSpent: '', + }, }, }); }); @@ -210,13 +249,20 @@ describe('Issuable Time Tracker', () => { }); describe('When time spent', () => { - beforeEach(() => { + it('link should appear on issue', () => { wrapper = mountComponent(); + expect(findReportLink().exists()).toBe(true); }); - it('link should appear', () => { + it('link should appear on merge request', () => { + wrapper = mountComponent({ issuableType: 'merge_request' }); expect(findReportLink().exists()).toBe(true); }); + + it('link should not appear on milestone', () => { + wrapper = mountComponent({ issuableType: 'milestone' }); + expect(findReportLink().exists()).toBe(false); + }); }); }); @@ -225,7 +271,16 @@ describe('Issuable Time Tracker', () => { const findCloseHelpButton = () => findByTestId('closeHelpButton'); beforeEach(async () => { - wrapper = mountComponent({ props: { timeEstimate: 0, timeSpent: 0 } }); + wrapper = mountComponent({ + props: { + initialTimeTracking: { + timeEstimate: 0, + totalTimeSpent: 0, + humanTimeEstimate: '', + humanTotalTimeSpent: '', + }, + }, + }); await wrapper.vm.$nextTick(); }); @@ -254,4 +309,14 @@ describe('Issuable Time Tracker', () => { }); }); }); + + describe('Event listeners', () => { + it('refetches issuableTimeTracking query when eventHub emits `timeTracker:refresh` event', async () => { + SidebarEventHub.$emit('timeTracker:refresh'); + + await wrapper.vm.$nextTick(); + + expect(issuableTimeTrackingRefetchSpy).toHaveBeenCalled(); + }); + }); }); |