Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 18 | import { |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 19 | AccountDetailInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 20 | AccountId, |
| 21 | AccountInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 22 | AccountsConfigInfo, |
| 23 | ApprovalInfo, |
| 24 | AuthInfo, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 25 | BasePatchSetNum, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 26 | BranchName, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 27 | ChangeConfigInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 28 | ChangeId, |
| 29 | ChangeInfo, |
| 30 | ChangeInfoId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 31 | ChangeMessageId, |
| 32 | ChangeMessageInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 33 | ChangeViewChangeInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 34 | CommentLinkInfo, |
| 35 | CommentLinks, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 36 | CommitId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 37 | CommitInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 38 | ConfigInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 39 | DownloadInfo, |
| 40 | EditPatchSetNum, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 41 | EmailAddress, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 42 | FixId, |
| 43 | FixSuggestionInfo, |
| 44 | GerritInfo, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 45 | GitPersonInfo, |
| 46 | GitRef, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 47 | GroupAuditEventInfo, |
| 48 | GroupAuditEventType, |
| 49 | GroupId, |
| 50 | GroupInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 51 | InheritedBooleanInfo, |
| 52 | MaxObjectSizeLimitInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 53 | MergeableInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 54 | NumericChangeId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 55 | PatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 56 | PluginConfigInfo, |
| 57 | PreferencesInfo, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 58 | RelatedChangeAndCommitInfo, |
| 59 | RelatedChangesInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 60 | RepoName, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 61 | Requirement, |
| 62 | RequirementType, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 63 | Reviewers, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 64 | RevisionInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 65 | SchemesInfoMap, |
| 66 | ServerInfo, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 67 | SubmittedTogetherInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 68 | SubmitTypeInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 69 | SuggestInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 70 | Timestamp, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 71 | TimezoneOffset, |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 72 | UrlEncodedCommentId, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 73 | UserConfigInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 74 | } from '../types/common'; |
| 75 | import { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 76 | AccountsVisibility, |
| 77 | AppTheme, |
| 78 | AuthType, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 79 | ChangeStatus, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 80 | CommentSide, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 81 | DateFormat, |
| 82 | DefaultBase, |
| 83 | DefaultDisplayNameConfig, |
| 84 | DiffViewMode, |
| 85 | EmailStrategy, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 86 | InheritedBooleanInfoConfiguredValue, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 87 | MergeabilityComputationBehavior, |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 88 | RequirementStatus, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 89 | RevisionKind, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 90 | SubmitType, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 91 | TimeFormat, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 92 | } from '../constants/constants'; |
| 93 | import {formatDate} from '../utils/date-util'; |
Ben Rohlfs | a9d2cff | 2021-01-22 21:33:58 +0100 | [diff] [blame] | 94 | import {GetDiffCommentsOutput} from '../services/gr-rest-api/gr-rest-api'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 95 | import {AppElementChangeViewParams} from '../elements/gr-app-types'; |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 96 | import {CommitInfoWithRequiredCommit} from '../elements/change/gr-change-metadata/gr-change-metadata'; |
| 97 | import {WebLinkInfo} from '../types/diff'; |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 98 | import {createCommentThreads, UIComment, UIDraft} from '../utils/comment-util'; |
Ben Rohlfs | ebe4acc | 2020-12-11 21:16:10 +0100 | [diff] [blame] | 99 | import {GerritView} from '../services/router/router-model'; |
Dhruv Srivastava | 430c1dd | 2020-12-14 08:39:32 +0100 | [diff] [blame] | 100 | import {ChangeComments} from '../elements/diff/gr-comment-api/gr-comment-api'; |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 101 | import {EditRevisionInfo, ParsedChangeInfo} from '../types/types'; |
Dhruv Srivastava | 0d9e8f0 | 2021-03-10 12:39:52 +0100 | [diff] [blame] | 102 | import {ChangeMessage} from '../elements/change/gr-message/gr-message'; |
Paladox none | 1854846 | 2021-07-07 14:36:43 +0000 | [diff] [blame] | 103 | import {GenerateUrlEditViewParameters} from '../elements/core/gr-navigation/gr-navigation'; |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 104 | |
| 105 | export 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 | |
| 111 | export function createCommentLink(match = 'test'): CommentLinkInfo { |
| 112 | return { |
| 113 | match, |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | export function createInheritedBoolean(value = false): InheritedBooleanInfo { |
| 118 | return { |
| 119 | value, |
| 120 | configured_value: value |
| 121 | ? InheritedBooleanInfoConfiguredValue.TRUE |
| 122 | : InheritedBooleanInfoConfiguredValue.FALSE, |
| 123 | }; |
| 124 | } |
| 125 | |
| 126 | export function createMaxObjectSizeLimit(): MaxObjectSizeLimitInfo { |
| 127 | return {}; |
| 128 | } |
| 129 | |
| 130 | export 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 | |
| 140 | export function createCommentLinks(): CommentLinks { |
| 141 | return {}; |
| 142 | } |
| 143 | |
| 144 | export 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 | |
| 155 | export function createAccountWithId(id = 5): AccountInfo { |
| 156 | return { |
| 157 | _account_id: id as AccountId, |
| 158 | }; |
| 159 | } |
| 160 | |
Ben Rohlfs | 07d0f6c | 2020-11-04 08:46:30 +0100 | [diff] [blame] | 161 | export 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 Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 168 | export function createAccountWithEmail(email = 'test@'): AccountInfo { |
| 169 | return { |
| 170 | email: email as EmailAddress, |
| 171 | }; |
| 172 | } |
| 173 | |
| 174 | export 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 | |
| 182 | export function createReviewers(): Reviewers { |
| 183 | return {}; |
| 184 | } |
| 185 | |
| 186 | export const TEST_PROJECT_NAME: RepoName = 'test-project' as RepoName; |
| 187 | export const TEST_BRANCH_ID: BranchName = 'test-branch' as BranchName; |
| 188 | export const TEST_CHANGE_ID: ChangeId = 'TestChangeId' as ChangeId; |
| 189 | export const TEST_CHANGE_INFO_ID: ChangeInfoId = `${TEST_PROJECT_NAME}~${TEST_BRANCH_ID}~${TEST_CHANGE_ID}` as ChangeInfoId; |
| 190 | export const TEST_SUBJECT = 'Test subject'; |
| 191 | export const TEST_NUMERIC_CHANGE_ID = 42 as NumericChangeId; |
| 192 | |
| 193 | export const TEST_CHANGE_CREATED = new Date(2020, 1, 1, 1, 2, 3); |
| 194 | export const TEST_CHANGE_UPDATED = new Date(2020, 10, 6, 5, 12, 34); |
| 195 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 196 | export function createGitPerson(name = 'Test name'): GitPersonInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 197 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 198 | name, |
Dmitrii Filippov | 3cd78fb | 2021-07-05 12:02:37 +0200 | [diff] [blame] | 199 | email: `${name}@` as EmailAddress, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 200 | date: dateToTimestamp(new Date(2019, 11, 6, 14, 5, 8)), |
| 201 | tz: 0 as TimezoneOffset, |
| 202 | }; |
| 203 | } |
| 204 | |
| 205 | export 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 Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame] | 215 | export function createCommitInfoWithRequiredCommit( |
| 216 | commit = 'commit' |
| 217 | ): CommitInfoWithRequiredCommit { |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 218 | return { |
| 219 | ...createCommit(), |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame] | 220 | commit: commit as CommitId, |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 221 | }; |
| 222 | } |
| 223 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 224 | export function createRevision(patchSetNum = 1): RevisionInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 225 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 226 | _number: patchSetNum as PatchSetNum, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 227 | 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 Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 235 | export function createEditRevision(): EditRevisionInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 236 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 237 | _number: EditPatchSetNum, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 238 | basePatchNum: 1 as BasePatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 239 | commit: createCommit(), |
| 240 | }; |
| 241 | } |
| 242 | |
Dhruv Srivastava | 0d9e8f0 | 2021-03-10 12:39:52 +0100 | [diff] [blame] | 243 | export function createChangeMessageInfo(id = 'cm_id_1'): ChangeMessageInfo { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 244 | return { |
| 245 | id: id as ChangeMessageId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 246 | date: dateToTimestamp(TEST_CHANGE_CREATED), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 247 | message: `This is a message with id ${id}`, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 248 | }; |
| 249 | } |
| 250 | |
Dhruv Srivastava | 0d9e8f0 | 2021-03-10 12:39:52 +0100 | [diff] [blame] | 251 | export function createChangeMessage(id = 'cm_id_1'): ChangeMessage { |
| 252 | return { |
| 253 | ...createChangeMessageInfo(id), |
| 254 | type: '', |
| 255 | expanded: false, |
| 256 | commentThreads: [], |
| 257 | }; |
| 258 | } |
| 259 | |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 260 | export function createRevisions( |
| 261 | count: number |
| 262 | ): {[revisionId: string]: RevisionInfo} { |
| 263 | const revisions: {[revisionId: string]: RevisionInfo} = {}; |
| 264 | const revisionDate = TEST_CHANGE_CREATED; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 265 | const revisionIdStart = 1; // The same as getCurrentRevision |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 266 | for (let i = 0; i < count; i++) { |
| 267 | const revisionId = (i + revisionIdStart).toString(16); |
| 268 | const revision: RevisionInfo = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 269 | ...createRevision(i + 1), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 270 | 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 Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 280 | export function getCurrentRevision(count: number): CommitId { |
| 281 | const revisionIdStart = 1; // The same as createRevisions |
| 282 | return (count + revisionIdStart).toString(16) as CommitId; |
| 283 | } |
| 284 | |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 285 | export 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 Srivastava | 0d9e8f0 | 2021-03-10 12:39:52 +0100 | [diff] [blame] | 291 | ...createChangeMessageInfo((i + messageIdStart).toString(16)), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 292 | date: dateToTimestamp(messageDate), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 293 | }); |
| 294 | messageDate.setDate(messageDate.getDate() + 1); |
| 295 | } |
| 296 | return messages; |
| 297 | } |
| 298 | |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 299 | export 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 Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 317 | |
| 318 | export function createChangeViewChange(): ChangeViewChangeInfo { |
| 319 | return { |
| 320 | ...createChange(), |
| 321 | revisions: { |
| 322 | abc: createRevision(), |
| 323 | }, |
| 324 | current_revision: 'abc' as CommitId, |
| 325 | }; |
| 326 | } |
| 327 | |
| 328 | export function createParsedChange(): ParsedChangeInfo { |
| 329 | return createChangeViewChange(); |
| 330 | } |
| 331 | |
| 332 | export function createAccountsConfig(): AccountsConfigInfo { |
| 333 | return { |
| 334 | visibility: AccountsVisibility.ALL, |
| 335 | default_display_name: DefaultDisplayNameConfig.FULL_NAME, |
| 336 | }; |
| 337 | } |
| 338 | |
| 339 | export function createAuth(): AuthInfo { |
| 340 | return { |
| 341 | auth_type: AuthType.OPENID, |
| 342 | editable_account_fields: [], |
| 343 | }; |
| 344 | } |
| 345 | |
| 346 | export function createChangeConfig(): ChangeConfigInfo { |
| 347 | return { |
| 348 | large_change: 500, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 349 | // 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 Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 354 | enable_assignee: false, |
| 355 | }; |
| 356 | } |
| 357 | |
| 358 | export function createDownloadSchemes(): SchemesInfoMap { |
| 359 | return {}; |
| 360 | } |
| 361 | |
| 362 | export function createDownloadInfo(): DownloadInfo { |
| 363 | return { |
| 364 | schemes: createDownloadSchemes(), |
| 365 | archives: ['tgz', 'tar'], |
| 366 | }; |
| 367 | } |
| 368 | |
| 369 | export function createGerritInfo(): GerritInfo { |
| 370 | return { |
| 371 | all_projects: 'All-Projects', |
| 372 | all_users: 'All-Users', |
| 373 | doc_search: false, |
| 374 | }; |
| 375 | } |
| 376 | |
| 377 | export function createPluginConfig(): PluginConfigInfo { |
| 378 | return { |
| 379 | has_avatars: false, |
| 380 | js_resource_paths: [], |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 381 | }; |
| 382 | } |
| 383 | |
| 384 | export function createSuggestInfo(): SuggestInfo { |
| 385 | return { |
| 386 | from: 0, |
| 387 | }; |
| 388 | } |
| 389 | |
| 390 | export function createUserConfig(): UserConfigInfo { |
| 391 | return { |
| 392 | anonymous_coward_name: 'Name of user not set', |
| 393 | }; |
| 394 | } |
| 395 | |
| 396 | export 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 | |
| 409 | export function createGetDiffCommentsOutput(): GetDiffCommentsOutput { |
| 410 | return { |
| 411 | baseComments: [], |
| 412 | comments: [], |
| 413 | }; |
| 414 | } |
| 415 | |
| 416 | export function createMergeable(): MergeableInfo { |
| 417 | return { |
| 418 | submit_type: SubmitType.MERGE_IF_NECESSARY, |
| 419 | mergeable: false, |
| 420 | }; |
| 421 | } |
| 422 | |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 423 | // TODO: Maybe reconcile with createDefaultPreferences() in constants.ts. |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 424 | export 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 | |
| 438 | export function createApproval(): ApprovalInfo { |
| 439 | return createAccountWithId(); |
| 440 | } |
| 441 | |
| 442 | export function createAppElementChangeViewParams(): AppElementChangeViewParams { |
| 443 | return { |
| 444 | view: GerritView.CHANGE, |
| 445 | changeNum: TEST_NUMERIC_CHANGE_ID, |
| 446 | project: TEST_PROJECT_NAME, |
| 447 | }; |
| 448 | } |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 449 | |
Paladox none | 1854846 | 2021-07-07 14:36:43 +0000 | [diff] [blame] | 450 | export 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 Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 460 | export function createRequirement(): Requirement { |
| 461 | return { |
| 462 | status: RequirementStatus.OK, |
| 463 | fallbackText: '', |
| 464 | type: 'wip' as RequirementType, |
| 465 | }; |
| 466 | } |
| 467 | |
| 468 | export function createWebLinkInfo(): WebLinkInfo { |
| 469 | return { |
| 470 | name: 'gitiles', |
| 471 | url: '#', |
| 472 | image_url: 'gitiles.jpg', |
| 473 | }; |
| 474 | } |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 475 | |
| 476 | export 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 Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 485 | path: 'abc.txt', |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 486 | }; |
| 487 | } |
| 488 | |
| 489 | export function createDraft(): UIDraft { |
| 490 | return { |
| 491 | ...createComment(), |
| 492 | collapsed: false, |
| 493 | __draft: true, |
| 494 | __editing: false, |
| 495 | }; |
| 496 | } |
Dhruv Srivastava | 430c1dd | 2020-12-14 08:39:32 +0100 | [diff] [blame] | 497 | |
| 498 | export 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 Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 600 | |
| 601 | export function createCommentThread(comments: UIComment[]) { |
Dhruv Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 602 | if (!comments.length) { |
| 603 | throw new Error('comment is required to create a thread'); |
| 604 | } |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 605 | comments = comments.map(comment => { |
| 606 | return {...createComment(), ...comment}; |
| 607 | }); |
| 608 | const threads = createCommentThreads(comments); |
Dhruv Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 609 | return threads[0]; |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 610 | } |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame] | 611 | |
| 612 | export function createRelatedChangeAndCommitInfo(): RelatedChangeAndCommitInfo { |
| 613 | return { |
| 614 | project: TEST_PROJECT_NAME, |
| 615 | commit: createCommitInfoWithRequiredCommit(), |
| 616 | }; |
| 617 | } |
| 618 | |
Milutin Kristofic | d26e742 | 2021-03-16 20:19:01 +0100 | [diff] [blame] | 619 | export function createRelatedChangesInfo(): RelatedChangesInfo { |
| 620 | return { |
| 621 | changes: [], |
| 622 | }; |
| 623 | } |
| 624 | |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame] | 625 | export function createSubmittedTogetherInfo(): SubmittedTogetherInfo { |
| 626 | return { |
| 627 | changes: [], |
| 628 | non_visible_changes: 0, |
| 629 | }; |
| 630 | } |
Dmitrii Filippov | 131bf7a | 2021-04-01 18:02:27 +0200 | [diff] [blame] | 631 | |
| 632 | export function createFixSuggestionInfo(fixId = 'fix_1'): FixSuggestionInfo { |
| 633 | return { |
| 634 | fix_id: fixId as FixId, |
| 635 | description: `Fix ${fixId}`, |
| 636 | replacements: [], |
| 637 | }; |
| 638 | } |
Milutin Kristofic | 1cc62b5 | 2021-06-15 08:35:02 +0200 | [diff] [blame] | 639 | |
| 640 | export function createGroupInfo(id = 'id'): GroupInfo { |
| 641 | return { |
| 642 | id: id as GroupId, |
| 643 | }; |
| 644 | } |
Dmitrii Filippov | 4756192 | 2021-07-02 11:43:10 +0200 | [diff] [blame] | 645 | |
| 646 | export 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 | } |