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

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