blob: 1911644626531e64b598923f47d5d1edc8dd1a38 [file] [log] [blame]
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +02001/**
2 * @license
3 * Copyright (C) 2020 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import {
Dmitrii Filippov47561922021-07-02 11:43:10 +020019 AccountDetailInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020020 AccountId,
21 AccountInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010022 AccountsConfigInfo,
23 ApprovalInfo,
24 AuthInfo,
Dmitrii Filippov47561922021-07-02 11:43:10 +020025 BasePatchSetNum,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020026 BranchName,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010027 ChangeConfigInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020028 ChangeId,
29 ChangeInfo,
30 ChangeInfoId,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020031 ChangeMessageId,
32 ChangeMessageInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010033 ChangeViewChangeInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020034 CommentLinkInfo,
35 CommentLinks,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010036 CommitId,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020037 CommitInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020038 ConfigInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010039 DownloadInfo,
40 EditPatchSetNum,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020041 EmailAddress,
Dmitrii Filippov47561922021-07-02 11:43:10 +020042 FixId,
43 FixSuggestionInfo,
44 GerritInfo,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020045 GitPersonInfo,
46 GitRef,
Dmitrii Filippov47561922021-07-02 11:43:10 +020047 GroupAuditEventInfo,
48 GroupAuditEventType,
49 GroupId,
50 GroupInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020051 InheritedBooleanInfo,
52 MaxObjectSizeLimitInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010053 MergeableInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020054 NumericChangeId,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020055 PatchSetNum,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010056 PluginConfigInfo,
57 PreferencesInfo,
Dmitrii Filippov47561922021-07-02 11:43:10 +020058 RelatedChangeAndCommitInfo,
59 RelatedChangesInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020060 RepoName,
Dmitrii Filippov47561922021-07-02 11:43:10 +020061 Requirement,
62 RequirementType,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020063 Reviewers,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020064 RevisionInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010065 SchemesInfoMap,
66 ServerInfo,
Dmitrii Filippov47561922021-07-02 11:43:10 +020067 SubmittedTogetherInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020068 SubmitTypeInfo,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010069 SuggestInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020070 Timestamp,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020071 TimezoneOffset,
Dhruv Srivastava52e7f152020-10-15 14:41:58 +020072 UrlEncodedCommentId,
Dmitrii Filippov47561922021-07-02 11:43:10 +020073 UserConfigInfo,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020074} from '../types/common';
75import {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010076 AccountsVisibility,
77 AppTheme,
78 AuthType,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020079 ChangeStatus,
Dmitrii Filippov47561922021-07-02 11:43:10 +020080 CommentSide,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010081 DateFormat,
82 DefaultBase,
83 DefaultDisplayNameConfig,
84 DiffViewMode,
85 EmailStrategy,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020086 InheritedBooleanInfoConfiguredValue,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010087 MergeabilityComputationBehavior,
Dmitrii Filippov47561922021-07-02 11:43:10 +020088 RequirementStatus,
Dmitrii Filippov0695d402020-10-22 16:57:57 +020089 RevisionKind,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020090 SubmitType,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010091 TimeFormat,
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +020092} from '../constants/constants';
93import {formatDate} from '../utils/date-util';
Ben Rohlfsa9d2cff2021-01-22 21:33:58 +010094import {GetDiffCommentsOutput} from '../services/gr-rest-api/gr-rest-api';
Dmitrii Filippov78448cd2020-10-26 17:39:11 +010095import {AppElementChangeViewParams} from '../elements/gr-app-types';
Milutin Kristofic40a6cde2020-11-30 23:48:28 +010096import {CommitInfoWithRequiredCommit} from '../elements/change/gr-change-metadata/gr-change-metadata';
97import {WebLinkInfo} from '../types/diff';
Dmitrii Filippov47561922021-07-02 11:43:10 +020098import {createCommentThreads, UIComment, UIDraft} from '../utils/comment-util';
Ben Rohlfsebe4acc2020-12-11 21:16:10 +010099import {GerritView} from '../services/router/router-model';
Dhruv Srivastava430c1dd2020-12-14 08:39:32 +0100100import {ChangeComments} from '../elements/diff/gr-comment-api/gr-comment-api';
Ben Rohlfsa00ef282021-01-22 21:45:53 +0100101import {EditRevisionInfo, ParsedChangeInfo} from '../types/types';
Dhruv Srivastava0d9e8f02021-03-10 12:39:52 +0100102import {ChangeMessage} from '../elements/change/gr-message/gr-message';
Paladox none18548462021-07-07 14:36:43 +0000103import {GenerateUrlEditViewParameters} from '../elements/core/gr-navigation/gr-navigation';
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +0200104
105export function dateToTimestamp(date: Date): Timestamp {
106 const nanosecondSuffix = '.000000000';
107 return (formatDate(date, 'YYYY-MM-DD HH:mm:ss') +
108 nanosecondSuffix) as Timestamp;
109}
110
111export function createCommentLink(match = 'test'): CommentLinkInfo {
112 return {
113 match,
114 };
115}
116
117export function createInheritedBoolean(value = false): InheritedBooleanInfo {
118 return {
119 value,
120 configured_value: value
121 ? InheritedBooleanInfoConfiguredValue.TRUE
122 : InheritedBooleanInfoConfiguredValue.FALSE,
123 };
124}
125
126export function createMaxObjectSizeLimit(): MaxObjectSizeLimitInfo {
127 return {};
128}
129
130export function createSubmitType(
131 value: Exclude<SubmitType, SubmitType.INHERIT> = SubmitType.MERGE_IF_NECESSARY
132): SubmitTypeInfo {
133 return {
134 value,
135 configured_value: SubmitType.INHERIT,
136 inherited_value: value,
137 };
138}
139
140export function createCommentLinks(): CommentLinks {
141 return {};
142}
143
144export function createConfig(): ConfigInfo {
145 return {
146 private_by_default: createInheritedBoolean(),
147 work_in_progress_by_default: createInheritedBoolean(),
148 max_object_size_limit: createMaxObjectSizeLimit(),
149 default_submit_type: createSubmitType(),
150 submit_type: SubmitType.INHERIT,
151 commentlinks: createCommentLinks(),
152 };
153}
154
155export function createAccountWithId(id = 5): AccountInfo {
156 return {
157 _account_id: id as AccountId,
158 };
159}
160
Ben Rohlfs07d0f6c2020-11-04 08:46:30 +0100161export function createAccountDetailWithId(id = 5): AccountDetailInfo {
162 return {
163 _account_id: id as AccountId,
164 registered_on: dateToTimestamp(new Date(2020, 10, 15, 14, 5, 8)),
165 };
166}
167
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +0200168export function createAccountWithEmail(email = 'test@'): AccountInfo {
169 return {
170 email: email as EmailAddress,
171 };
172}
173
174export function createAccountWithIdNameAndEmail(id = 5): AccountInfo {
175 return {
176 _account_id: id as AccountId,
177 email: `user-${id}@` as EmailAddress,
178 name: `User-${id}`,
179 };
180}
181
182export function createReviewers(): Reviewers {
183 return {};
184}
185
186export const TEST_PROJECT_NAME: RepoName = 'test-project' as RepoName;
187export const TEST_BRANCH_ID: BranchName = 'test-branch' as BranchName;
188export const TEST_CHANGE_ID: ChangeId = 'TestChangeId' as ChangeId;
189export const TEST_CHANGE_INFO_ID: ChangeInfoId = `${TEST_PROJECT_NAME}~${TEST_BRANCH_ID}~${TEST_CHANGE_ID}` as ChangeInfoId;
190export const TEST_SUBJECT = 'Test subject';
191export const TEST_NUMERIC_CHANGE_ID = 42 as NumericChangeId;
192
193export const TEST_CHANGE_CREATED = new Date(2020, 1, 1, 1, 2, 3);
194export const TEST_CHANGE_UPDATED = new Date(2020, 10, 6, 5, 12, 34);
195
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100196export function createGitPerson(name = 'Test name'): GitPersonInfo {
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200197 return {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100198 name,
Dmitrii Filippov3cd78fb2021-07-05 12:02:37 +0200199 email: `${name}@` as EmailAddress,
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200200 date: dateToTimestamp(new Date(2019, 11, 6, 14, 5, 8)),
201 tz: 0 as TimezoneOffset,
202 };
203}
204
205export function createCommit(): CommitInfo {
206 return {
207 parents: [],
208 author: createGitPerson(),
209 committer: createGitPerson(),
210 subject: 'Test commit subject',
211 message: 'Test commit message',
212 };
213}
214
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +0100215export function createCommitInfoWithRequiredCommit(
216 commit = 'commit'
217): CommitInfoWithRequiredCommit {
Milutin Kristofic40a6cde2020-11-30 23:48:28 +0100218 return {
219 ...createCommit(),
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +0100220 commit: commit as CommitId,
Milutin Kristofic40a6cde2020-11-30 23:48:28 +0100221 };
222}
223
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100224export function createRevision(patchSetNum = 1): RevisionInfo {
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200225 return {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100226 _number: patchSetNum as PatchSetNum,
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200227 commit: createCommit(),
228 created: dateToTimestamp(TEST_CHANGE_CREATED),
229 kind: RevisionKind.REWORK,
230 ref: 'refs/changes/5/6/1' as GitRef,
231 uploader: createAccountWithId(),
232 };
233}
234
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100235export function createEditRevision(): EditRevisionInfo {
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200236 return {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100237 _number: EditPatchSetNum,
Dhruv Srivastava591b4902021-03-10 11:48:12 +0100238 basePatchNum: 1 as BasePatchSetNum,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100239 commit: createCommit(),
240 };
241}
242
Dhruv Srivastava0d9e8f02021-03-10 12:39:52 +0100243export function createChangeMessageInfo(id = 'cm_id_1'): ChangeMessageInfo {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100244 return {
245 id: id as ChangeMessageId,
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200246 date: dateToTimestamp(TEST_CHANGE_CREATED),
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100247 message: `This is a message with id ${id}`,
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200248 };
249}
250
Dhruv Srivastava0d9e8f02021-03-10 12:39:52 +0100251export function createChangeMessage(id = 'cm_id_1'): ChangeMessage {
252 return {
253 ...createChangeMessageInfo(id),
254 type: '',
255 expanded: false,
256 commentThreads: [],
257 };
258}
259
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200260export function createRevisions(
261 count: number
262): {[revisionId: string]: RevisionInfo} {
263 const revisions: {[revisionId: string]: RevisionInfo} = {};
264 const revisionDate = TEST_CHANGE_CREATED;
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100265 const revisionIdStart = 1; // The same as getCurrentRevision
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200266 for (let i = 0; i < count; i++) {
267 const revisionId = (i + revisionIdStart).toString(16);
268 const revision: RevisionInfo = {
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100269 ...createRevision(i + 1),
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200270 created: dateToTimestamp(revisionDate),
271 ref: `refs/changes/5/6/${i + 1}` as GitRef,
272 };
273 revisions[revisionId] = revision;
274 // advance 1 day
275 revisionDate.setDate(revisionDate.getDate() + 1);
276 }
277 return revisions;
278}
279
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100280export function getCurrentRevision(count: number): CommitId {
281 const revisionIdStart = 1; // The same as createRevisions
282 return (count + revisionIdStart).toString(16) as CommitId;
283}
284
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200285export function createChangeMessages(count: number): ChangeMessageInfo[] {
286 const messageIdStart = 1000;
287 const messages: ChangeMessageInfo[] = [];
288 const messageDate = TEST_CHANGE_CREATED;
289 for (let i = 0; i < count; i++) {
290 messages.push({
Dhruv Srivastava0d9e8f02021-03-10 12:39:52 +0100291 ...createChangeMessageInfo((i + messageIdStart).toString(16)),
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200292 date: dateToTimestamp(messageDate),
Dmitrii Filippov0695d402020-10-22 16:57:57 +0200293 });
294 messageDate.setDate(messageDate.getDate() + 1);
295 }
296 return messages;
297}
298
Dmitrii Filippovfc3e4f72020-10-22 16:57:57 +0200299export function createChange(): ChangeInfo {
300 return {
301 id: TEST_CHANGE_INFO_ID,
302 project: TEST_PROJECT_NAME,
303 branch: TEST_BRANCH_ID,
304 change_id: TEST_CHANGE_ID,
305 subject: TEST_SUBJECT,
306 status: ChangeStatus.NEW,
307 created: dateToTimestamp(TEST_CHANGE_CREATED),
308 updated: dateToTimestamp(TEST_CHANGE_UPDATED),
309 insertions: 0,
310 deletions: 0,
311 _number: TEST_NUMERIC_CHANGE_ID,
312 owner: createAccountWithId(),
313 // This is documented as optional, but actually always set.
314 reviewers: createReviewers(),
315 };
316}
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100317
318export function createChangeViewChange(): ChangeViewChangeInfo {
319 return {
320 ...createChange(),
321 revisions: {
322 abc: createRevision(),
323 },
324 current_revision: 'abc' as CommitId,
325 };
326}
327
328export function createParsedChange(): ParsedChangeInfo {
329 return createChangeViewChange();
330}
331
332export function createAccountsConfig(): AccountsConfigInfo {
333 return {
334 visibility: AccountsVisibility.ALL,
335 default_display_name: DefaultDisplayNameConfig.FULL_NAME,
336 };
337}
338
339export function createAuth(): AuthInfo {
340 return {
341 auth_type: AuthType.OPENID,
342 editable_account_fields: [],
343 };
344}
345
346export function createChangeConfig(): ChangeConfigInfo {
347 return {
348 large_change: 500,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100349 // The default update_delay is 5 minutes, but we don't want to accidentally
350 // start polling in tests
351 update_delay: 0,
352 mergeability_computation_behavior:
353 MergeabilityComputationBehavior.REF_UPDATED_AND_CHANGE_REINDEX,
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100354 enable_assignee: false,
355 };
356}
357
358export function createDownloadSchemes(): SchemesInfoMap {
359 return {};
360}
361
362export function createDownloadInfo(): DownloadInfo {
363 return {
364 schemes: createDownloadSchemes(),
365 archives: ['tgz', 'tar'],
366 };
367}
368
369export function createGerritInfo(): GerritInfo {
370 return {
371 all_projects: 'All-Projects',
372 all_users: 'All-Users',
373 doc_search: false,
374 };
375}
376
377export function createPluginConfig(): PluginConfigInfo {
378 return {
379 has_avatars: false,
380 js_resource_paths: [],
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100381 };
382}
383
384export function createSuggestInfo(): SuggestInfo {
385 return {
386 from: 0,
387 };
388}
389
390export function createUserConfig(): UserConfigInfo {
391 return {
392 anonymous_coward_name: 'Name of user not set',
393 };
394}
395
396export function createServerInfo(): ServerInfo {
397 return {
398 accounts: createAccountsConfig(),
399 auth: createAuth(),
400 change: createChangeConfig(),
401 download: createDownloadInfo(),
402 gerrit: createGerritInfo(),
403 plugin: createPluginConfig(),
404 suggest: createSuggestInfo(),
405 user: createUserConfig(),
406 };
407}
408
409export function createGetDiffCommentsOutput(): GetDiffCommentsOutput {
410 return {
411 baseComments: [],
412 comments: [],
413 };
414}
415
416export function createMergeable(): MergeableInfo {
417 return {
418 submit_type: SubmitType.MERGE_IF_NECESSARY,
419 mergeable: false,
420 };
421}
422
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100423// TODO: Maybe reconcile with createDefaultPreferences() in constants.ts.
Dmitrii Filippov78448cd2020-10-26 17:39:11 +0100424export function createPreferences(): PreferencesInfo {
425 return {
426 changes_per_page: 10,
427 theme: AppTheme.LIGHT,
428 date_format: DateFormat.ISO,
429 time_format: TimeFormat.HHMM_24,
430 diff_view: DiffViewMode.SIDE_BY_SIDE,
431 my: [],
432 change_table: [],
433 email_strategy: EmailStrategy.ENABLED,
434 default_base_for_merges: DefaultBase.AUTO_MERGE,
435 };
436}
437
438export function createApproval(): ApprovalInfo {
439 return createAccountWithId();
440}
441
442export function createAppElementChangeViewParams(): AppElementChangeViewParams {
443 return {
444 view: GerritView.CHANGE,
445 changeNum: TEST_NUMERIC_CHANGE_ID,
446 project: TEST_PROJECT_NAME,
447 };
448}
Milutin Kristofic40a6cde2020-11-30 23:48:28 +0100449
Paladox none18548462021-07-07 14:36:43 +0000450export function createGenerateUrlEditViewParameters(): GenerateUrlEditViewParameters {
451 return {
452 view: GerritView.EDIT,
453 changeNum: TEST_NUMERIC_CHANGE_ID,
454 patchNum: EditPatchSetNum as PatchSetNum,
455 path: 'foo/bar.baz',
456 project: TEST_PROJECT_NAME,
457 };
458}
459
Milutin Kristofic40a6cde2020-11-30 23:48:28 +0100460export function createRequirement(): Requirement {
461 return {
462 status: RequirementStatus.OK,
463 fallbackText: '',
464 type: 'wip' as RequirementType,
465 };
466}
467
468export function createWebLinkInfo(): WebLinkInfo {
469 return {
470 name: 'gitiles',
471 url: '#',
472 image_url: 'gitiles.jpg',
473 };
474}
Dhruv Srivastava52e7f152020-10-15 14:41:58 +0200475
476export function createComment(): UIComment {
477 return {
478 patch_set: 1 as PatchSetNum,
479 id: '12345' as UrlEncodedCommentId,
480 side: CommentSide.REVISION,
481 line: 1,
482 message: 'hello world',
483 updated: '2018-02-13 22:48:48.018000000' as Timestamp,
484 unresolved: false,
Dhruv Srivastava254cb722021-03-08 21:15:37 +0100485 path: 'abc.txt',
Dhruv Srivastava52e7f152020-10-15 14:41:58 +0200486 };
487}
488
489export function createDraft(): UIDraft {
490 return {
491 ...createComment(),
492 collapsed: false,
493 __draft: true,
494 __editing: false,
495 };
496}
Dhruv Srivastava430c1dd2020-12-14 08:39:32 +0100497
498export function createChangeComments(): ChangeComments {
499 const comments = {
500 '/COMMIT_MSG': [
501 {
502 ...createComment(),
503 message: 'Done',
504 updated: '2017-02-08 16:40:49' as Timestamp,
505 id: '1' as UrlEncodedCommentId,
506 },
507 {
508 ...createComment(),
509 message: 'oh hay',
510 updated: '2017-02-09 16:40:49' as Timestamp,
511 id: '2' as UrlEncodedCommentId,
512 },
513 {
514 ...createComment(),
515 patch_set: 2 as PatchSetNum,
516 message: 'hello',
517 updated: '2017-02-10 16:40:49' as Timestamp,
518 id: '3' as UrlEncodedCommentId,
519 },
520 ],
521 'myfile.txt': [
522 {
523 ...createComment(),
524 message: 'good news!',
525 updated: '2017-02-08 16:40:49' as Timestamp,
526 id: '4' as UrlEncodedCommentId,
527 },
528 {
529 ...createComment(),
530 patch_set: 2 as PatchSetNum,
531 message: 'wat!?',
532 updated: '2017-02-09 16:40:49' as Timestamp,
533 id: '5' as UrlEncodedCommentId,
534 },
535 {
536 ...createComment(),
537 patch_set: 2 as PatchSetNum,
538 message: 'hi',
539 updated: '2017-02-10 16:40:49' as Timestamp,
540 id: '6' as UrlEncodedCommentId,
541 },
542 ],
543 'unresolved.file': [
544 {
545 ...createComment(),
546 patch_set: 2 as PatchSetNum,
547 message: 'wat!?',
548 updated: '2017-02-09 16:40:49' as Timestamp,
549 id: '7' as UrlEncodedCommentId,
550 unresolved: true,
551 },
552 {
553 ...createComment(),
554 patch_set: 2 as PatchSetNum,
555 message: 'hi',
556 updated: '2017-02-10 16:40:49' as Timestamp,
557 id: '8' as UrlEncodedCommentId,
558 in_reply_to: '7' as UrlEncodedCommentId,
559 unresolved: false,
560 },
561 {
562 ...createComment(),
563 patch_set: 2 as PatchSetNum,
564 message: 'good news!',
565 updated: '2017-02-08 16:40:49' as Timestamp,
566 id: '9' as UrlEncodedCommentId,
567 unresolved: true,
568 },
569 ],
570 };
571 const drafts = {
572 '/COMMIT_MSG': [
573 {
574 ...createDraft(),
575 message: 'hi',
576 updated: '2017-02-15 16:40:49' as Timestamp,
577 id: '10' as UrlEncodedCommentId,
578 unresolved: true,
579 },
580 {
581 ...createDraft(),
582 message: 'fyi',
583 updated: '2017-02-15 16:40:49' as Timestamp,
584 id: '11' as UrlEncodedCommentId,
585 unresolved: false,
586 },
587 ],
588 'unresolved.file': [
589 {
590 ...createDraft(),
591 message: 'hi',
592 updated: '2017-02-11 16:40:49' as Timestamp,
593 id: '12' as UrlEncodedCommentId,
594 unresolved: false,
595 },
596 ],
597 };
598 return new ChangeComments(comments, {}, drafts, {}, {});
599}
Dhruv Srivastavad6737fb2020-12-16 13:54:12 +0100600
601export function createCommentThread(comments: UIComment[]) {
Dhruv Srivastava254cb722021-03-08 21:15:37 +0100602 if (!comments.length) {
603 throw new Error('comment is required to create a thread');
604 }
Dhruv Srivastavad6737fb2020-12-16 13:54:12 +0100605 comments = comments.map(comment => {
606 return {...createComment(), ...comment};
607 });
608 const threads = createCommentThreads(comments);
Dhruv Srivastava254cb722021-03-08 21:15:37 +0100609 return threads[0];
Dhruv Srivastavad6737fb2020-12-16 13:54:12 +0100610}
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +0100611
612export function createRelatedChangeAndCommitInfo(): RelatedChangeAndCommitInfo {
613 return {
614 project: TEST_PROJECT_NAME,
615 commit: createCommitInfoWithRequiredCommit(),
616 };
617}
618
Milutin Kristoficd26e7422021-03-16 20:19:01 +0100619export function createRelatedChangesInfo(): RelatedChangesInfo {
620 return {
621 changes: [],
622 };
623}
624
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +0100625export function createSubmittedTogetherInfo(): SubmittedTogetherInfo {
626 return {
627 changes: [],
628 non_visible_changes: 0,
629 };
630}
Dmitrii Filippov131bf7a2021-04-01 18:02:27 +0200631
632export function createFixSuggestionInfo(fixId = 'fix_1'): FixSuggestionInfo {
633 return {
634 fix_id: fixId as FixId,
635 description: `Fix ${fixId}`,
636 replacements: [],
637 };
638}
Milutin Kristofic1cc62b52021-06-15 08:35:02 +0200639
640export function createGroupInfo(id = 'id'): GroupInfo {
641 return {
642 id: id as GroupId,
643 };
644}
Dmitrii Filippov47561922021-07-02 11:43:10 +0200645
646export function createGroupAuditEventInfo(
647 type: GroupAuditEventType
648): GroupAuditEventInfo {
649 if (
650 type === GroupAuditEventType.ADD_USER ||
651 type === GroupAuditEventType.REMOVE_USER
652 ) {
653 return {
654 type,
655 member: createAccountWithId(10),
656 user: createAccountWithId(),
657 date: dateToTimestamp(new Date(2019, 11, 6, 14, 5, 8)),
658 };
659 } else {
660 return {
661 type,
662 member: createGroupInfo(),
663 user: createAccountWithId(),
664 date: dateToTimestamp(new Date(2019, 11, 6, 14, 5, 8)),
665 };
666 }
667}