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 { |
| 19 | AccountId, |
| 20 | AccountInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 21 | AccountsConfigInfo, |
| 22 | ApprovalInfo, |
| 23 | AuthInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 24 | BranchName, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 25 | ChangeConfigInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 26 | ChangeId, |
| 27 | ChangeInfo, |
| 28 | ChangeInfoId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 29 | ChangeMessageId, |
| 30 | ChangeMessageInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 31 | ChangeViewChangeInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 32 | CommentLinkInfo, |
| 33 | CommentLinks, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 34 | CommitId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 35 | CommitInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 36 | ConfigInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 37 | DownloadInfo, |
| 38 | EditPatchSetNum, |
| 39 | GerritInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 40 | EmailAddress, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 41 | GitPersonInfo, |
| 42 | GitRef, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 43 | InheritedBooleanInfo, |
| 44 | MaxObjectSizeLimitInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 45 | MergeableInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 46 | NumericChangeId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 47 | PatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 48 | PluginConfigInfo, |
| 49 | PreferencesInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 50 | RepoName, |
| 51 | Reviewers, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 52 | RevisionInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 53 | SchemesInfoMap, |
| 54 | ServerInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 55 | SubmitTypeInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 56 | SuggestInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 57 | Timestamp, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 58 | TimezoneOffset, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 59 | UserConfigInfo, |
Ben Rohlfs | 07d0f6c | 2020-11-04 08:46:30 +0100 | [diff] [blame] | 60 | AccountDetailInfo, |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 61 | Requirement, |
| 62 | RequirementType, |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 63 | UrlEncodedCommentId, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 64 | BasePatchSetNum, |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame^] | 65 | RelatedChangeAndCommitInfo, |
| 66 | SubmittedTogetherInfo, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 67 | } from '../types/common'; |
| 68 | import { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 69 | AccountsVisibility, |
| 70 | AppTheme, |
| 71 | AuthType, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 72 | ChangeStatus, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 73 | DateFormat, |
| 74 | DefaultBase, |
| 75 | DefaultDisplayNameConfig, |
| 76 | DiffViewMode, |
| 77 | EmailStrategy, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 78 | InheritedBooleanInfoConfiguredValue, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 79 | MergeabilityComputationBehavior, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 80 | RevisionKind, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 81 | SubmitType, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 82 | TimeFormat, |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 83 | RequirementStatus, |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 84 | CommentSide, |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 85 | } from '../constants/constants'; |
| 86 | import {formatDate} from '../utils/date-util'; |
Ben Rohlfs | a9d2cff | 2021-01-22 21:33:58 +0100 | [diff] [blame] | 87 | import {GetDiffCommentsOutput} from '../services/gr-rest-api/gr-rest-api'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 88 | import {AppElementChangeViewParams} from '../elements/gr-app-types'; |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 89 | import {CommitInfoWithRequiredCommit} from '../elements/change/gr-change-metadata/gr-change-metadata'; |
| 90 | import {WebLinkInfo} from '../types/diff'; |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 91 | import {UIComment, UIDraft, createCommentThreads} from '../utils/comment-util'; |
Ben Rohlfs | ebe4acc | 2020-12-11 21:16:10 +0100 | [diff] [blame] | 92 | import {GerritView} from '../services/router/router-model'; |
Dhruv Srivastava | 430c1dd | 2020-12-14 08:39:32 +0100 | [diff] [blame] | 93 | import {ChangeComments} from '../elements/diff/gr-comment-api/gr-comment-api'; |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 94 | import {EditRevisionInfo, ParsedChangeInfo} from '../types/types'; |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 95 | |
| 96 | export function dateToTimestamp(date: Date): Timestamp { |
| 97 | const nanosecondSuffix = '.000000000'; |
| 98 | return (formatDate(date, 'YYYY-MM-DD HH:mm:ss') + |
| 99 | nanosecondSuffix) as Timestamp; |
| 100 | } |
| 101 | |
| 102 | export function createCommentLink(match = 'test'): CommentLinkInfo { |
| 103 | return { |
| 104 | match, |
| 105 | }; |
| 106 | } |
| 107 | |
| 108 | export function createInheritedBoolean(value = false): InheritedBooleanInfo { |
| 109 | return { |
| 110 | value, |
| 111 | configured_value: value |
| 112 | ? InheritedBooleanInfoConfiguredValue.TRUE |
| 113 | : InheritedBooleanInfoConfiguredValue.FALSE, |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | export function createMaxObjectSizeLimit(): MaxObjectSizeLimitInfo { |
| 118 | return {}; |
| 119 | } |
| 120 | |
| 121 | export function createSubmitType( |
| 122 | value: Exclude<SubmitType, SubmitType.INHERIT> = SubmitType.MERGE_IF_NECESSARY |
| 123 | ): SubmitTypeInfo { |
| 124 | return { |
| 125 | value, |
| 126 | configured_value: SubmitType.INHERIT, |
| 127 | inherited_value: value, |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | export function createCommentLinks(): CommentLinks { |
| 132 | return {}; |
| 133 | } |
| 134 | |
| 135 | export function createConfig(): ConfigInfo { |
| 136 | return { |
| 137 | private_by_default: createInheritedBoolean(), |
| 138 | work_in_progress_by_default: createInheritedBoolean(), |
| 139 | max_object_size_limit: createMaxObjectSizeLimit(), |
| 140 | default_submit_type: createSubmitType(), |
| 141 | submit_type: SubmitType.INHERIT, |
| 142 | commentlinks: createCommentLinks(), |
| 143 | }; |
| 144 | } |
| 145 | |
| 146 | export function createAccountWithId(id = 5): AccountInfo { |
| 147 | return { |
| 148 | _account_id: id as AccountId, |
| 149 | }; |
| 150 | } |
| 151 | |
Ben Rohlfs | 07d0f6c | 2020-11-04 08:46:30 +0100 | [diff] [blame] | 152 | export function createAccountDetailWithId(id = 5): AccountDetailInfo { |
| 153 | return { |
| 154 | _account_id: id as AccountId, |
| 155 | registered_on: dateToTimestamp(new Date(2020, 10, 15, 14, 5, 8)), |
| 156 | }; |
| 157 | } |
| 158 | |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 159 | export function createAccountWithEmail(email = 'test@'): AccountInfo { |
| 160 | return { |
| 161 | email: email as EmailAddress, |
| 162 | }; |
| 163 | } |
| 164 | |
| 165 | export function createAccountWithIdNameAndEmail(id = 5): AccountInfo { |
| 166 | return { |
| 167 | _account_id: id as AccountId, |
| 168 | email: `user-${id}@` as EmailAddress, |
| 169 | name: `User-${id}`, |
| 170 | }; |
| 171 | } |
| 172 | |
| 173 | export function createReviewers(): Reviewers { |
| 174 | return {}; |
| 175 | } |
| 176 | |
| 177 | export const TEST_PROJECT_NAME: RepoName = 'test-project' as RepoName; |
| 178 | export const TEST_BRANCH_ID: BranchName = 'test-branch' as BranchName; |
| 179 | export const TEST_CHANGE_ID: ChangeId = 'TestChangeId' as ChangeId; |
| 180 | export const TEST_CHANGE_INFO_ID: ChangeInfoId = `${TEST_PROJECT_NAME}~${TEST_BRANCH_ID}~${TEST_CHANGE_ID}` as ChangeInfoId; |
| 181 | export const TEST_SUBJECT = 'Test subject'; |
| 182 | export const TEST_NUMERIC_CHANGE_ID = 42 as NumericChangeId; |
| 183 | |
| 184 | export const TEST_CHANGE_CREATED = new Date(2020, 1, 1, 1, 2, 3); |
| 185 | export const TEST_CHANGE_UPDATED = new Date(2020, 10, 6, 5, 12, 34); |
| 186 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 187 | export function createGitPerson(name = 'Test name'): GitPersonInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 188 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 189 | name, |
| 190 | email: `${name}@`, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 191 | date: dateToTimestamp(new Date(2019, 11, 6, 14, 5, 8)), |
| 192 | tz: 0 as TimezoneOffset, |
| 193 | }; |
| 194 | } |
| 195 | |
| 196 | export function createCommit(): CommitInfo { |
| 197 | return { |
| 198 | parents: [], |
| 199 | author: createGitPerson(), |
| 200 | committer: createGitPerson(), |
| 201 | subject: 'Test commit subject', |
| 202 | message: 'Test commit message', |
| 203 | }; |
| 204 | } |
| 205 | |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame^] | 206 | export function createCommitInfoWithRequiredCommit( |
| 207 | commit = 'commit' |
| 208 | ): CommitInfoWithRequiredCommit { |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 209 | return { |
| 210 | ...createCommit(), |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame^] | 211 | commit: commit as CommitId, |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 212 | }; |
| 213 | } |
| 214 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 215 | export function createRevision(patchSetNum = 1): RevisionInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 216 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 217 | _number: patchSetNum as PatchSetNum, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 218 | commit: createCommit(), |
| 219 | created: dateToTimestamp(TEST_CHANGE_CREATED), |
| 220 | kind: RevisionKind.REWORK, |
| 221 | ref: 'refs/changes/5/6/1' as GitRef, |
| 222 | uploader: createAccountWithId(), |
| 223 | }; |
| 224 | } |
| 225 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 226 | export function createEditRevision(): EditRevisionInfo { |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 227 | return { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 228 | _number: EditPatchSetNum, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 229 | basePatchNum: 1 as BasePatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 230 | commit: createCommit(), |
| 231 | }; |
| 232 | } |
| 233 | |
| 234 | export function createChangeMessage(id = 'cm_id_1'): ChangeMessageInfo { |
| 235 | return { |
| 236 | id: id as ChangeMessageId, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 237 | date: dateToTimestamp(TEST_CHANGE_CREATED), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 238 | message: `This is a message with id ${id}`, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 239 | }; |
| 240 | } |
| 241 | |
| 242 | export function createRevisions( |
| 243 | count: number |
| 244 | ): {[revisionId: string]: RevisionInfo} { |
| 245 | const revisions: {[revisionId: string]: RevisionInfo} = {}; |
| 246 | const revisionDate = TEST_CHANGE_CREATED; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 247 | const revisionIdStart = 1; // The same as getCurrentRevision |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 248 | for (let i = 0; i < count; i++) { |
| 249 | const revisionId = (i + revisionIdStart).toString(16); |
| 250 | const revision: RevisionInfo = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 251 | ...createRevision(i + 1), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 252 | created: dateToTimestamp(revisionDate), |
| 253 | ref: `refs/changes/5/6/${i + 1}` as GitRef, |
| 254 | }; |
| 255 | revisions[revisionId] = revision; |
| 256 | // advance 1 day |
| 257 | revisionDate.setDate(revisionDate.getDate() + 1); |
| 258 | } |
| 259 | return revisions; |
| 260 | } |
| 261 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 262 | export function getCurrentRevision(count: number): CommitId { |
| 263 | const revisionIdStart = 1; // The same as createRevisions |
| 264 | return (count + revisionIdStart).toString(16) as CommitId; |
| 265 | } |
| 266 | |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 267 | export function createChangeMessages(count: number): ChangeMessageInfo[] { |
| 268 | const messageIdStart = 1000; |
| 269 | const messages: ChangeMessageInfo[] = []; |
| 270 | const messageDate = TEST_CHANGE_CREATED; |
| 271 | for (let i = 0; i < count; i++) { |
| 272 | messages.push({ |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 273 | ...createChangeMessage((i + messageIdStart).toString(16)), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 274 | date: dateToTimestamp(messageDate), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 275 | }); |
| 276 | messageDate.setDate(messageDate.getDate() + 1); |
| 277 | } |
| 278 | return messages; |
| 279 | } |
| 280 | |
Dmitrii Filippov | fc3e4f7 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 281 | export function createChange(): ChangeInfo { |
| 282 | return { |
| 283 | id: TEST_CHANGE_INFO_ID, |
| 284 | project: TEST_PROJECT_NAME, |
| 285 | branch: TEST_BRANCH_ID, |
| 286 | change_id: TEST_CHANGE_ID, |
| 287 | subject: TEST_SUBJECT, |
| 288 | status: ChangeStatus.NEW, |
| 289 | created: dateToTimestamp(TEST_CHANGE_CREATED), |
| 290 | updated: dateToTimestamp(TEST_CHANGE_UPDATED), |
| 291 | insertions: 0, |
| 292 | deletions: 0, |
| 293 | _number: TEST_NUMERIC_CHANGE_ID, |
| 294 | owner: createAccountWithId(), |
| 295 | // This is documented as optional, but actually always set. |
| 296 | reviewers: createReviewers(), |
| 297 | }; |
| 298 | } |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 299 | |
| 300 | export function createChangeViewChange(): ChangeViewChangeInfo { |
| 301 | return { |
| 302 | ...createChange(), |
| 303 | revisions: { |
| 304 | abc: createRevision(), |
| 305 | }, |
| 306 | current_revision: 'abc' as CommitId, |
| 307 | }; |
| 308 | } |
| 309 | |
| 310 | export function createParsedChange(): ParsedChangeInfo { |
| 311 | return createChangeViewChange(); |
| 312 | } |
| 313 | |
| 314 | export function createAccountsConfig(): AccountsConfigInfo { |
| 315 | return { |
| 316 | visibility: AccountsVisibility.ALL, |
| 317 | default_display_name: DefaultDisplayNameConfig.FULL_NAME, |
| 318 | }; |
| 319 | } |
| 320 | |
| 321 | export function createAuth(): AuthInfo { |
| 322 | return { |
| 323 | auth_type: AuthType.OPENID, |
| 324 | editable_account_fields: [], |
| 325 | }; |
| 326 | } |
| 327 | |
| 328 | export function createChangeConfig(): ChangeConfigInfo { |
| 329 | return { |
| 330 | large_change: 500, |
| 331 | reply_label: 'Reply', |
| 332 | reply_tooltip: 'Reply and score', |
| 333 | // The default update_delay is 5 minutes, but we don't want to accidentally |
| 334 | // start polling in tests |
| 335 | update_delay: 0, |
| 336 | mergeability_computation_behavior: |
| 337 | MergeabilityComputationBehavior.REF_UPDATED_AND_CHANGE_REINDEX, |
| 338 | enable_attention_set: false, |
| 339 | enable_assignee: false, |
| 340 | }; |
| 341 | } |
| 342 | |
| 343 | export function createDownloadSchemes(): SchemesInfoMap { |
| 344 | return {}; |
| 345 | } |
| 346 | |
| 347 | export function createDownloadInfo(): DownloadInfo { |
| 348 | return { |
| 349 | schemes: createDownloadSchemes(), |
| 350 | archives: ['tgz', 'tar'], |
| 351 | }; |
| 352 | } |
| 353 | |
| 354 | export function createGerritInfo(): GerritInfo { |
| 355 | return { |
| 356 | all_projects: 'All-Projects', |
| 357 | all_users: 'All-Users', |
| 358 | doc_search: false, |
| 359 | }; |
| 360 | } |
| 361 | |
| 362 | export function createPluginConfig(): PluginConfigInfo { |
| 363 | return { |
| 364 | has_avatars: false, |
| 365 | js_resource_paths: [], |
| 366 | html_resource_paths: [], |
| 367 | }; |
| 368 | } |
| 369 | |
| 370 | export function createSuggestInfo(): SuggestInfo { |
| 371 | return { |
| 372 | from: 0, |
| 373 | }; |
| 374 | } |
| 375 | |
| 376 | export function createUserConfig(): UserConfigInfo { |
| 377 | return { |
| 378 | anonymous_coward_name: 'Name of user not set', |
| 379 | }; |
| 380 | } |
| 381 | |
| 382 | export function createServerInfo(): ServerInfo { |
| 383 | return { |
| 384 | accounts: createAccountsConfig(), |
| 385 | auth: createAuth(), |
| 386 | change: createChangeConfig(), |
| 387 | download: createDownloadInfo(), |
| 388 | gerrit: createGerritInfo(), |
| 389 | plugin: createPluginConfig(), |
| 390 | suggest: createSuggestInfo(), |
| 391 | user: createUserConfig(), |
| 392 | }; |
| 393 | } |
| 394 | |
| 395 | export function createGetDiffCommentsOutput(): GetDiffCommentsOutput { |
| 396 | return { |
| 397 | baseComments: [], |
| 398 | comments: [], |
| 399 | }; |
| 400 | } |
| 401 | |
| 402 | export function createMergeable(): MergeableInfo { |
| 403 | return { |
| 404 | submit_type: SubmitType.MERGE_IF_NECESSARY, |
| 405 | mergeable: false, |
| 406 | }; |
| 407 | } |
| 408 | |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 409 | // TODO: Maybe reconcile with createDefaultPreferences() in constants.ts. |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 410 | export function createPreferences(): PreferencesInfo { |
| 411 | return { |
| 412 | changes_per_page: 10, |
| 413 | theme: AppTheme.LIGHT, |
| 414 | date_format: DateFormat.ISO, |
| 415 | time_format: TimeFormat.HHMM_24, |
| 416 | diff_view: DiffViewMode.SIDE_BY_SIDE, |
| 417 | my: [], |
| 418 | change_table: [], |
| 419 | email_strategy: EmailStrategy.ENABLED, |
| 420 | default_base_for_merges: DefaultBase.AUTO_MERGE, |
| 421 | }; |
| 422 | } |
| 423 | |
| 424 | export function createApproval(): ApprovalInfo { |
| 425 | return createAccountWithId(); |
| 426 | } |
| 427 | |
| 428 | export function createAppElementChangeViewParams(): AppElementChangeViewParams { |
| 429 | return { |
| 430 | view: GerritView.CHANGE, |
| 431 | changeNum: TEST_NUMERIC_CHANGE_ID, |
| 432 | project: TEST_PROJECT_NAME, |
| 433 | }; |
| 434 | } |
Milutin Kristofic | 40a6cde | 2020-11-30 23:48:28 +0100 | [diff] [blame] | 435 | |
| 436 | export function createRequirement(): Requirement { |
| 437 | return { |
| 438 | status: RequirementStatus.OK, |
| 439 | fallbackText: '', |
| 440 | type: 'wip' as RequirementType, |
| 441 | }; |
| 442 | } |
| 443 | |
| 444 | export function createWebLinkInfo(): WebLinkInfo { |
| 445 | return { |
| 446 | name: 'gitiles', |
| 447 | url: '#', |
| 448 | image_url: 'gitiles.jpg', |
| 449 | }; |
| 450 | } |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 451 | |
| 452 | export function createComment(): UIComment { |
| 453 | return { |
| 454 | patch_set: 1 as PatchSetNum, |
| 455 | id: '12345' as UrlEncodedCommentId, |
| 456 | side: CommentSide.REVISION, |
| 457 | line: 1, |
| 458 | message: 'hello world', |
| 459 | updated: '2018-02-13 22:48:48.018000000' as Timestamp, |
| 460 | unresolved: false, |
Dhruv Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 461 | path: 'abc.txt', |
Dhruv Srivastava | 52e7f15 | 2020-10-15 14:41:58 +0200 | [diff] [blame] | 462 | }; |
| 463 | } |
| 464 | |
| 465 | export function createDraft(): UIDraft { |
| 466 | return { |
| 467 | ...createComment(), |
| 468 | collapsed: false, |
| 469 | __draft: true, |
| 470 | __editing: false, |
| 471 | }; |
| 472 | } |
Dhruv Srivastava | 430c1dd | 2020-12-14 08:39:32 +0100 | [diff] [blame] | 473 | |
| 474 | export function createChangeComments(): ChangeComments { |
| 475 | const comments = { |
| 476 | '/COMMIT_MSG': [ |
| 477 | { |
| 478 | ...createComment(), |
| 479 | message: 'Done', |
| 480 | updated: '2017-02-08 16:40:49' as Timestamp, |
| 481 | id: '1' as UrlEncodedCommentId, |
| 482 | }, |
| 483 | { |
| 484 | ...createComment(), |
| 485 | message: 'oh hay', |
| 486 | updated: '2017-02-09 16:40:49' as Timestamp, |
| 487 | id: '2' as UrlEncodedCommentId, |
| 488 | }, |
| 489 | { |
| 490 | ...createComment(), |
| 491 | patch_set: 2 as PatchSetNum, |
| 492 | message: 'hello', |
| 493 | updated: '2017-02-10 16:40:49' as Timestamp, |
| 494 | id: '3' as UrlEncodedCommentId, |
| 495 | }, |
| 496 | ], |
| 497 | 'myfile.txt': [ |
| 498 | { |
| 499 | ...createComment(), |
| 500 | message: 'good news!', |
| 501 | updated: '2017-02-08 16:40:49' as Timestamp, |
| 502 | id: '4' as UrlEncodedCommentId, |
| 503 | }, |
| 504 | { |
| 505 | ...createComment(), |
| 506 | patch_set: 2 as PatchSetNum, |
| 507 | message: 'wat!?', |
| 508 | updated: '2017-02-09 16:40:49' as Timestamp, |
| 509 | id: '5' as UrlEncodedCommentId, |
| 510 | }, |
| 511 | { |
| 512 | ...createComment(), |
| 513 | patch_set: 2 as PatchSetNum, |
| 514 | message: 'hi', |
| 515 | updated: '2017-02-10 16:40:49' as Timestamp, |
| 516 | id: '6' as UrlEncodedCommentId, |
| 517 | }, |
| 518 | ], |
| 519 | 'unresolved.file': [ |
| 520 | { |
| 521 | ...createComment(), |
| 522 | patch_set: 2 as PatchSetNum, |
| 523 | message: 'wat!?', |
| 524 | updated: '2017-02-09 16:40:49' as Timestamp, |
| 525 | id: '7' as UrlEncodedCommentId, |
| 526 | unresolved: true, |
| 527 | }, |
| 528 | { |
| 529 | ...createComment(), |
| 530 | patch_set: 2 as PatchSetNum, |
| 531 | message: 'hi', |
| 532 | updated: '2017-02-10 16:40:49' as Timestamp, |
| 533 | id: '8' as UrlEncodedCommentId, |
| 534 | in_reply_to: '7' as UrlEncodedCommentId, |
| 535 | unresolved: false, |
| 536 | }, |
| 537 | { |
| 538 | ...createComment(), |
| 539 | patch_set: 2 as PatchSetNum, |
| 540 | message: 'good news!', |
| 541 | updated: '2017-02-08 16:40:49' as Timestamp, |
| 542 | id: '9' as UrlEncodedCommentId, |
| 543 | unresolved: true, |
| 544 | }, |
| 545 | ], |
| 546 | }; |
| 547 | const drafts = { |
| 548 | '/COMMIT_MSG': [ |
| 549 | { |
| 550 | ...createDraft(), |
| 551 | message: 'hi', |
| 552 | updated: '2017-02-15 16:40:49' as Timestamp, |
| 553 | id: '10' as UrlEncodedCommentId, |
| 554 | unresolved: true, |
| 555 | }, |
| 556 | { |
| 557 | ...createDraft(), |
| 558 | message: 'fyi', |
| 559 | updated: '2017-02-15 16:40:49' as Timestamp, |
| 560 | id: '11' as UrlEncodedCommentId, |
| 561 | unresolved: false, |
| 562 | }, |
| 563 | ], |
| 564 | 'unresolved.file': [ |
| 565 | { |
| 566 | ...createDraft(), |
| 567 | message: 'hi', |
| 568 | updated: '2017-02-11 16:40:49' as Timestamp, |
| 569 | id: '12' as UrlEncodedCommentId, |
| 570 | unresolved: false, |
| 571 | }, |
| 572 | ], |
| 573 | }; |
| 574 | return new ChangeComments(comments, {}, drafts, {}, {}); |
| 575 | } |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 576 | |
| 577 | export function createCommentThread(comments: UIComment[]) { |
Dhruv Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 578 | if (!comments.length) { |
| 579 | throw new Error('comment is required to create a thread'); |
| 580 | } |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 581 | comments = comments.map(comment => { |
| 582 | return {...createComment(), ...comment}; |
| 583 | }); |
| 584 | const threads = createCommentThreads(comments); |
Dhruv Srivastava | 254cb72 | 2021-03-08 21:15:37 +0100 | [diff] [blame] | 585 | return threads[0]; |
Dhruv Srivastava | d6737fb | 2020-12-16 13:54:12 +0100 | [diff] [blame] | 586 | } |
Milutin Kristofic | f4c04fb4 | 2021-03-10 16:41:19 +0100 | [diff] [blame^] | 587 | |
| 588 | export function createRelatedChangeAndCommitInfo(): RelatedChangeAndCommitInfo { |
| 589 | return { |
| 590 | project: TEST_PROJECT_NAME, |
| 591 | commit: createCommitInfoWithRequiredCommit(), |
| 592 | }; |
| 593 | } |
| 594 | |
| 595 | export function createSubmittedTogetherInfo(): SubmittedTogetherInfo { |
| 596 | return { |
| 597 | changes: [], |
| 598 | non_visible_changes: 0, |
| 599 | }; |
| 600 | } |