You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testMocks.ts 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { Location } from 'history';
  21. import { InjectedRouter } from 'react-router';
  22. import { createStore, Store } from 'redux';
  23. import { DocumentationEntry } from '../apps/documentation/utils';
  24. import { Exporter, Profile } from '../apps/quality-profiles/types';
  25. import { Language } from '../types/languages';
  26. import { DumpStatus, DumpTask } from '../types/project-dump';
  27. import { TaskStatuses } from '../types/tasks';
  28. import {
  29. AlmApplication,
  30. Analysis,
  31. AnalysisEvent,
  32. AppState,
  33. Condition,
  34. CurrentUser,
  35. FlowLocation,
  36. Group,
  37. HealthType,
  38. IdentityProvider,
  39. Issue,
  40. LoggedInUser,
  41. Measure,
  42. MeasureEnhanced,
  43. Metric,
  44. Paging,
  45. ParsedAnalysis,
  46. Period,
  47. ProfileInheritanceDetails,
  48. Rule,
  49. RuleActivation,
  50. RuleDetails,
  51. RuleParameter,
  52. SnippetsByComponent,
  53. SourceLine,
  54. SourceViewerFile,
  55. SysInfoBase,
  56. SysInfoCluster,
  57. SysInfoStandalone,
  58. User
  59. } from '../types/types';
  60. export function mockAlmApplication(overrides: Partial<AlmApplication> = {}): AlmApplication {
  61. return {
  62. backgroundColor: '#444444',
  63. iconPath: '/images/sonarcloud/github-white.svg',
  64. installationUrl: 'https://github.com/apps/greg-sonarcloud/installations/new',
  65. key: 'github',
  66. name: 'GitHub',
  67. ...overrides
  68. };
  69. }
  70. export function mockAnalysis(overrides: Partial<Analysis> = {}): Analysis {
  71. return {
  72. date: '2017-03-01T09:36:01+0100',
  73. events: [],
  74. key: 'foo',
  75. projectVersion: '1.0',
  76. ...overrides
  77. };
  78. }
  79. export function mockParsedAnalysis(overrides: Partial<ParsedAnalysis> = {}): ParsedAnalysis {
  80. return {
  81. date: new Date('2017-03-01T09:37:01+0100'),
  82. events: [],
  83. key: 'foo',
  84. projectVersion: '1.0',
  85. ...overrides
  86. };
  87. }
  88. export function mockAnalysisEvent(overrides: Partial<AnalysisEvent> = {}): AnalysisEvent {
  89. return {
  90. category: 'QUALITY_GATE',
  91. key: 'E11',
  92. description: 'Lorem ipsum dolor sit amet',
  93. name: 'Lorem ipsum',
  94. qualityGate: {
  95. status: 'ERROR',
  96. stillFailing: true,
  97. failing: [
  98. {
  99. key: 'foo',
  100. name: 'Foo',
  101. branch: 'master'
  102. },
  103. {
  104. key: 'bar',
  105. name: 'Bar',
  106. branch: 'feature/bar'
  107. }
  108. ]
  109. },
  110. ...overrides
  111. };
  112. }
  113. export function mockAppState(overrides: Partial<AppState> = {}): AppState {
  114. return {
  115. edition: 'community',
  116. productionDatabase: true,
  117. qualifiers: ['TRK'],
  118. settings: {},
  119. version: '1.0',
  120. ...overrides
  121. };
  122. }
  123. export function mockBaseSysInfo(overrides: Partial<any> = {}): SysInfoBase {
  124. return {
  125. Health: 'GREEN' as HealthType,
  126. 'Health Causes': [],
  127. System: {
  128. Version: '7.8'
  129. },
  130. Database: {
  131. Database: 'PostgreSQL',
  132. 'Database Version': '10.3',
  133. Username: 'sonar',
  134. URL: 'jdbc:postgresql://localhost/sonar',
  135. Driver: 'PostgreSQL JDBC Driver',
  136. 'Driver Version': '42.2.5'
  137. },
  138. 'Compute Engine Tasks': {
  139. 'Total Pending': 0,
  140. 'Total In Progress': 0
  141. },
  142. 'Search State': { State: 'GREEN', Nodes: 3 },
  143. 'Search Indexes': {
  144. 'Index components - Docs': 30445,
  145. 'Index components - Shards': 10
  146. },
  147. ...overrides
  148. };
  149. }
  150. export function mockClusterSysInfo(overrides: Partial<any> = {}): SysInfoCluster {
  151. const baseInfo = mockBaseSysInfo(overrides);
  152. return {
  153. ...baseInfo,
  154. System: {
  155. ...baseInfo.System,
  156. 'High Availability': true,
  157. 'Server ID': 'asd564-asd54a-5dsfg45'
  158. },
  159. Settings: {
  160. 'sonar.cluster.enabled': 'true',
  161. 'sonar.cluster.node.name': 'server9.example.com'
  162. },
  163. 'Application Nodes': [
  164. {
  165. Name: 'server9.example.com',
  166. Host: '10.0.0.0',
  167. Health: 'GREEN' as HealthType,
  168. 'Health Causes': [],
  169. System: {
  170. Version: '7.8'
  171. },
  172. Plugins: {
  173. java: '5.13.0.17924 [SonarJava]'
  174. },
  175. 'Web JVM State': {
  176. 'Max Memory (MB)': 1024,
  177. 'Free Memory (MB)': 122
  178. },
  179. 'Web Database Connection': {
  180. 'Pool Active Connections': 1
  181. },
  182. 'Web Logging': { 'Logs Level': 'DEBUG' },
  183. 'Web JVM Properties': {
  184. 'file.encoding': 'UTF-8',
  185. 'file.separator': '/'
  186. },
  187. 'Compute Engine Tasks': {
  188. Pending: 0,
  189. 'In Progress': 0
  190. },
  191. 'Compute Engine JVM State': {
  192. 'Max Memory (MB)': 1024,
  193. 'Free Memory (MB)': 78
  194. },
  195. 'Compute Engine Database Connection': {
  196. 'Pool Initial Size': 0,
  197. 'Pool Active Connections': 0
  198. },
  199. 'Compute Engine Logging': {
  200. 'Logs Level': 'INFO'
  201. },
  202. 'Compute Engine JVM Properties': {
  203. 'file.encoding': 'UTF-8',
  204. 'file.separator': '/'
  205. }
  206. },
  207. {
  208. Name: 'server9.example.com',
  209. Host: '10.0.0.0',
  210. Health: 'GREEN' as HealthType,
  211. 'Health Causes': [],
  212. System: {
  213. Version: '7.8'
  214. },
  215. Plugins: {
  216. java: '5.13.0.17924 [SonarJava]'
  217. },
  218. 'Web JVM State': {
  219. 'Max Memory (MB)': 1024,
  220. 'Free Memory (MB)': 111
  221. },
  222. 'Web Database Connection': {
  223. 'Pool Active Connections': 0,
  224. 'Pool Max Connections': 60
  225. },
  226. 'Web Logging': { 'Logs Level': 'INFO' },
  227. 'Web JVM Properties': {
  228. 'file.encoding': 'UTF-8',
  229. 'file.separator': '/'
  230. },
  231. 'Compute Engine Tasks': {
  232. Pending: 0,
  233. 'In Progress': 0
  234. },
  235. 'Compute Engine JVM State': {
  236. 'Max Memory (MB)': 1024,
  237. 'Free Memory (MB)': 89
  238. },
  239. 'Compute Engine Database Connection': {
  240. 'Pool Initial Size': 0,
  241. 'Pool Active Connections': 0
  242. },
  243. 'Compute Engine Logging': {
  244. 'Logs Level': 'INFO'
  245. },
  246. 'Compute Engine JVM Properties': {
  247. 'file.encoding': 'UTF-8',
  248. 'file.separator': '/'
  249. }
  250. }
  251. ],
  252. 'Search Nodes': [
  253. {
  254. Name: 'server.example.com',
  255. Host: '10.0.0.0',
  256. 'Search State': {
  257. 'CPU Usage (%)': 0,
  258. 'Disk Available': '93 GB'
  259. }
  260. },
  261. {
  262. Name: 'server.example.com',
  263. Host: '10.0.0.0',
  264. 'Search State': {
  265. 'CPU Usage (%)': 0,
  266. 'Disk Available': '93 GB'
  267. }
  268. },
  269. {
  270. Name: 'server.example.com',
  271. Host: '10.0.0.0',
  272. 'Search State': {
  273. 'CPU Usage (%)': 0,
  274. 'Disk Available': '93 GB'
  275. }
  276. }
  277. ],
  278. Statistics: {
  279. ncloc: 989880
  280. },
  281. ...overrides
  282. };
  283. }
  284. export function mockCondition(overrides: Partial<Condition> = {}): Condition {
  285. return {
  286. error: '10',
  287. id: 1,
  288. metric: 'coverage',
  289. op: 'LT',
  290. ...overrides
  291. };
  292. }
  293. export function mockSnippetsByComponent(
  294. component = 'main.js',
  295. lines: number[] = [16]
  296. ): SnippetsByComponent {
  297. const sources = lines.reduce((lines: { [key: number]: SourceLine }, line) => {
  298. lines[line] = mockSourceLine({ line });
  299. return lines;
  300. }, {});
  301. return {
  302. component: mockSourceViewerFile({
  303. key: component,
  304. path: component
  305. }),
  306. sources
  307. };
  308. }
  309. export function mockSourceLine(overrides: Partial<SourceLine> = {}): SourceLine {
  310. return {
  311. line: 16,
  312. code: '<span class="k">import</span> java.util.<span class="sym-9 sym">ArrayList</span>;',
  313. coverageStatus: 'covered',
  314. coveredConditions: 2,
  315. scmRevision: '80f564becc0c0a1c9abaa006eca83a4fd278c3f0',
  316. scmAuthor: 'simon.brandhof@sonarsource.com',
  317. scmDate: '2018-12-11T10:48:39+0100',
  318. duplicated: false,
  319. isNew: true,
  320. ...overrides
  321. };
  322. }
  323. export function mockCurrentUser(overrides: Partial<CurrentUser> = {}): CurrentUser {
  324. return {
  325. isLoggedIn: false,
  326. ...overrides
  327. };
  328. }
  329. export function mockLoggedInUser(overrides: Partial<LoggedInUser> = {}): LoggedInUser {
  330. return {
  331. groups: [],
  332. isLoggedIn: true,
  333. login: 'luke',
  334. name: 'Skywalker',
  335. scmAccounts: [],
  336. ...overrides
  337. };
  338. }
  339. export function mockGroup(overrides: Partial<Group> = {}): Group {
  340. return {
  341. id: 1,
  342. membersCount: 1,
  343. name: 'Foo',
  344. ...overrides
  345. };
  346. }
  347. export function mockEvent(overrides = {}) {
  348. return {
  349. target: { blur() {} },
  350. currentTarget: { blur() {} },
  351. preventDefault() {},
  352. stopPropagation() {},
  353. ...overrides
  354. } as any;
  355. }
  356. export function mockIssue(withLocations = false, overrides: Partial<Issue> = {}) {
  357. const issue: Issue = {
  358. actions: [],
  359. component: 'main.js',
  360. componentLongName: 'main.js',
  361. componentQualifier: 'FIL',
  362. componentUuid: 'foo1234',
  363. creationDate: '2017-03-01T09:36:01+0100',
  364. flows: [],
  365. fromHotspot: false,
  366. key: 'AVsae-CQS-9G3txfbFN2',
  367. line: 25,
  368. message: 'Reduce the number of conditional operators (4) used in the expression',
  369. project: 'myproject',
  370. projectKey: 'foo',
  371. projectName: 'Foo',
  372. rule: 'javascript:S1067',
  373. ruleName: 'foo',
  374. secondaryLocations: [],
  375. severity: 'MAJOR',
  376. status: 'OPEN',
  377. textRange: { startLine: 25, endLine: 26, startOffset: 0, endOffset: 15 },
  378. transitions: [],
  379. type: 'BUG'
  380. };
  381. const loc = mockFlowLocation;
  382. if (withLocations) {
  383. issue.flows = [
  384. [loc(), loc(), loc()],
  385. [loc(), loc()]
  386. ];
  387. issue.secondaryLocations = [loc(), loc()];
  388. }
  389. return {
  390. ...issue,
  391. ...overrides
  392. };
  393. }
  394. export function mockLocation(overrides: Partial<Location> = {}): Location {
  395. return {
  396. action: 'PUSH',
  397. hash: '',
  398. key: 'key',
  399. pathname: '/path',
  400. query: {},
  401. search: '',
  402. state: {},
  403. ...overrides
  404. };
  405. }
  406. export function mockMetric(overrides: Partial<Pick<Metric, 'key' | 'name' | 'type'>> = {}): Metric {
  407. const key = overrides.key || 'coverage';
  408. const name = overrides.name || key[0].toUpperCase() + key.substr(1);
  409. const type = overrides.type || 'PERCENT';
  410. return {
  411. id: key,
  412. key,
  413. name,
  414. type
  415. };
  416. }
  417. export function mockMeasure(overrides: Partial<Measure> = {}): Measure {
  418. return {
  419. bestValue: true,
  420. metric: 'bugs',
  421. period: {
  422. bestValue: true,
  423. index: 1,
  424. value: '1.0'
  425. },
  426. value: '1.0',
  427. ...overrides
  428. };
  429. }
  430. export function mockMeasureEnhanced(overrides: Partial<MeasureEnhanced> = {}): MeasureEnhanced {
  431. return {
  432. bestValue: true,
  433. leak: '1',
  434. metric: mockMetric({ ...(overrides.metric || {}) }),
  435. period: {
  436. bestValue: true,
  437. index: 1,
  438. value: '1.0'
  439. },
  440. value: '1.0',
  441. ...overrides
  442. };
  443. }
  444. export function mockPeriod(overrides: Partial<Period> = {}): Period {
  445. return {
  446. date: '2019-04-23T02:12:32+0100',
  447. index: 0,
  448. mode: 'previous_version',
  449. ...overrides
  450. };
  451. }
  452. export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile {
  453. return {
  454. activeDeprecatedRuleCount: 2,
  455. activeRuleCount: 10,
  456. childrenCount: 0,
  457. depth: 1,
  458. isBuiltIn: false,
  459. isDefault: false,
  460. isInherited: false,
  461. key: 'key',
  462. language: 'js',
  463. languageName: 'JavaScript',
  464. name: 'name',
  465. projectCount: 3,
  466. ...overrides
  467. };
  468. }
  469. export function mockQualityProfileInheritance(
  470. overrides: Partial<ProfileInheritanceDetails> = {}
  471. ): ProfileInheritanceDetails {
  472. return {
  473. activeRuleCount: 4,
  474. isBuiltIn: false,
  475. key: 'foo',
  476. name: 'Foo',
  477. overridingRuleCount: 0,
  478. ...overrides
  479. };
  480. }
  481. export function mockQualityProfileChangelogEvent(eventOverride?: any) {
  482. return {
  483. action: 'ACTIVATED',
  484. date: '2019-04-23T02:12:32+0100',
  485. params: {
  486. severity: 'MAJOR'
  487. },
  488. ruleKey: 'rule-key',
  489. ruleName: 'rule-name',
  490. ...eventOverride
  491. };
  492. }
  493. export function mockQualityProfileExporter(override?: Partial<Exporter>): Exporter {
  494. return {
  495. key: 'exporter-key',
  496. name: 'exporter-name',
  497. languages: ['first-lang', 'second-lang'],
  498. ...override
  499. };
  500. }
  501. export function mockRouter(overrides: { push?: Function; replace?: Function } = {}) {
  502. return {
  503. createHref: jest.fn(),
  504. createPath: jest.fn(),
  505. go: jest.fn(),
  506. goBack: jest.fn(),
  507. goForward: jest.fn(),
  508. isActive: jest.fn(),
  509. push: jest.fn(),
  510. replace: jest.fn(),
  511. setRouteLeaveHook: jest.fn(),
  512. ...overrides
  513. } as InjectedRouter;
  514. }
  515. export function mockRule(overrides: Partial<Rule> = {}): Rule {
  516. return {
  517. key: 'javascript:S1067',
  518. lang: 'js',
  519. langName: 'JavaScript',
  520. name: 'Use foo',
  521. severity: 'MAJOR',
  522. status: 'READY',
  523. sysTags: ['a', 'b'],
  524. tags: ['x'],
  525. type: 'CODE_SMELL',
  526. ...overrides
  527. } as Rule;
  528. }
  529. export function mockRuleActivation(overrides: Partial<RuleActivation> = {}): RuleActivation {
  530. return {
  531. createdAt: '2020-02-01',
  532. inherit: 'NONE',
  533. params: [{ key: 'foo', value: 'Bar' }],
  534. qProfile: 'baz',
  535. severity: 'MAJOR',
  536. ...overrides
  537. };
  538. }
  539. export function mockRuleDetails(overrides: Partial<RuleDetails> = {}): RuleDetails {
  540. return {
  541. key: 'squid:S1337',
  542. repo: 'squid',
  543. name: '".equals()" should not be used to test the values of "Atomic" classes',
  544. createdAt: '2014-12-16T17:26:54+0100',
  545. htmlDesc: '',
  546. mdDesc: '',
  547. severity: 'MAJOR',
  548. status: 'READY',
  549. isTemplate: false,
  550. tags: [],
  551. sysTags: ['multi-threading'],
  552. lang: 'java',
  553. langName: 'Java',
  554. params: [],
  555. defaultDebtRemFnType: 'CONSTANT_ISSUE',
  556. defaultDebtRemFnOffset: '5min',
  557. debtOverloaded: false,
  558. debtRemFnType: 'CONSTANT_ISSUE',
  559. debtRemFnOffset: '5min',
  560. defaultRemFnType: 'CONSTANT_ISSUE',
  561. defaultRemFnBaseEffort: '5min',
  562. remFnType: 'CONSTANT_ISSUE',
  563. remFnBaseEffort: '5min',
  564. remFnOverloaded: false,
  565. scope: 'MAIN',
  566. isExternal: false,
  567. type: 'BUG',
  568. ...overrides
  569. };
  570. }
  571. export function mockRuleDetailsParameter(overrides: Partial<RuleParameter> = {}): RuleParameter {
  572. return {
  573. defaultValue: '1',
  574. htmlDesc: 'description',
  575. key: '1',
  576. type: 'number',
  577. ...overrides
  578. };
  579. }
  580. export function mockSourceViewerFile(overrides: Partial<SourceViewerFile> = {}): SourceViewerFile {
  581. return {
  582. key: 'foo',
  583. measures: {
  584. coverage: '85.2',
  585. duplicationDensity: '1.0',
  586. issues: '12',
  587. lines: '56'
  588. },
  589. path: 'foo/bar.ts',
  590. project: 'my-project',
  591. projectName: 'MyProject',
  592. q: 'FIL',
  593. uuid: 'foo-bar',
  594. ...overrides
  595. };
  596. }
  597. export function mockStandaloneSysInfo(overrides: Partial<any> = {}): SysInfoStandalone {
  598. const baseInfo = mockBaseSysInfo(overrides);
  599. return {
  600. ...baseInfo,
  601. System: {
  602. ...baseInfo.System,
  603. 'High Availability': false,
  604. 'Server ID': 'asd564-asd54a-5dsfg45'
  605. },
  606. Settings: {
  607. 'sonar.cluster.enabled': 'true',
  608. 'sonar.cluster.node.name': 'server9.example.com'
  609. },
  610. 'Web JVM State': {
  611. 'Max Memory (MB)': 1024,
  612. 'Free Memory (MB)': 111
  613. },
  614. 'Web Database Connection': {
  615. 'Pool Active Connections': 0,
  616. 'Pool Max Connections': 60
  617. },
  618. 'Web Logging': { 'Logs Level': 'INFO', 'Logs Dir': '/logs' },
  619. 'Web JVM Properties': {
  620. 'file.encoding': 'UTF-8',
  621. 'file.separator': '/'
  622. },
  623. 'Compute Engine Tasks': {
  624. Pending: 0,
  625. 'In Progress': 0
  626. },
  627. 'Compute Engine JVM State': {
  628. 'Max Memory (MB)': 1024,
  629. 'Free Memory (MB)': 89
  630. },
  631. 'Compute Engine Database Connection': {
  632. 'Pool Initial Size': 0,
  633. 'Pool Active Connections': 0
  634. },
  635. 'Compute Engine Logging': {
  636. 'Logs Level': 'DEBUG',
  637. 'Logs Dir': '/logs'
  638. },
  639. 'Compute Engine JVM Properties': {
  640. 'file.encoding': 'UTF-8',
  641. 'file.separator': '/'
  642. },
  643. ALMs: {},
  644. Bundled: {},
  645. Plugins: {},
  646. ...overrides
  647. };
  648. }
  649. export function mockStore(state: any = {}, reducer = (state: any) => state): Store {
  650. return createStore(reducer, state);
  651. }
  652. export function mockUser(overrides: Partial<User> = {}): User {
  653. return {
  654. active: true,
  655. local: true,
  656. login: 'john.doe',
  657. name: 'John Doe',
  658. ...overrides
  659. };
  660. }
  661. export function mockDocumentationMarkdown(
  662. overrides: Partial<{ content: string; title: string; key: string }> = {}
  663. ): string {
  664. const content =
  665. overrides.content ||
  666. `
  667. ## Lorem Ipsum
  668. Donec at est elit. In finibus justo ut augue rhoncus, vitae consequat mauris mattis.
  669. Nunc ante est, volutpat ac volutpat ac, pharetra in libero.
  670. `;
  671. const frontMatter = `
  672. ---
  673. ${overrides.title ? 'title: ' + overrides.title : ''}
  674. ${overrides.key ? 'key: ' + overrides.key : ''}
  675. ---`;
  676. return `${frontMatter}
  677. ${content}`;
  678. }
  679. export function mockDocumentationEntry(
  680. overrides: Partial<DocumentationEntry> = {}
  681. ): DocumentationEntry {
  682. return {
  683. content: 'Lorem ipsum dolor sit amet fredum',
  684. relativeName: 'Lorem',
  685. navTitle: undefined,
  686. text: 'Lorem ipsum dolor sit amet fredum',
  687. title: 'Lorem',
  688. url: '/lorem/ipsum',
  689. ...overrides
  690. };
  691. }
  692. export function mockLanguage(overrides: Partial<Language> = {}): Language {
  693. return {
  694. key: 'css',
  695. name: 'CSS',
  696. ...overrides
  697. };
  698. }
  699. export function mockFlowLocation(overrides: Partial<FlowLocation> = {}): FlowLocation {
  700. return {
  701. component: 'main.js',
  702. textRange: {
  703. startLine: 1,
  704. startOffset: 1,
  705. endLine: 2,
  706. endOffset: 2
  707. },
  708. ...overrides
  709. };
  710. }
  711. export function mockIdentityProvider(overrides: Partial<IdentityProvider> = {}): IdentityProvider {
  712. return {
  713. backgroundColor: '#000000',
  714. iconPath: '/path/icon.svg',
  715. key: 'github',
  716. name: 'Github',
  717. ...overrides
  718. };
  719. }
  720. export function mockRef(
  721. overrides: Partial<React.RefObject<Partial<HTMLElement>>> = {}
  722. ): React.RefObject<HTMLElement> {
  723. return {
  724. current: {
  725. getBoundingClientRect: jest.fn(),
  726. ...overrides.current
  727. }
  728. } as React.RefObject<HTMLElement>;
  729. }
  730. export function mockPaging(overrides: Partial<Paging> = {}): Paging {
  731. return {
  732. pageIndex: 1,
  733. pageSize: 100,
  734. total: 1000,
  735. ...overrides
  736. };
  737. }
  738. export function mockDumpTask(props: Partial<DumpTask> = {}): DumpTask {
  739. return {
  740. status: TaskStatuses.Success,
  741. startedAt: '2020-03-12T12:20:20Z',
  742. submittedAt: '2020-03-12T12:15:20Z',
  743. executedAt: '2020-03-12T12:22:20Z',
  744. ...props
  745. };
  746. }
  747. export function mockDumpStatus(props: Partial<DumpStatus> = {}): DumpStatus {
  748. return {
  749. canBeExported: true,
  750. canBeImported: true,
  751. dumpToImport: '',
  752. exportedDump: '',
  753. ...props
  754. };
  755. }
  756. export function mockRuleRepository(
  757. override: Partial<{ key: string; language: string; name: string }> = {}
  758. ) {
  759. return { key: 'css', language: 'css', name: 'SonarQube', ...override };
  760. }