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

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