From 5dafdbf710cab6f5edb395bd88af9fed3d59a0e2 Mon Sep 17 00:00:00 2001 From: wenjing-qi Date: Tue, 30 Jan 2024 14:35:36 +0800 Subject: [PATCH] [ADM-792] add test for cycle time by status --- .../components/HomeGuide/HomeGuide.test.tsx | 2 +- .../Metrics/MetricsStep/CycleTime.test.tsx | 177 ++++++++++++++++-- .../Metrics/MetricsStep/MetricsStep.test.tsx | 73 ++++++-- .../Metrics/MetricsStep/RealDone.test.tsx | 30 +-- .../MetricsStepper/MetricsStepper.test.tsx | 1 + .../Metrics/ReportStep/ReportStep.test.tsx | 1 + .../src/context/metricsSlice.test.ts | 21 ++- frontend/__tests__/src/fixtures.ts | 38 ++-- frontend/__tests__/src/utils/Util.test.tsx | 92 ++++++--- 9 files changed, 321 insertions(+), 114 deletions(-) diff --git a/frontend/__tests__/src/components/HomeGuide/HomeGuide.test.tsx b/frontend/__tests__/src/components/HomeGuide/HomeGuide.test.tsx index 86ae3ead69..d10422060b 100644 --- a/frontend/__tests__/src/components/HomeGuide/HomeGuide.test.tsx +++ b/frontend/__tests__/src/components/HomeGuide/HomeGuide.test.tsx @@ -88,7 +88,7 @@ describe('HomeGuide', () => { fireEvent.change(input) await waitFor(() => { - expect(mockedUseAppDispatch).toHaveBeenCalledTimes(3) + expect(mockedUseAppDispatch).toHaveBeenCalledTimes(4) expect(navigateMock).toHaveBeenCalledWith(METRICS_PAGE_ROUTE) }) }) diff --git a/frontend/__tests__/src/components/Metrics/MetricsStep/CycleTime.test.tsx b/frontend/__tests__/src/components/Metrics/MetricsStep/CycleTime.test.tsx index d372b81751..3eb7ce441f 100644 --- a/frontend/__tests__/src/components/Metrics/MetricsStep/CycleTime.test.tsx +++ b/frontend/__tests__/src/components/Metrics/MetricsStep/CycleTime.test.tsx @@ -1,32 +1,57 @@ -import { act, render, waitFor, within } from '@testing-library/react' +import { act, render, waitFor, within, screen } from '@testing-library/react' import { CycleTime } from '@src/components/Metrics/MetricsStep/CycleTime' import userEvent from '@testing-library/user-event' import { Provider } from 'react-redux' import { setupStore } from '../../../utils/setupStoreUtil' import { CYCLE_TIME_SETTINGS, ERROR_MESSAGE_TIME_DURATION, LIST_OPEN, NO_RESULT_DASH } from '../../../fixtures' -import { saveDoneColumn, updateTreatFlagCardAsBlock } from '@src/context/Metrics/metricsSlice' +import { + saveCycleTimeSettings, + saveDoneColumn, + selectMetricsContent, + setCycleTimeSettingsType, + updateTreatFlagCardAsBlock, +} from '@src/context/Metrics/metricsSlice' +import { CYCLE_TIME_SETTINGS_TYPES, METRICS_CONSTANTS } from '@src/constants/resources' const FlagAsBlock = 'Consider the "Flag" as "Block"' +const cycleTimeSettings = [ + { + column: 'Doing', + status: 'Analysis', + value: 'Analysis', + }, + { + column: 'Doing', + status: 'In Dev', + value: 'Analysis', + }, + { + column: 'Doing', + status: 'doing', + value: 'Analysis', + }, + { + column: 'Testing', + status: 'Test', + value: 'Review', + }, + { + column: 'TODO', + status: 'To do', + value: '----', + }, + { + column: 'Done', + status: 'done', + value: 'Done', + }, +] +const cycleTimeTypeLabels = ['By Column', 'By Status'] let store = setupStore() jest.mock('@src/context/Metrics/metricsSlice', () => ({ ...jest.requireActual('@src/context/Metrics/metricsSlice'), - selectMetricsContent: jest.fn().mockReturnValue({ - cycleTimeSettings: [ - { - name: 'Doing', - value: 'Analysis', - }, - { - name: 'Testing', - value: 'Review', - }, - { - name: 'TODO', - value: '----', - }, - ], - }), + selectMetricsContent: jest.fn(), selectTreatFlagCardAsBlock: jest.fn().mockReturnValue(true), selectCycleTimeWarningMessage: jest.fn().mockReturnValue('Test warning Message'), })) @@ -54,10 +79,15 @@ const setup = () => describe('CycleTime', () => { beforeEach(() => { store = setupStore() + ;(selectMetricsContent as jest.Mock).mockReturnValue({ + cycleTimeSettingsType: 'byColumn', + cycleTimeSettings, + }) }) afterEach(() => { jest.clearAllMocks() + jest.useRealTimers() }) describe('CycleTime Title', () => { @@ -103,11 +133,29 @@ describe('CycleTime', () => { const inputElements = getAllByRole('combobox') const selectedInputValues = inputElements.map((input) => input.getAttribute('value')) - const expectedInputValues = ['Analysis', 'Review', NO_RESULT_DASH] + const expectedInputValues = ['Analysis', 'Review', NO_RESULT_DASH, 'Done'] expect(selectedInputValues).toEqual(expectedInputValues) }) + it('should use default value when state value is null', () => { + ;(selectMetricsContent as jest.Mock).mockReturnValue({ + cycleTimeSettingsType: 'byColumn', + cycleTimeSettings: [ + { + column: 'Doing', + status: 'Analysis', + value: null, + }, + ], + }) + setup() + + const inputElements = screen.getAllByRole('combobox') + const selectedInputValues = inputElements.map((input) => input.getAttribute('value')) + expect(selectedInputValues).toEqual([NO_RESULT_DASH]) + }) + it('should show detail options when click included button', async () => { const { getAllByRole, getByRole } = setup() const columnsArray = getAllByRole('button', { name: LIST_OPEN }) @@ -286,4 +334,95 @@ describe('CycleTime', () => { expect(queryByText('Test warning Message')).not.toBeInTheDocument() }) }) + + it('should update cycle time type and clear table value when select status type', async () => { + setup() + await userEvent.click(screen.getByRole('radio', { name: cycleTimeTypeLabels[1] })) + + expect(mockedUseAppDispatch).toHaveBeenCalledTimes(3) + expect(mockedUseAppDispatch).toHaveBeenCalledWith(setCycleTimeSettingsType(CYCLE_TIME_SETTINGS_TYPES.BY_STATUS)) + expect(mockedUseAppDispatch).toHaveBeenCalledWith( + saveCycleTimeSettings( + cycleTimeSettings.map((item) => ({ + ...item, + value: METRICS_CONSTANTS.cycleTimeEmptyStr, + })) + ) + ) + expect(mockedUseAppDispatch).toHaveBeenCalledWith(saveDoneColumn([])) + }) + + describe('cycle time by status', () => { + beforeEach(() => { + ;(selectMetricsContent as jest.Mock).mockReturnValue({ + cycleTimeSettingsType: 'byStatus', + cycleTimeSettings, + }) + }) + + it('should show status mapping table when cycle time settings type by status', async () => { + setup() + + expect(screen.getByText('Analysis (Doing)')).toBeInTheDocument() + expect(screen.getByText('In Dev (Doing)')).toBeInTheDocument() + expect(screen.getByText('doing (Doing)')).toBeInTheDocument() + expect(screen.getByText('Test (Testing)')).toBeInTheDocument() + expect(screen.getByText('To do (TODO)')).toBeInTheDocument() + }) + + it('should show selected option when click the dropDown button ', async () => { + setup() + const columnsArray = screen.getAllByRole('button', { name: LIST_OPEN }) + await userEvent.click(columnsArray[2]) + + const listBox = within(screen.getByRole('listbox')) + const options = listBox.getAllByRole('option') + const selectedOption = options.find((option) => option.getAttribute('aria-selected') === 'true') + const selectedOptionText = selectedOption?.textContent + expect(selectedOptionText).toBe('Analysis') + }) + + it('should show other selections when change option and will not affect Real done', async () => { + setup() + const columnsArray = screen.getAllByRole('button', { name: LIST_OPEN }) + await userEvent.click(columnsArray[2]) + const listBox = within(screen.getByRole('listbox')) + const mockOptions = listBox.getAllByRole('option') + await userEvent.click(mockOptions[1]) + + const inputElements = screen.getAllByRole('combobox') + const selectedInputValue = inputElements.map((option) => option.getAttribute('value'))[2] + expect(selectedInputValue).toBe('To do') + expect(mockedUseAppDispatch).not.toHaveBeenCalledWith(saveDoneColumn([])) + }) + + it('should not reset Real done when marked as done from other options', async () => { + setup() + const columnsArray = screen.getAllByRole('button', { name: LIST_OPEN }) + await userEvent.click(columnsArray[0]) + const listBox = within(screen.getByRole('listbox')) + await userEvent.click(listBox.getAllByRole('option')[8]) + + const inputElements = screen.getAllByRole('combobox') + const selectedInputValue = inputElements.map((option) => option.getAttribute('value'))[0] + expect(selectedInputValue).toBe('Done') + expect(mockedUseAppDispatch).not.toHaveBeenCalledWith(saveDoneColumn([])) + }) + + it('should show the correct selected value when cancel the done', async () => { + setup() + const columnsArray = screen.getAllByRole('button', { name: LIST_OPEN }) + await userEvent.click(columnsArray[0]) + const listBox = within(screen.getByRole('listbox')) + await userEvent.click(listBox.getAllByRole('option')[8]) + await userEvent.click(columnsArray[0]) + const newListBox = within(screen.getByRole('listbox')) + await userEvent.click(newListBox.getAllByRole('option')[7]) + + const inputElements = screen.getAllByRole('combobox') + const selectedInputValue = inputElements.map((option) => option.getAttribute('value'))[0] + expect(selectedInputValue).toBe('Review') + expect(mockedUseAppDispatch).not.toHaveBeenCalledWith(saveDoneColumn([])) + }) + }) }) diff --git a/frontend/__tests__/src/components/Metrics/MetricsStep/MetricsStep.test.tsx b/frontend/__tests__/src/components/Metrics/MetricsStep/MetricsStep.test.tsx index 6466071a2a..364c305f0c 100644 --- a/frontend/__tests__/src/components/Metrics/MetricsStep/MetricsStep.test.tsx +++ b/frontend/__tests__/src/components/Metrics/MetricsStep/MetricsStep.test.tsx @@ -39,17 +39,31 @@ describe('MetricsStep', () => { it('should render Crews when select velocity, and show Real done when have done column in Cycle time', async () => { store.dispatch(updateMetrics([REQUIRED_DATA_LIST[1]])) + store.dispatch( + saveCycleTimeSettings([ + { column: 'Testing', status: 'testing', value: 'Done' }, + { column: 'Testing', status: 'test', value: 'Done' }, + ]) + ) + const { getByText, queryByText } = setup() expect(getByText(CREWS_SETTING)).toBeInTheDocument() expect(queryByText(CYCLE_TIME_SETTINGS)).not.toBeInTheDocument() expect(queryByText(CLASSIFICATION_SETTING)).not.toBeInTheDocument() + expect(getByText(REAL_DONE)).toBeInTheDocument() + }) - act(() => { - store.dispatch(saveCycleTimeSettings([{ name: 'Testing', value: 'Done' }])) - }) + it('should not show Real done when only one value is done for cycle time', async () => { + store.dispatch(updateMetrics([REQUIRED_DATA_LIST[1]])) + store.dispatch(saveCycleTimeSettings([{ column: 'Testing', status: 'testing', value: 'Done' }])) - expect(getByText(REAL_DONE)).toBeInTheDocument() + const { getByText, queryByText } = setup() + + expect(getByText(CREWS_SETTING)).toBeInTheDocument() + expect(queryByText(CYCLE_TIME_SETTINGS)).not.toBeInTheDocument() + expect(queryByText(CLASSIFICATION_SETTING)).not.toBeInTheDocument() + expect(queryByText(REAL_DONE)).not.toBeInTheDocument() }) it('should show Cycle Time Settings when select cycle time in config page', async () => { @@ -60,7 +74,7 @@ describe('MetricsStep', () => { }) it('should hide Real Done when no done column in cycleTime settings', async () => { - await store.dispatch(saveCycleTimeSettings([{ name: 'Testing', value: 'Block' }])) + await store.dispatch(saveCycleTimeSettings([{ column: 'Testing', status: 'testing', value: 'Block' }])) const { queryByText } = setup() expect(queryByText(REAL_DONE)).not.toBeInTheDocument() @@ -100,33 +114,68 @@ describe('MetricsStep', () => { beforeEach(() => { const cycleTimeSettingsWithTwoDoneValue = [ { - name: 'To Do', + column: 'To Do', + status: 'BACKLOG', + value: 'To Do', + }, + { + column: 'To Do', + status: 'TO DO', + value: 'To Do', + }, + { + column: 'To Do', + status: 'GOING TO DO', value: 'To Do', }, { - name: 'In Progress', + column: 'In Progress', + status: 'IN PROGRESS', value: 'Done', }, { - name: 'Block', + column: 'In Progress', + status: 'IN DEV', + value: 'Done', + }, + { + column: 'Block', + status: 'BLOCK', value: 'Block', }, { - name: 'Test', + column: 'Test', + status: 'TESTING', + value: 'To do', + }, + { + column: 'Test', + status: 'TO BE TESTED', value: 'To do', }, { - name: 'Done', + column: 'Done', + status: 'PRE-DONE,', + value: 'Done', + }, + { + column: 'Done', + status: 'DONE', + value: 'Done', + }, + { + column: 'Done', + status: 'CANCEL', value: 'Done', }, ] - const doneColumn = ['IN PROGRESS', 'IN DEV', 'PRE-DONE', 'DONE', 'CANCLE'] + const doneColumn = ['IN PROGRESS', 'IN DEV', 'PRE-DONE', 'DONE', 'CANCEL'] const jiraColumns = [ { key: 'indeterminate', value: { name: 'To Do', statuses: ['BACKLOG', 'TO DO', 'GOING TO DO'] } }, { key: 'indeterminate', value: { name: 'In Progress', statuses: ['IN PROGRESS', 'IN DEV'] } }, { key: 'indeterminate', value: { name: 'Block', statuses: ['BLOCK'] } }, { key: 'indeterminate', value: { name: 'Test', statuses: ['TESTING', 'TO BE TESTED'] } }, - { key: 'done', value: { name: 'Done', statuses: ['PRE-DONE,', 'DONE', 'CANCLE'] } }, + { key: 'done', value: { name: 'Done', statuses: ['PRE-DONE,', 'DONE', 'CANCEL'] } }, ] store.dispatch(updateMetrics(REQUIRED_DATA_LIST)) diff --git a/frontend/__tests__/src/components/Metrics/MetricsStep/RealDone.test.tsx b/frontend/__tests__/src/components/Metrics/MetricsStep/RealDone.test.tsx index 71ebf0002f..2b26a241ca 100644 --- a/frontend/__tests__/src/components/Metrics/MetricsStep/RealDone.test.tsx +++ b/frontend/__tests__/src/components/Metrics/MetricsStep/RealDone.test.tsx @@ -109,7 +109,12 @@ describe('RealDone', () => { }) it('should show doing when choose Testing column is Done', async () => { - await store.dispatch(saveCycleTimeSettings([{ name: 'Done', value: 'Done' }])) + await store.dispatch( + saveCycleTimeSettings([ + { column: 'Done', status: 'DONE', value: 'Done' }, + { column: 'Done', status: 'CANCELLED', value: 'Done' }, + ]) + ) const { getByRole } = setup() await act(async () => { @@ -144,27 +149,4 @@ describe('RealDone', () => { }) }) }) - - describe('when done column with only one status', () => { - it('should not show read done box', async () => { - const mockColumnsList = [ - { - key: 'done', - value: { - name: 'Done', - statuses: ['DONE'], - }, - }, - ] - - const { queryByText } = render( - - - - ) - - expect(queryByText(mockTitle)).not.toBeInTheDocument() - expect(queryByText(mockLabel)).not.toBeInTheDocument() - }) - }) }) diff --git a/frontend/__tests__/src/components/Metrics/MetricsStepper/MetricsStepper.test.tsx b/frontend/__tests__/src/components/Metrics/MetricsStepper/MetricsStepper.test.tsx index 38c1662d23..b4f870a3c1 100644 --- a/frontend/__tests__/src/components/Metrics/MetricsStepper/MetricsStepper.test.tsx +++ b/frontend/__tests__/src/components/Metrics/MetricsStepper/MetricsStepper.test.tsx @@ -88,6 +88,7 @@ jest.mock('@src/utils/util', () => ({ transformToCleanedBuildKiteEmoji: jest.fn(), findCaseInsensitiveType: jest.fn(), filterAndMapCycleTimeSettings: jest.fn(), + getRealDoneStatus: jest.fn(), })) jest.mock('@src/hooks/useGenerateReportEffect', () => ({ diff --git a/frontend/__tests__/src/components/Metrics/ReportStep/ReportStep.test.tsx b/frontend/__tests__/src/components/Metrics/ReportStep/ReportStep.test.tsx index e6f6eb7ea7..40bd19d609 100644 --- a/frontend/__tests__/src/components/Metrics/ReportStep/ReportStep.test.tsx +++ b/frontend/__tests__/src/components/Metrics/ReportStep/ReportStep.test.tsx @@ -60,6 +60,7 @@ jest.mock('@src/utils/util', () => ({ transformToCleanedBuildKiteEmoji: jest.fn(), getJiraBoardToken: jest.fn(), filterAndMapCycleTimeSettings: jest.fn(), + getRealDoneStatus: jest.fn(), })) let store = null diff --git a/frontend/__tests__/src/context/metricsSlice.test.ts b/frontend/__tests__/src/context/metricsSlice.test.ts index 116ce03792..86067c3f23 100644 --- a/frontend/__tests__/src/context/metricsSlice.test.ts +++ b/frontend/__tests__/src/context/metricsSlice.test.ts @@ -19,7 +19,7 @@ import saveMetricsSettingReducer, { } from '@src/context/Metrics/metricsSlice' import { store } from '@src/store' import { CLASSIFICATION_WARNING_MESSAGE, NO_RESULT_DASH, PIPELINE_SETTING_TYPES } from '../fixtures' -import { ASSIGNEE_FILTER_TYPES, MESSAGE } from '@src/constants/resources' +import { ASSIGNEE_FILTER_TYPES, CYCLE_TIME_SETTINGS_TYPES, MESSAGE } from '@src/constants/resources' import { setupStore } from '../utils/setupStoreUtil' const initState = { @@ -29,6 +29,7 @@ const initState = { pipelineCrews: [], doneColumn: [], cycleTimeSettings: [], + cycleTimeSettingsType: CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN, deploymentFrequencySettings: [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }], leadTimeForChanges: [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }], classification: [], @@ -255,9 +256,10 @@ describe('saveMetricsSetting reducer', () => { expect(savedMetricsSetting.targetFields).toEqual([{ key: 'issuetype', name: 'Issue Type', flag: true }]) expect(savedMetricsSetting.users).toEqual(['User B']) expect(savedMetricsSetting.cycleTimeSettings).toEqual([ - { name: 'Done', value: 'Done' }, - { name: 'Doing', value: NO_RESULT_DASH }, - { name: 'Testing', value: NO_RESULT_DASH }, + { column: 'Done', status: 'DONE', value: 'Done' }, + { column: 'Done', status: 'CLOSED', value: 'Done' }, + { column: 'Doing', status: 'ANALYSIS', value: NO_RESULT_DASH }, + { column: 'Testing', status: 'TESTING', value: NO_RESULT_DASH }, ]) expect(savedMetricsSetting.doneColumn).toEqual(['DONE']) }) @@ -299,9 +301,10 @@ describe('saveMetricsSetting reducer', () => { expect(savedMetricsSetting.targetFields).toEqual([{ key: 'issuetype', name: 'Issue Type', flag: false }]) expect(savedMetricsSetting.users).toEqual(['User A', 'User B']) expect(savedMetricsSetting.cycleTimeSettings).toEqual([ - { name: 'Done', value: NO_RESULT_DASH }, - { name: 'Doing', value: NO_RESULT_DASH }, - { name: 'Testing', value: NO_RESULT_DASH }, + { column: 'Done', status: 'DONE', value: NO_RESULT_DASH }, + { column: 'Done', status: 'CLOSED', value: NO_RESULT_DASH }, + { column: 'Doing', status: 'ANALYSIS', value: NO_RESULT_DASH }, + { column: 'Testing', status: 'TESTING', value: NO_RESULT_DASH }, ]) expect(savedMetricsSetting.doneColumn).toEqual([]) }) @@ -797,7 +800,7 @@ describe('saveMetricsSetting reducer', () => { const savedMetricsSetting = saveMetricsSettingReducer( { ...initState, - cycleTimeSettings: [{ name: 'Done', value: 'Done' }], + cycleTimeSettings: [{ column: 'Done', status: 'DONE', value: 'Done' }], importedData: { ...initState.importedData, importedDoneStatus: ['DONE', 'CLOSED'], @@ -826,7 +829,7 @@ describe('saveMetricsSetting reducer', () => { const savedMetricsSetting = saveMetricsSettingReducer( { ...initState, - cycleTimeSettings: [{ name: 'Done', value: 'Done' }], + cycleTimeSettings: [{ column: 'Done', status: 'DONE', value: 'Done' }], importedData: { ...initState.importedData, importedDoneStatus: ['DONE', 'CLOSED', 'CANCELED'], diff --git a/frontend/__tests__/src/fixtures.ts b/frontend/__tests__/src/fixtures.ts index 3a7a7e80b2..475af591ff 100644 --- a/frontend/__tests__/src/fixtures.ts +++ b/frontend/__tests__/src/fixtures.ts @@ -222,14 +222,17 @@ export const IMPORTED_NEW_CONFIG_FIXTURE = { }, crews: ['lucy', 'hi hi', 'Yu Zhang'], classification: ['type', 'Parent'], - cycleTime: [ - { - 'In Analysis': 'To do', - }, - { - 'Ready For Dev': 'Analysis', - }, - ], + cycleTime: { + type: 'byColumn', + jiraColumns: [ + { + 'In Analysis': 'To do', + }, + { + 'Ready For Dev': 'Analysis', + }, + ], + }, } export const MOCK_EXPORT_CSV_REQUEST_PARAMS: CSVReportRequestDTO = { @@ -293,25 +296,6 @@ export const MOCK_BUILD_KITE_VERIFY_RESPONSE = { ], } -export const FILTER_CYCLE_TIME_SETTINGS = [ - { name: 'TODO', value: 'TODO' }, - { name: 'BACKLOG', value: 'TODO' }, - { name: 'IN DEV', value: 'IN DEV' }, - { name: 'DOING', value: 'IN DEV' }, - { name: 'DONE', value: 'DONE' }, -] - -export const MOCK_CYCLE_TIME_SETTING = [ - { name: 'TODO', value: 'TODO' }, - { name: 'IN DEV', value: 'IN DEV' }, - { name: 'DONE', value: 'DONE' }, -] -export const MOCK_JIRA_WITH_STATUES_SETTING = [ - { name: 'TODO', statuses: ['TODO', 'BACKLOG'] }, - { name: 'IN DEV', statuses: ['IN DEV', 'DOING'] }, - { name: 'DONE', statuses: ['DONE'] }, -] - export const MOCK_GITHUB_VERIFY_RESPONSE = { githubRepos: ['https://github.com/xxxx1/repo1', 'https://github.com/xxxx1/repo2'], } diff --git a/frontend/__tests__/src/utils/Util.test.tsx b/frontend/__tests__/src/utils/Util.test.tsx index 78319436e3..fd511a1900 100644 --- a/frontend/__tests__/src/utils/Util.test.tsx +++ b/frontend/__tests__/src/utils/Util.test.tsx @@ -3,16 +3,13 @@ import { filterAndMapCycleTimeSettings, findCaseInsensitiveType, getJiraBoardToken, + getRealDoneStatus, transformToCleanedBuildKiteEmoji, } from '@src/utils/util' import { CleanedBuildKiteEmoji, OriginBuildKiteEmoji } from '@src/emojis/emoji' import { EMPTY_STRING } from '@src/constants/commons' -import { - FILTER_CYCLE_TIME_SETTINGS, - MOCK_CYCLE_TIME_SETTING, - MOCK_JIRA_WITH_STATUES_SETTING, - PIPELINE_TOOL_TYPES, -} from '../fixtures' +import { PIPELINE_TOOL_TYPES } from '../fixtures' +import { CYCLE_TIME_SETTINGS_TYPES } from '@src/constants/resources' describe('exportToJsonFile function', () => { it('should create a link element with the correct attributes and click it', () => { @@ -102,29 +99,80 @@ describe('findCaseInsensitiveType function', () => { describe('filterAndMapCycleTimeSettings function', () => { it('should filter and map CycleTimeSettings when generate report', () => { - const value = filterAndMapCycleTimeSettings(MOCK_CYCLE_TIME_SETTING, MOCK_JIRA_WITH_STATUES_SETTING) - expect(value).toStrictEqual(FILTER_CYCLE_TIME_SETTINGS) + const MOCK_CYCLE_TIME_SETTING = [ + { column: 'TODO', status: 'ToDo', value: 'TODO' }, + { column: 'TODO', status: 'Backlog', value: 'TODO' }, + { column: 'IN DEV', status: 'InDev', value: 'IN DEV' }, + { column: 'IN DEV', status: 'Doing', value: 'IN DEV' }, + { column: 'DONE', status: 'Done', value: 'DONE' }, + ] + + const value = filterAndMapCycleTimeSettings(MOCK_CYCLE_TIME_SETTING) + + expect(value).toStrictEqual([ + { name: 'ToDo', value: 'TODO' }, + { name: 'Backlog', value: 'TODO' }, + { name: 'InDev', value: 'IN DEV' }, + { name: 'Doing', value: 'IN DEV' }, + { name: 'Done', value: 'DONE' }, + ]) }) +}) - it('should filter and map CycleTimeSettings when generate report', () => { - const filterCycleTimeSettings = [ - { name: 'IN DEV', value: 'IN DEV' }, - { name: 'DOING', value: 'IN DEV' }, - { name: 'DONE', value: 'DONE' }, +describe('getRealDoneStatus', () => { + it('should return selected done status when cycle time settings only have one done value and type is by column', () => { + const MOCK_CYCLE_TIME_SETTING = [ + { column: 'TODO', status: 'ToDo', value: 'TODO' }, + { column: 'TODO', status: 'Backlog', value: 'TODO' }, + { column: 'IN DEV', status: 'InDev', value: 'IN DEV' }, + { column: 'IN DEV', status: 'Doing', value: 'IN DEV' }, + { column: 'DONE', status: 'DONE', value: 'Done' }, ] + const result = getRealDoneStatus(MOCK_CYCLE_TIME_SETTING, CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN, []) + + expect(result).toEqual(['DONE']) + }) + + it('should return selected done status when cycle time settings only have one done value and type is by status', () => { const MOCK_CYCLE_TIME_SETTING = [ - { name: 'TODO', value: 'TODO' }, - { name: 'IN DEV', value: 'IN DEV' }, - { name: 'DONE', value: 'DONE' }, + { column: 'TODO', status: 'ToDo', value: 'TODO' }, + { column: 'TODO', status: 'Backlog', value: 'TODO' }, + { column: 'IN DEV', status: 'InDev', value: 'IN DEV' }, + { column: 'IN DEV', status: 'Doing', value: 'IN DEV' }, + { column: 'DONE', status: 'DONE', value: 'Done' }, ] - const MOCK_JIRA_WITH_STATUES_SETTING = [ - { name: 'todo', statuses: ['TODO', 'BACKLOG'] }, - { name: 'IN DEV', statuses: ['IN DEV', 'DOING'] }, - { name: 'DONE', statuses: ['DONE'] }, + const result = getRealDoneStatus(MOCK_CYCLE_TIME_SETTING, CYCLE_TIME_SETTINGS_TYPES.BY_STATUS, []) + + expect(result).toEqual(['DONE']) + }) + + it('should return real done status when cycle time settings type is by column', () => { + const MOCK_CYCLE_TIME_SETTING = [ + { column: 'TODO', status: 'ToDo', value: 'TODO' }, + { column: 'TODO', status: 'Backlog', value: 'TODO' }, + { column: 'IN DEV', status: 'InDev', value: 'IN DEV' }, + { column: 'IN DEV', status: 'Doing', value: 'Done' }, + { column: 'DONE', status: 'DONE', value: 'Done' }, ] - const value = filterAndMapCycleTimeSettings(MOCK_CYCLE_TIME_SETTING, MOCK_JIRA_WITH_STATUES_SETTING) - expect(value).toStrictEqual(filterCycleTimeSettings) + + const result = getRealDoneStatus(MOCK_CYCLE_TIME_SETTING, CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN, ['Doing']) + + expect(result).toEqual(['Doing']) + }) + + it('should return selected done status when cycle time settings type is by column', () => { + const MOCK_CYCLE_TIME_SETTING = [ + { column: 'TODO', status: 'ToDo', value: 'TODO' }, + { column: 'TODO', status: 'Backlog', value: 'TODO' }, + { column: 'IN DEV', status: 'InDev', value: 'IN DEV' }, + { column: 'IN DEV', status: 'Doing', value: 'Done' }, + { column: 'DONE', status: 'DONE', value: 'Done' }, + ] + + const result = getRealDoneStatus(MOCK_CYCLE_TIME_SETTING, CYCLE_TIME_SETTINGS_TYPES.BY_STATUS, ['something']) + + expect(result).toEqual(['Doing', 'DONE']) }) })