diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/frontend/cycle_analytics/utils_spec.js | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/frontend/cycle_analytics/utils_spec.js')
-rw-r--r-- | spec/frontend/cycle_analytics/utils_spec.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/frontend/cycle_analytics/utils_spec.js b/spec/frontend/cycle_analytics/utils_spec.js new file mode 100644 index 00000000000..73e26e1cdcc --- /dev/null +++ b/spec/frontend/cycle_analytics/utils_spec.js @@ -0,0 +1,77 @@ +import { decorateEvents, decorateData } from '~/cycle_analytics/utils'; +import { selectedStage, rawData, convertedData, rawEvents } from './mock_data'; + +describe('Value stream analytics utils', () => { + describe('decorateEvents', () => { + const [result] = decorateEvents(rawEvents, selectedStage); + const eventKeys = Object.keys(result); + const authorKeys = Object.keys(result.author); + it('will return the same number of events', () => { + expect(decorateEvents(rawEvents, selectedStage).length).toBe(rawEvents.length); + }); + + it('will set all the required event fields', () => { + ['totalTime', 'author', 'createdAt', 'shortSha', 'commitUrl'].forEach((key) => { + expect(eventKeys).toContain(key); + }); + ['webUrl', 'avatarUrl'].forEach((key) => { + expect(authorKeys).toContain(key); + }); + }); + + it('will remove unused fields', () => { + ['total_time', 'created_at', 'short_sha', 'commit_url'].forEach((key) => { + expect(eventKeys).not.toContain(key); + }); + + ['web_url', 'avatar_url'].forEach((key) => { + expect(authorKeys).not.toContain(key); + }); + }); + }); + + describe('decorateData', () => { + const result = decorateData(rawData); + it('returns the summary data', () => { + expect(result.summary).toEqual(convertedData.summary); + }); + + it('returns the stages data', () => { + expect(result.stages).toEqual(convertedData.stages); + }); + + it('returns each of the default value stream stages', () => { + const stages = result.stages.map(({ name }) => name); + ['issue', 'plan', 'code', 'test', 'review', 'staging'].forEach((stageName) => { + expect(stages).toContain(stageName); + }); + }); + + it('returns `-` for summary data that has no value', () => { + const singleSummaryResult = decorateData({ + stats: [], + permissions: { issue: true }, + summary: [{ value: null, title: 'Commits' }], + }); + expect(singleSummaryResult.summary).toEqual([{ value: '-', title: 'Commits' }]); + }); + + it('returns additional fields for each stage', () => { + const singleStageResult = decorateData({ + stats: [{ name: 'issue', value: null }], + permissions: { issue: false }, + }); + const stage = singleStageResult.stages[0]; + const txt = + 'The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage.'; + + expect(stage).toMatchObject({ + active: false, + isUserAllowed: false, + emptyStageText: txt, + slug: 'issue', + component: 'stage-issue-component', + }); + }); + }); +}); |