/spec/javascripts/vue_mr_widget/components/mr_widget_pipeline_spec.js

https://gitlab.com/Stretch96/gitlab-ce · JavaScript · 274 lines · 226 code · 48 blank · 0 comment · 3 complexity · 46992b598913ae62663dfb2a04004891 MD5 · raw file

  1. import Vue from 'vue';
  2. import pipelineComponent from '~/vue_merge_request_widget/components/mr_widget_pipeline.vue';
  3. import mountComponent from 'spec/helpers/vue_mount_component_helper';
  4. import { trimText } from 'spec/helpers/vue_component_helper';
  5. import mockData from '../mock_data';
  6. describe('MRWidgetPipeline', () => {
  7. let vm;
  8. let Component;
  9. beforeEach(() => {
  10. Component = Vue.extend(pipelineComponent);
  11. });
  12. afterEach(() => {
  13. vm.$destroy();
  14. });
  15. describe('computed', () => {
  16. describe('hasPipeline', () => {
  17. it('should return true when there is a pipeline', () => {
  18. vm = mountComponent(Component, {
  19. pipeline: mockData.pipeline,
  20. ciStatus: 'success',
  21. hasCi: true,
  22. troubleshootingDocsPath: 'help',
  23. });
  24. expect(vm.hasPipeline).toEqual(true);
  25. });
  26. it('should return false when there is no pipeline', () => {
  27. vm = mountComponent(Component, {
  28. pipeline: {},
  29. troubleshootingDocsPath: 'help',
  30. });
  31. expect(vm.hasPipeline).toEqual(false);
  32. });
  33. });
  34. describe('hasCIError', () => {
  35. it('should return false when there is no CI error', () => {
  36. vm = mountComponent(Component, {
  37. pipeline: mockData.pipeline,
  38. hasCi: true,
  39. ciStatus: 'success',
  40. troubleshootingDocsPath: 'help',
  41. });
  42. expect(vm.hasCIError).toEqual(false);
  43. });
  44. it('should return true when there is a CI error', () => {
  45. vm = mountComponent(Component, {
  46. pipeline: mockData.pipeline,
  47. hasCi: true,
  48. ciStatus: null,
  49. troubleshootingDocsPath: 'help',
  50. });
  51. expect(vm.hasCIError).toEqual(true);
  52. });
  53. });
  54. });
  55. describe('rendered output', () => {
  56. it('should render CI error', () => {
  57. vm = mountComponent(Component, {
  58. pipeline: mockData.pipeline,
  59. hasCi: true,
  60. ciStatus: null,
  61. troubleshootingDocsPath: 'help',
  62. });
  63. expect(vm.$el.querySelector('.media-body').textContent.trim()).toContain(
  64. 'Could not retrieve the pipeline status. For troubleshooting steps, read the documentation.',
  65. );
  66. });
  67. describe('with a pipeline', () => {
  68. beforeEach(() => {
  69. vm = mountComponent(Component, {
  70. pipeline: mockData.pipeline,
  71. hasCi: true,
  72. ciStatus: 'success',
  73. troubleshootingDocsPath: 'help',
  74. });
  75. });
  76. it('should render pipeline ID', () => {
  77. expect(vm.$el.querySelector('.pipeline-id').textContent.trim()).toEqual(
  78. `#${mockData.pipeline.id}`,
  79. );
  80. });
  81. it('should render pipeline status and commit id', () => {
  82. expect(vm.$el.querySelector('.media-body').textContent.trim()).toContain(
  83. mockData.pipeline.details.status.label,
  84. );
  85. expect(vm.$el.querySelector('.js-commit-link').textContent.trim()).toEqual(
  86. mockData.pipeline.commit.short_id,
  87. );
  88. expect(vm.$el.querySelector('.js-commit-link').getAttribute('href')).toEqual(
  89. mockData.pipeline.commit.commit_path,
  90. );
  91. });
  92. it('should render pipeline graph', () => {
  93. expect(vm.$el.querySelector('.mr-widget-pipeline-graph')).toBeDefined();
  94. expect(vm.$el.querySelectorAll('.stage-container').length).toEqual(
  95. mockData.pipeline.details.stages.length,
  96. );
  97. });
  98. it('should render coverage information', () => {
  99. expect(vm.$el.querySelector('.media-body').textContent).toContain(
  100. `Coverage ${mockData.pipeline.coverage}`,
  101. );
  102. });
  103. });
  104. describe('without commit path', () => {
  105. beforeEach(() => {
  106. const mockCopy = JSON.parse(JSON.stringify(mockData));
  107. delete mockCopy.pipeline.commit;
  108. vm = mountComponent(Component, {
  109. pipeline: mockCopy.pipeline,
  110. hasCi: true,
  111. ciStatus: 'success',
  112. troubleshootingDocsPath: 'help',
  113. });
  114. });
  115. it('should render pipeline ID', () => {
  116. expect(vm.$el.querySelector('.pipeline-id').textContent.trim()).toEqual(
  117. `#${mockData.pipeline.id}`,
  118. );
  119. });
  120. it('should render pipeline status', () => {
  121. expect(vm.$el.querySelector('.media-body').textContent.trim()).toContain(
  122. mockData.pipeline.details.status.label,
  123. );
  124. expect(vm.$el.querySelector('.js-commit-link')).toBeNull();
  125. });
  126. it('should render pipeline graph', () => {
  127. expect(vm.$el.querySelector('.mr-widget-pipeline-graph')).toBeDefined();
  128. expect(vm.$el.querySelectorAll('.stage-container').length).toEqual(
  129. mockData.pipeline.details.stages.length,
  130. );
  131. });
  132. it('should render coverage information', () => {
  133. expect(vm.$el.querySelector('.media-body').textContent).toContain(
  134. `Coverage ${mockData.pipeline.coverage}`,
  135. );
  136. });
  137. });
  138. describe('without coverage', () => {
  139. it('should not render a coverage', () => {
  140. const mockCopy = JSON.parse(JSON.stringify(mockData));
  141. delete mockCopy.pipeline.coverage;
  142. vm = mountComponent(Component, {
  143. pipeline: mockCopy.pipeline,
  144. hasCi: true,
  145. ciStatus: 'success',
  146. troubleshootingDocsPath: 'help',
  147. });
  148. expect(vm.$el.querySelector('.media-body').textContent).not.toContain('Coverage');
  149. });
  150. });
  151. describe('without a pipeline graph', () => {
  152. it('should not render a pipeline graph', () => {
  153. const mockCopy = JSON.parse(JSON.stringify(mockData));
  154. delete mockCopy.pipeline.details.stages;
  155. vm = mountComponent(Component, {
  156. pipeline: mockCopy.pipeline,
  157. hasCi: true,
  158. ciStatus: 'success',
  159. troubleshootingDocsPath: 'help',
  160. });
  161. expect(vm.$el.querySelector('.js-mini-pipeline-graph')).toEqual(null);
  162. });
  163. });
  164. describe('without pipeline.merge_request', () => {
  165. it('should render info that includes the commit and branch details', () => {
  166. const mockCopy = JSON.parse(JSON.stringify(mockData));
  167. delete mockCopy.pipeline.merge_request;
  168. const { pipeline } = mockCopy;
  169. vm = mountComponent(Component, {
  170. pipeline,
  171. hasCi: true,
  172. ciStatus: 'success',
  173. troubleshootingDocsPath: 'help',
  174. sourceBranchLink: mockCopy.source_branch_link,
  175. });
  176. const expected = `Pipeline #${pipeline.id} ${pipeline.details.status.label} for ${
  177. pipeline.commit.short_id
  178. } on ${mockCopy.source_branch_link}`;
  179. const actual = trimText(vm.$el.querySelector('.js-pipeline-info-container').innerText);
  180. expect(actual).toBe(expected);
  181. });
  182. });
  183. describe('with pipeline.merge_request and flags.merge_request_pipeline', () => {
  184. it('should render info that includes the commit, MR, source branch, and target branch details', () => {
  185. const mockCopy = JSON.parse(JSON.stringify(mockData));
  186. const { pipeline } = mockCopy;
  187. pipeline.flags.merge_request_pipeline = true;
  188. pipeline.flags.detached_merge_request_pipeline = false;
  189. vm = mountComponent(Component, {
  190. pipeline,
  191. hasCi: true,
  192. ciStatus: 'success',
  193. troubleshootingDocsPath: 'help',
  194. sourceBranchLink: mockCopy.source_branch_link,
  195. });
  196. const expected = `Pipeline #${pipeline.id} ${pipeline.details.status.label} for ${
  197. pipeline.commit.short_id
  198. } on !${pipeline.merge_request.iid} with ${pipeline.merge_request.source_branch} into ${
  199. pipeline.merge_request.target_branch
  200. }`;
  201. const actual = trimText(vm.$el.querySelector('.js-pipeline-info-container').innerText);
  202. expect(actual).toBe(expected);
  203. });
  204. });
  205. describe('with pipeline.merge_request and flags.detached_merge_request_pipeline', () => {
  206. it('should render info that includes the commit, MR, and source branch details', () => {
  207. const mockCopy = JSON.parse(JSON.stringify(mockData));
  208. const { pipeline } = mockCopy;
  209. pipeline.flags.merge_request_pipeline = false;
  210. pipeline.flags.detached_merge_request_pipeline = true;
  211. vm = mountComponent(Component, {
  212. pipeline,
  213. hasCi: true,
  214. ciStatus: 'success',
  215. troubleshootingDocsPath: 'help',
  216. sourceBranchLink: mockCopy.source_branch_link,
  217. });
  218. const expected = `Pipeline #${pipeline.id} ${pipeline.details.status.label} for ${
  219. pipeline.commit.short_id
  220. } on !${pipeline.merge_request.iid} with ${pipeline.merge_request.source_branch}`;
  221. const actual = trimText(vm.$el.querySelector('.js-pipeline-info-container').innerText);
  222. expect(actual).toBe(expected);
  223. });
  224. });
  225. });
  226. });