Dmitrii Filippov | acd39a2 | 2020-04-02 10:31:43 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2015 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Dmitrii Filippov | acd39a2 | 2020-04-02 10:31:43 +0200 | [diff] [blame] | 5 | */ |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 6 | import '../../../test/common-test-setup-karma'; |
| 7 | import '../../edit/gr-edit-constants'; |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 8 | import '../gr-thread-list/gr-thread-list'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 9 | import './gr-change-view'; |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 10 | import { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 11 | ChangeStatus, |
| 12 | CommentSide, |
| 13 | DefaultBase, |
| 14 | DiffViewMode, |
| 15 | HttpMethod, |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 16 | MessageTag, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 17 | PrimaryTab, |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 18 | createDefaultPreferences, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 19 | } from '../../../constants/constants'; |
| 20 | import {GrEditConstants} from '../../edit/gr-edit-constants'; |
| 21 | import {_testOnly_resetEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints'; |
Ben Rohlfs | ebe4acc | 2020-12-11 21:16:10 +0100 | [diff] [blame] | 22 | import {GerritNav} from '../../core/gr-navigation/gr-navigation'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 23 | import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader'; |
Ben Rohlfs | a7ab950 | 2021-02-15 17:45:45 +0100 | [diff] [blame] | 24 | import {EventType, PluginApi} from '../../../api/plugin'; |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 25 | import { |
| 26 | mockPromise, |
| 27 | queryAndAssert, |
| 28 | stubRestApi, |
| 29 | stubUsers, |
| 30 | waitQueryAndAssert, |
| 31 | waitUntil, |
| 32 | } from '../../../test/test-utils'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 33 | import { |
| 34 | createAppElementChangeViewParams, |
| 35 | createApproval, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 36 | createChange, |
| 37 | createChangeMessages, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 38 | createCommit, |
| 39 | createMergeable, |
| 40 | createPreferences, |
| 41 | createRevision, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 42 | createRevisions, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 43 | createServerInfo, |
| 44 | createUserConfig, |
| 45 | TEST_NUMERIC_CHANGE_ID, |
| 46 | TEST_PROJECT_NAME, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 47 | createEditRevision, |
| 48 | createAccountWithIdNameAndEmail, |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 49 | createChangeViewChange, |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 50 | createRelatedChangeAndCommitInfo, |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 51 | createAccountDetailWithId, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 52 | createParsedChange, |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 53 | createDraft, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 54 | } from '../../../test/test-data-generators'; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 55 | import {GrChangeView} from './gr-change-view'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 56 | import { |
| 57 | AccountId, |
| 58 | ApprovalInfo, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 59 | BasePatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 60 | ChangeId, |
| 61 | ChangeInfo, |
| 62 | CommitId, |
Ben Rohlfs | ef04317 | 2022-05-27 16:07:27 +0200 | [diff] [blame] | 63 | EDIT, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 64 | NumericChangeId, |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 65 | PARENT, |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 66 | RelatedChangeAndCommitInfo, |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 67 | ReviewInputTag, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 68 | RevisionInfo, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 69 | RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 70 | RobotId, |
Ben Rohlfs | 05750b9 | 2021-10-29 08:23:08 +0200 | [diff] [blame] | 71 | RobotCommentInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 72 | Timestamp, |
| 73 | UrlEncodedCommentId, |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 74 | DetailedLabelInfo, |
| 75 | RepoName, |
| 76 | QuickLabelInfo, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 77 | } from '../../../types/common'; |
| 78 | import { |
| 79 | pressAndReleaseKeyOn, |
| 80 | tap, |
| 81 | } from '@polymer/iron-test-helpers/mock-interactions'; |
| 82 | import {GrEditControls} from '../../edit/gr-edit-controls/gr-edit-controls'; |
| 83 | import {AppElementChangeViewParams} from '../../gr-app-types'; |
Ben Rohlfs | 8e28ad8 | 2021-09-20 14:48:33 +0200 | [diff] [blame] | 84 | import {SinonFakeTimers, SinonStubbedMember} from 'sinon'; |
Ben Rohlfs | a9d2cff | 2021-01-22 21:33:58 +0100 | [diff] [blame] | 85 | import {RestApiService} from '../../../services/gr-rest-api/gr-rest-api'; |
Ben Rohlfs | 05750b9 | 2021-10-29 08:23:08 +0200 | [diff] [blame] | 86 | import {CommentThread} from '../../../utils/comment-util'; |
Ben Rohlfs | ebe4acc | 2020-12-11 21:16:10 +0100 | [diff] [blame] | 87 | import {GerritView} from '../../../services/router/router-model'; |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 88 | import {ParsedChangeInfo} from '../../../types/types'; |
Milutin Kristofic | 8803ea0 | 2020-12-09 23:34:39 +0100 | [diff] [blame] | 89 | import {GrRelatedChangesList} from '../gr-related-changes-list/gr-related-changes-list'; |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 90 | import {ChangeStates} from '../../shared/gr-change-status/gr-change-status'; |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 91 | import {LoadingStatus} from '../../../models/change/change-model'; |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 92 | import {FocusTarget, GrReplyDialog} from '../gr-reply-dialog/gr-reply-dialog'; |
| 93 | import {GrOverlay} from '../../shared/gr-overlay/gr-overlay'; |
Paladox none | 70efbef | 2021-08-12 05:21:59 +0000 | [diff] [blame] | 94 | import {GrChangeStar} from '../../shared/gr-change-star/gr-change-star'; |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 95 | import {GrThreadList} from '../gr-thread-list/gr-thread-list'; |
Chris Poucet | dd2d010 | 2022-05-13 14:09:39 +0200 | [diff] [blame] | 96 | import {assertIsDefined} from '../../../utils/common-util'; |
Dhruv | 47c21d1 | 2022-06-07 16:37:52 +0200 | [diff] [blame] | 97 | import {DEFAULT_NUM_FILES_SHOWN} from '../gr-file-list/gr-file-list'; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 98 | import {fixture, html} from '@open-wc/testing-helpers'; |
| 99 | import {deepClone} from '../../../utils/deep-util'; |
Dmitrii Filippov | 0028b58 | 2020-03-24 11:58:55 +0100 | [diff] [blame] | 100 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 101 | suite('gr-change-view tests', () => { |
| 102 | let element: GrChangeView; |
| 103 | |
Frank Borden | 6988bdf | 2021-04-07 14:42:00 +0200 | [diff] [blame] | 104 | let navigateToChangeStub: SinonStubbedMember< |
| 105 | typeof GerritNav.navigateToChange |
| 106 | >; |
Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 107 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 108 | const ROBOT_COMMENTS_LIMIT = 10; |
| 109 | |
Tao Zhou | 18738b9 | 2020-05-04 19:44:51 +0200 | [diff] [blame] | 110 | // TODO: should have a mock service to generate VALID fake data |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 111 | const THREADS: CommentThread[] = [ |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 112 | { |
| 113 | comments: [ |
| 114 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 115 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 116 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 117 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 118 | name: 'user', |
| 119 | username: 'user', |
| 120 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 121 | patch_set: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 122 | robot_id: 'rb1' as RobotId, |
| 123 | id: 'ecf0b9fa_fe1a5f62' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 124 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 125 | updated: '2018-02-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 126 | message: 'test', |
| 127 | unresolved: true, |
| 128 | }, |
| 129 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 130 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 131 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 132 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 133 | name: 'user', |
| 134 | username: 'user', |
| 135 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 136 | patch_set: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 137 | id: 'ecf0b9fa_fe1a5f62_1' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 138 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 139 | updated: '2018-02-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 140 | message: 'test', |
| 141 | unresolved: true, |
| 142 | }, |
| 143 | { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 144 | id: '503008e2_0ab203ee' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 145 | path: '/COMMIT_MSG', |
| 146 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 147 | in_reply_to: 'ecf0b9fa_fe1a5f62' as UrlEncodedCommentId, |
| 148 | updated: '2018-02-13 22:48:48.018000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 149 | message: 'draft', |
| 150 | unresolved: false, |
| 151 | __draft: true, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 152 | patch_set: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 153 | }, |
| 154 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 155 | patchNum: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 156 | path: '/COMMIT_MSG', |
| 157 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 158 | rootId: 'ecf0b9fa_fe1a5f62' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 159 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 160 | }, |
| 161 | { |
| 162 | comments: [ |
| 163 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 164 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 165 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 166 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 167 | name: 'user', |
| 168 | username: 'user', |
| 169 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 170 | patch_set: 3 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 171 | id: 'ecf0b9fa_fe5f62' as UrlEncodedCommentId, |
| 172 | robot_id: 'rb2' as RobotId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 173 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 174 | updated: '2018-02-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 175 | message: 'test', |
| 176 | unresolved: true, |
| 177 | }, |
| 178 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 179 | path: 'test.txt', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 180 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 181 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 182 | name: 'user', |
| 183 | username: 'user', |
| 184 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 185 | patch_set: 3 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 186 | id: '09a9fb0a_1484e6cf' as UrlEncodedCommentId, |
| 187 | side: CommentSide.PARENT, |
| 188 | updated: '2018-02-13 22:47:19.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 189 | message: 'Some comment on another patchset.', |
| 190 | unresolved: false, |
| 191 | }, |
| 192 | ], |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 193 | patchNum: 3 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 194 | path: 'test.txt', |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 195 | rootId: '09a9fb0a_1484e6cf' as UrlEncodedCommentId, |
| 196 | commentSide: CommentSide.PARENT, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 197 | }, |
| 198 | { |
| 199 | comments: [ |
| 200 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 201 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 202 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 203 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 204 | name: 'user', |
| 205 | username: 'user', |
| 206 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 207 | patch_set: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 208 | id: '8caddf38_44770ec1' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 209 | line: 4, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 210 | updated: '2018-02-13 22:48:40.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 211 | message: 'Another unresolved comment', |
| 212 | unresolved: true, |
| 213 | }, |
| 214 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 215 | patchNum: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 216 | path: '/COMMIT_MSG', |
| 217 | line: 4, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 218 | rootId: '8caddf38_44770ec1' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 219 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 220 | }, |
| 221 | { |
| 222 | comments: [ |
| 223 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 224 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 225 | author: { |
Ben Rohlfs | 3f27968 | 2022-02-25 12:07:27 +0100 | [diff] [blame] | 226 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 227 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 228 | name: 'user', |
| 229 | username: 'user', |
| 230 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 231 | patch_set: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 232 | id: 'scaddf38_44770ec1' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 233 | line: 4, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 234 | updated: '2018-02-14 22:48:40.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 235 | message: 'Yet another unresolved comment', |
| 236 | unresolved: true, |
| 237 | }, |
| 238 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 239 | patchNum: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 240 | path: '/COMMIT_MSG', |
| 241 | line: 4, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 242 | rootId: 'scaddf38_44770ec1' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 243 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 244 | }, |
| 245 | { |
| 246 | comments: [ |
| 247 | { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 248 | id: 'zcf0b9fa_fe1a5f62' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 249 | path: '/COMMIT_MSG', |
| 250 | line: 6, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 251 | updated: '2018-02-15 22:48:48.018000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 252 | message: 'resolved draft', |
| 253 | unresolved: false, |
| 254 | __draft: true, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 255 | patch_set: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 256 | }, |
| 257 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 258 | patchNum: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 259 | path: '/COMMIT_MSG', |
| 260 | line: 6, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 261 | rootId: 'zcf0b9fa_fe1a5f62' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 262 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 263 | }, |
| 264 | { |
| 265 | comments: [ |
| 266 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 267 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 268 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 269 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 270 | name: 'user', |
| 271 | username: 'user', |
| 272 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 273 | patch_set: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 274 | id: 'rc1' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 275 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 276 | updated: '2019-02-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 277 | message: 'test', |
| 278 | unresolved: true, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 279 | robot_id: 'rc1' as RobotId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 280 | }, |
| 281 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 282 | patchNum: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 283 | path: '/COMMIT_MSG', |
| 284 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 285 | rootId: 'rc1' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 286 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 287 | }, |
| 288 | { |
| 289 | comments: [ |
| 290 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 291 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 292 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 293 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 294 | name: 'user', |
| 295 | username: 'user', |
| 296 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 297 | patch_set: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 298 | id: 'rc2' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 299 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 300 | updated: '2019-03-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 301 | message: 'test', |
| 302 | unresolved: true, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 303 | robot_id: 'rc2' as RobotId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 304 | }, |
| 305 | { |
Dhruv Srivastava | 3dfaf36 | 2020-12-01 21:53:59 +0100 | [diff] [blame] | 306 | path: '/COMMIT_MSG', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 307 | author: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 308 | _account_id: 1000000 as AccountId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 309 | name: 'user', |
| 310 | username: 'user', |
| 311 | }, |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 312 | patch_set: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 313 | id: 'c2_1' as UrlEncodedCommentId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 314 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 315 | updated: '2019-03-08 18:49:18.000000000' as Timestamp, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 316 | message: 'test', |
| 317 | unresolved: true, |
| 318 | }, |
| 319 | ], |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 320 | patchNum: 4 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 321 | path: '/COMMIT_MSG', |
| 322 | line: 5, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 323 | rootId: 'rc2' as UrlEncodedCommentId, |
Dhruv Srivastava | 794db3a | 2020-11-11 11:28:08 +0100 | [diff] [blame] | 324 | commentSide: CommentSide.REVISION, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 325 | }, |
| 326 | ]; |
| 327 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 328 | setup(async () => { |
Dmitrii Filippov | f97fc6e | 2020-04-07 09:59:22 +0200 | [diff] [blame] | 329 | // Since pluginEndpoints are global, must reset state. |
| 330 | _testOnly_resetEndpoints(); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 331 | navigateToChangeStub = sinon.stub(GerritNav, 'navigateToChange'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 332 | |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 333 | stubRestApi('getConfig').returns( |
| 334 | Promise.resolve({ |
| 335 | ...createServerInfo(), |
| 336 | user: { |
| 337 | ...createUserConfig(), |
| 338 | anonymous_coward_name: 'test coward name', |
| 339 | }, |
| 340 | }) |
| 341 | ); |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 342 | stubRestApi('getAccount').returns( |
| 343 | Promise.resolve(createAccountDetailWithId(5)) |
| 344 | ); |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 345 | stubRestApi('getDiffComments').returns(Promise.resolve({})); |
| 346 | stubRestApi('getDiffRobotComments').returns(Promise.resolve({})); |
| 347 | stubRestApi('getDiffDrafts').returns(Promise.resolve({})); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 348 | |
Dhruv Srivastava | 12e2c99 | 2020-09-01 16:40:21 +0200 | [diff] [blame] | 349 | getPluginLoader().loadPlugins([]); |
Chris Poucet | d3f52fd | 2021-11-29 23:16:39 +0100 | [diff] [blame] | 350 | window.Gerrit.install( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 351 | plugin => { |
| 352 | plugin.registerDynamicCustomComponent( |
| 353 | 'change-view-tab-header', |
| 354 | 'gr-checks-change-view-tab-header-view' |
| 355 | ); |
| 356 | plugin.registerDynamicCustomComponent( |
| 357 | 'change-view-tab-content', |
| 358 | 'gr-checks-view' |
| 359 | ); |
| 360 | }, |
| 361 | '0.1', |
Ben Rohlfs | ef1dd59 | 2021-03-09 10:58:29 +0100 | [diff] [blame] | 362 | 'http://some/plugins/url.js' |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 363 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 364 | element = await fixture<GrChangeView>( |
| 365 | html`<gr-change-view></gr-change-view>` |
| 366 | ); |
| 367 | element.params = { |
| 368 | view: GerritView.CHANGE, |
| 369 | changeNum: TEST_NUMERIC_CHANGE_ID, |
| 370 | project: 'gerrit' as RepoName, |
| 371 | }; |
Frank Borden | 610556a | 2022-07-15 15:34:10 +0200 | [diff] [blame^] | 372 | // Do this asynchronously as some tests don't expect the element to have |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 373 | // rendered yet. |
| 374 | element.updateComplete.then(() => { |
| 375 | assertIsDefined(element.actions); |
| 376 | sinon.stub(element.actions, 'reload').returns(Promise.resolve()); |
| 377 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 378 | }); |
| 379 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 380 | teardown(async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 381 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 382 | }); |
| 383 | |
Frank Borden | 610556a | 2022-07-15 15:34:10 +0200 | [diff] [blame^] | 384 | test('render', () => { |
| 385 | expect(element).shadowDom.to.equal(/* HTML */ ` |
| 386 | <div class="container loading">Loading...</div> |
| 387 | <div aria-hidden="false" class="container" hidden="" id="mainContent"> |
| 388 | <section class="changeInfoSection"> |
| 389 | <div class="header"> |
| 390 | <h1 class="assistive-tech-only">Change :</h1> |
| 391 | <div class="headerTitle"> |
| 392 | <div class="changeStatuses"></div> |
| 393 | <gr-change-star id="changeStar"> </gr-change-star> |
| 394 | <a aria-label="Change undefined" class="changeNumber"> </a> |
| 395 | <span class="changeNumberColon"> : </span> |
| 396 | <span class="headerSubject"> </span> |
| 397 | <gr-copy-clipboard |
| 398 | class="changeCopyClipboard" |
| 399 | hideinput="" |
| 400 | text="undefined: undefined | http://localhost:9876undefined" |
| 401 | > |
| 402 | </gr-copy-clipboard> |
| 403 | </div> |
| 404 | <div class="commitActions"> |
| 405 | <gr-change-actions hidden="" id="actions"> </gr-change-actions> |
| 406 | </div> |
| 407 | </div> |
| 408 | <h2 class="assistive-tech-only">Change metadata</h2> |
| 409 | <div class="changeInfo"> |
| 410 | <div class="changeInfo-column changeMetadata hideOnMobileOverlay"> |
| 411 | <gr-change-metadata id="metadata"> </gr-change-metadata> |
| 412 | </div> |
| 413 | <div class="changeInfo-column mainChangeInfo" id="mainChangeInfo"> |
| 414 | <div class="hideOnMobileOverlay" id="commitAndRelated"> |
| 415 | <div class="commitContainer"> |
| 416 | <h3 class="assistive-tech-only">Commit Message</h3> |
| 417 | <div> |
| 418 | <gr-button |
| 419 | aria-disabled="false" |
| 420 | class="reply" |
| 421 | id="replyBtn" |
| 422 | primary="" |
| 423 | role="button" |
| 424 | tabindex="0" |
| 425 | title="Open reply dialog to publish comments and add reviewers (shortcut: a)" |
| 426 | > |
| 427 | Reply |
| 428 | </gr-button> |
| 429 | </div> |
| 430 | <div class="commitMessage" id="commitMessage"> |
| 431 | <gr-editable-content |
| 432 | id="commitMessageEditor" |
| 433 | remove-zero-width-space="" |
| 434 | > |
| 435 | <gr-linked-text pre="" remove-zero-width-space=""> |
| 436 | <span id="output" slot="insert"> </span> |
| 437 | </gr-linked-text> |
| 438 | </gr-editable-content> |
| 439 | </div> |
| 440 | <h3 class="assistive-tech-only"> |
| 441 | Comments and Checks Summary |
| 442 | </h3> |
| 443 | <gr-change-summary> </gr-change-summary> |
| 444 | <gr-endpoint-decorator name="commit-container"> |
| 445 | <gr-endpoint-param name="change"> </gr-endpoint-param> |
| 446 | <gr-endpoint-param name="revision"> </gr-endpoint-param> |
| 447 | </gr-endpoint-decorator> |
| 448 | </div> |
| 449 | <div class="relatedChanges"> |
| 450 | <gr-related-changes-list id="relatedChanges"> |
| 451 | </gr-related-changes-list> |
| 452 | </div> |
| 453 | <div class="emptySpace"></div> |
| 454 | </div> |
| 455 | </div> |
| 456 | </div> |
| 457 | </section> |
| 458 | <h2 class="assistive-tech-only">Files and Comments tabs</h2> |
| 459 | <paper-tabs dir="null" id="primaryTabs" role="tablist" tabindex="0"> |
| 460 | <paper-tab |
| 461 | aria-disabled="false" |
| 462 | aria-selected="true" |
| 463 | class="iron-selected" |
| 464 | data-name="files" |
| 465 | role="tab" |
| 466 | tabindex="0" |
| 467 | > |
| 468 | <span> Files </span> |
| 469 | </paper-tab> |
| 470 | <paper-tab |
| 471 | aria-disabled="false" |
| 472 | aria-selected="false" |
| 473 | class="commentThreads" |
| 474 | data-name="comments" |
| 475 | role="tab" |
| 476 | tabindex="-1" |
| 477 | > |
| 478 | <gr-tooltip-content has-tooltip="" title=""> |
| 479 | <span> Comments </span> |
| 480 | </gr-tooltip-content> |
| 481 | </paper-tab> |
| 482 | <paper-tab |
| 483 | aria-disabled="false" |
| 484 | aria-selected="false" |
| 485 | data-name="change-view-tab-header-url" |
| 486 | role="tab" |
| 487 | tabindex="-1" |
| 488 | > |
| 489 | <gr-endpoint-decorator name="change-view-tab-header-url"> |
| 490 | <gr-endpoint-param name="change"> </gr-endpoint-param> |
| 491 | <gr-endpoint-param name="revision"> </gr-endpoint-param> |
| 492 | </gr-endpoint-decorator> |
| 493 | </paper-tab> |
| 494 | </paper-tabs> |
| 495 | <section class="patchInfo"> |
| 496 | <div> |
| 497 | <gr-file-list-header id="fileListHeader"> </gr-file-list-header> |
| 498 | <gr-file-list class="hideOnMobileOverlay" id="fileList"> |
| 499 | </gr-file-list> |
| 500 | </div> |
| 501 | </section> |
| 502 | <gr-endpoint-decorator name="change-view-integration"> |
| 503 | <gr-endpoint-param name="change"> </gr-endpoint-param> |
| 504 | <gr-endpoint-param name="revision"> </gr-endpoint-param> |
| 505 | </gr-endpoint-decorator> |
| 506 | <paper-tabs dir="null" id="secondaryTabs" role="tablist" tabindex="0"> |
| 507 | <paper-tab |
| 508 | aria-disabled="false" |
| 509 | aria-selected="false" |
| 510 | class="changeLog" |
| 511 | data-name="_changeLog" |
| 512 | role="tab" |
| 513 | tabindex="-1" |
| 514 | > |
| 515 | Change Log |
| 516 | </paper-tab> |
| 517 | </paper-tabs> |
| 518 | <section class="changeLog"> |
| 519 | <h2 class="assistive-tech-only">Change Log</h2> |
| 520 | <gr-messages-list class="hideOnMobileOverlay"> </gr-messages-list> |
| 521 | </section> |
| 522 | </div> |
| 523 | <gr-apply-fix-dialog id="applyFixDialog"> </gr-apply-fix-dialog> |
| 524 | <gr-overlay |
| 525 | aria-hidden="true" |
| 526 | id="downloadOverlay" |
| 527 | style="outline: none; display: none;" |
| 528 | tabindex="-1" |
| 529 | with-backdrop="" |
| 530 | > |
| 531 | <gr-download-dialog id="downloadDialog" role="dialog"> |
| 532 | </gr-download-dialog> |
| 533 | </gr-overlay> |
| 534 | <gr-overlay |
| 535 | aria-hidden="true" |
| 536 | id="includedInOverlay" |
| 537 | style="outline: none; display: none;" |
| 538 | tabindex="-1" |
| 539 | with-backdrop="" |
| 540 | > |
| 541 | <gr-included-in-dialog id="includedInDialog"> </gr-included-in-dialog> |
| 542 | </gr-overlay> |
| 543 | <gr-overlay |
| 544 | aria-hidden="true" |
| 545 | class="scrollable" |
| 546 | id="replyOverlay" |
| 547 | no-cancel-on-esc-key="" |
| 548 | no-cancel-on-outside-click="" |
| 549 | scroll-action="lock" |
| 550 | style="outline: none; display: none;" |
| 551 | tabindex="-1" |
| 552 | with-backdrop="" |
| 553 | > |
| 554 | </gr-overlay> |
| 555 | `); |
| 556 | }); |
| 557 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 558 | test('handleMessageAnchorTap', async () => { |
| 559 | element.changeNum = 1 as NumericChangeId; |
| 560 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 561 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 562 | patchNum: 1 as RevisionPatchSetNum, |
Dhruv Srivastava | 163de6f | 2020-06-04 09:40:28 +0000 | [diff] [blame] | 563 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 564 | element.change = createChangeViewChange(); |
| 565 | await element.updateComplete; |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 566 | const getUrlStub = sinon.stub(GerritNav, 'getUrlForChange'); |
| 567 | const replaceStateStub = sinon.stub(history, 'replaceState'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 568 | element.handleMessageAnchorTap( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 569 | new CustomEvent('message-anchor-tap', {detail: {id: 'a12345'}}) |
| 570 | ); |
Dhruv Srivastava | 163de6f | 2020-06-04 09:40:28 +0000 | [diff] [blame] | 571 | |
Dhruv Srivastava | c9d12bc | 2021-11-12 11:32:40 +0100 | [diff] [blame] | 572 | assert.equal(getUrlStub.lastCall.args[1]!.messageHash, '#message-a12345'); |
Dhruv Srivastava | 163de6f | 2020-06-04 09:40:28 +0000 | [diff] [blame] | 573 | assert.isTrue(replaceStateStub.called); |
| 574 | }); |
| 575 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 576 | test('handleDiffAgainstBase', () => { |
| 577 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 578 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 579 | revisions: createRevisions(10), |
| 580 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 581 | element.patchRange = { |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 582 | patchNum: 3 as RevisionPatchSetNum, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 583 | basePatchNum: 1 as BasePatchSetNum, |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 584 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 585 | element.handleDiffAgainstBase(); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 586 | assert(navigateToChangeStub.called); |
| 587 | const args = navigateToChangeStub.getCall(0).args; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 588 | assert.equal(args[0], element.change); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 589 | assert.equal(args[1]!.patchNum, 3 as RevisionPatchSetNum); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 590 | }); |
| 591 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 592 | test('handleDiffAgainstLatest', () => { |
| 593 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 594 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 595 | revisions: createRevisions(10), |
| 596 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 597 | element.patchRange = { |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 598 | basePatchNum: 1 as BasePatchSetNum, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 599 | patchNum: 3 as RevisionPatchSetNum, |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 600 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 601 | element.handleDiffAgainstLatest(); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 602 | assert(navigateToChangeStub.called); |
| 603 | const args = navigateToChangeStub.getCall(0).args; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 604 | assert.equal(args[0], element.change); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 605 | assert.equal(args[1]!.patchNum, 10 as RevisionPatchSetNum); |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 606 | assert.equal(args[1]!.basePatchNum, 1 as BasePatchSetNum); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 607 | }); |
| 608 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 609 | test('handleDiffBaseAgainstLeft', () => { |
| 610 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 611 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 612 | revisions: createRevisions(10), |
| 613 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 614 | element.patchRange = { |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 615 | patchNum: 3 as RevisionPatchSetNum, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 616 | basePatchNum: 1 as BasePatchSetNum, |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 617 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 618 | element.handleDiffBaseAgainstLeft(); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 619 | assert(navigateToChangeStub.called); |
| 620 | const args = navigateToChangeStub.getCall(0).args; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 621 | assert.equal(args[0], element.change); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 622 | assert.equal(args[1]!.patchNum, 1 as RevisionPatchSetNum); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 623 | }); |
| 624 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 625 | test('handleDiffRightAgainstLatest', () => { |
| 626 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 627 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 628 | revisions: createRevisions(10), |
| 629 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 630 | element.patchRange = { |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 631 | basePatchNum: 1 as BasePatchSetNum, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 632 | patchNum: 3 as RevisionPatchSetNum, |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 633 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 634 | element.handleDiffRightAgainstLatest(); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 635 | assert(navigateToChangeStub.called); |
| 636 | const args = navigateToChangeStub.getCall(0).args; |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 637 | assert.equal(args[1]!.patchNum, 10 as RevisionPatchSetNum); |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 638 | assert.equal(args[1]!.basePatchNum, 3 as BasePatchSetNum); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 639 | }); |
| 640 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 641 | test('handleDiffBaseAgainstLatest', () => { |
| 642 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 643 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 644 | revisions: createRevisions(10), |
| 645 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 646 | element.patchRange = { |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 647 | basePatchNum: 1 as BasePatchSetNum, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 648 | patchNum: 3 as RevisionPatchSetNum, |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 649 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 650 | element.handleDiffBaseAgainstLatest(); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 651 | assert(navigateToChangeStub.called); |
| 652 | const args = navigateToChangeStub.getCall(0).args; |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 653 | assert.equal(args[1]!.patchNum, 10 as RevisionPatchSetNum); |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 654 | assert.isNotOk(args[1]!.basePatchNum); |
Dhruv Srivastava | 4757b35 | 2020-06-12 15:41:42 +0200 | [diff] [blame] | 655 | }); |
| 656 | |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 657 | test('toggle attention set status', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 658 | element.change = { |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 659 | ...createChangeViewChange(), |
| 660 | revisions: createRevisions(10), |
| 661 | }; |
| 662 | const addToAttentionSetStub = stubRestApi('addToAttentionSet').returns( |
| 663 | Promise.resolve(new Response()) |
| 664 | ); |
| 665 | |
| 666 | const removeFromAttentionSetStub = stubRestApi( |
| 667 | 'removeFromAttentionSet' |
| 668 | ).returns(Promise.resolve(new Response())); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 669 | element.patchRange = { |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 670 | basePatchNum: 1 as BasePatchSetNum, |
| 671 | patchNum: 3 as RevisionPatchSetNum, |
| 672 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 673 | await element.updateComplete; |
| 674 | assert.isNotOk(element.change.attention_set); |
| 675 | element.handleToggleAttentionSet(); |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 676 | assert.isTrue(addToAttentionSetStub.called); |
| 677 | assert.isFalse(removeFromAttentionSetStub.called); |
| 678 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 679 | element.handleToggleAttentionSet(); |
Dhruv Srivastava | 8e1e2b2 | 2021-09-30 12:17:55 +0100 | [diff] [blame] | 680 | assert.isTrue(removeFromAttentionSetStub.called); |
| 681 | }); |
| 682 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 683 | suite('plugins adding to file tab', () => { |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 684 | setup(async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 685 | element.changeNum = TEST_NUMERIC_CHANGE_ID; |
| 686 | await element.updateComplete; |
Andrew Bonventre | 547b8ab | 2015-12-01 01:02:00 -0500 | [diff] [blame] | 687 | }); |
| 688 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 689 | test('plugin added tab shows up as a dynamic endpoint', async () => { |
| 690 | await flush(); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 691 | assert( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 692 | element.dynamicTabHeaderEndpoints.includes('change-view-tab-header-url') |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 693 | ); |
| 694 | const primaryTabs = element.shadowRoot!.querySelector('#primaryTabs')!; |
| 695 | const paperTabs = primaryTabs.querySelectorAll<HTMLElement>('paper-tab'); |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 696 | // 4 Tabs are : Files, Comment Threads, Plugin |
| 697 | assert.equal(primaryTabs.querySelectorAll('paper-tab').length, 3); |
| 698 | assert.equal(paperTabs[0].dataset.name, 'files'); |
| 699 | assert.equal(paperTabs[1].dataset.name, 'comments'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 700 | assert.equal(paperTabs[2].dataset.name, 'change-view-tab-header-url'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 701 | }); |
| 702 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 703 | test('setActivePrimaryTab switched tab correctly', async () => { |
| 704 | element.setActivePrimaryTab( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 705 | new CustomEvent('', { |
| 706 | detail: {tab: 'change-view-tab-header-url'}, |
| 707 | }) |
| 708 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 709 | await element.updateComplete; |
| 710 | assert.equal(element.activeTabs[0], 'change-view-tab-header-url'); |
Tao Zhou | 4fd32d5 | 2020-04-06 17:23:10 +0200 | [diff] [blame] | 711 | }); |
| 712 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 713 | test('show-primary-tab switched primary tab correctly', async () => { |
Paladox none | 6b055dc | 2020-06-28 14:53:18 +0000 | [diff] [blame] | 714 | element.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 715 | new CustomEvent('show-primary-tab', { |
| 716 | composed: true, |
| 717 | bubbles: true, |
| 718 | detail: { |
| 719 | tab: 'change-view-tab-header-url', |
| 720 | }, |
| 721 | }) |
| 722 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 723 | await element.updateComplete; |
| 724 | assert.equal(element.activeTabs[0], 'change-view-tab-header-url'); |
Tao Zhou | 4fd32d5 | 2020-04-06 17:23:10 +0200 | [diff] [blame] | 725 | }); |
| 726 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 727 | test('param change should switch primary tab correctly', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 728 | assert.equal(element.activeTabs[0], PrimaryTab.FILES); |
Tao Zhou | 4fd32d5 | 2020-04-06 17:23:10 +0200 | [diff] [blame] | 729 | // view is required |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 730 | element.changeNum = undefined; |
Tao Zhou | 4cd35cb | 2020-07-22 11:28:22 +0200 | [diff] [blame] | 731 | element.params = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 732 | ...createAppElementChangeViewParams(), |
| 733 | ...element.params, |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 734 | tab: PrimaryTab.COMMENT_THREADS, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 735 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 736 | await element.updateComplete; |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 737 | assert.equal(element.activeTabs[0], PrimaryTab.COMMENT_THREADS); |
Tao Zhou | 4fd32d5 | 2020-04-06 17:23:10 +0200 | [diff] [blame] | 738 | }); |
| 739 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 740 | test('invalid param change should not switch primary tab', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 741 | assert.equal(element.activeTabs[0], PrimaryTab.FILES); |
Tao Zhou | 4fd32d5 | 2020-04-06 17:23:10 +0200 | [diff] [blame] | 742 | // view is required |
Tao Zhou | 4cd35cb | 2020-07-22 11:28:22 +0200 | [diff] [blame] | 743 | element.params = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 744 | ...createAppElementChangeViewParams(), |
| 745 | ...element.params, |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 746 | tab: 'random', |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 747 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 748 | await element.updateComplete; |
| 749 | assert.equal(element.activeTabs[0], PrimaryTab.FILES); |
Kasper Nilsson | f074373 | 2016-10-18 13:01:10 -0700 | [diff] [blame] | 750 | }); |
| 751 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 752 | test('switching tab sets _selectedTabPluginEndpoint', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 753 | const paperTabs = element.shadowRoot!.querySelector('#primaryTabs')!; |
| 754 | tap(paperTabs.querySelectorAll('paper-tab')[2]); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 755 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 756 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 757 | element.selectedTabPluginEndpoint, |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 758 | 'change-view-tab-content-url' |
| 759 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 760 | }); |
| 761 | }); |
Paladox none | 7acb7ac | 2017-11-09 18:06:18 +0000 | [diff] [blame] | 762 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 763 | suite('keyboard shortcuts', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 764 | let clock: SinonFakeTimers; |
Dhruv Srivastava | 4caf084 | 2020-09-18 11:50:33 +0200 | [diff] [blame] | 765 | setup(() => { |
| 766 | clock = sinon.useFakeTimers(); |
| 767 | }); |
| 768 | |
| 769 | teardown(() => { |
| 770 | clock.restore(); |
| 771 | sinon.restore(); |
| 772 | }); |
| 773 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 774 | test('t to add topic', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 775 | assertIsDefined(element.metadata); |
| 776 | const editStub = sinon.stub(element.metadata, 'editTopic'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 777 | pressAndReleaseKeyOn(element, 83, null, 't'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 778 | assert(editStub.called); |
| 779 | }); |
| 780 | |
| 781 | test('S should toggle the CL star', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 782 | assertIsDefined(element.changeStar); |
| 783 | const starStub = sinon.stub(element.changeStar, 'toggleStar'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 784 | pressAndReleaseKeyOn(element, 83, null, 's'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 785 | assert(starStub.called); |
| 786 | }); |
| 787 | |
Dhruv Srivastava | 4caf084 | 2020-09-18 11:50:33 +0200 | [diff] [blame] | 788 | test('toggle star is throttled', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 789 | assertIsDefined(element.changeStar); |
| 790 | const starStub = sinon.stub(element.changeStar, 'toggleStar'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 791 | pressAndReleaseKeyOn(element, 83, null, 's'); |
Dhruv Srivastava | 4caf084 | 2020-09-18 11:50:33 +0200 | [diff] [blame] | 792 | assert(starStub.called); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 793 | pressAndReleaseKeyOn(element, 83, null, 's'); |
Dhruv Srivastava | 4caf084 | 2020-09-18 11:50:33 +0200 | [diff] [blame] | 794 | assert.equal(starStub.callCount, 1); |
| 795 | clock.tick(1000); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 796 | pressAndReleaseKeyOn(element, 83, null, 's'); |
Dhruv Srivastava | 4caf084 | 2020-09-18 11:50:33 +0200 | [diff] [blame] | 797 | assert.equal(starStub.callCount, 2); |
| 798 | }); |
| 799 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 800 | test('U should navigate to root if no backPage set', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 801 | const relativeNavStub = sinon.stub(GerritNav, 'navigateToRelativeUrl'); |
| 802 | pressAndReleaseKeyOn(element, 85, null, 'u'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 803 | assert.isTrue(relativeNavStub.called); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 804 | assert.isTrue( |
| 805 | relativeNavStub.lastCall.calledWithExactly(GerritNav.getUrlForRoot()) |
| 806 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 807 | }); |
| 808 | |
| 809 | test('U should navigate to backPage if set', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 810 | const relativeNavStub = sinon.stub(GerritNav, 'navigateToRelativeUrl'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 811 | element.backPage = '/dashboard/self'; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 812 | pressAndReleaseKeyOn(element, 85, null, 'u'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 813 | assert.isTrue(relativeNavStub.called); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 814 | assert.isTrue( |
| 815 | relativeNavStub.lastCall.calledWithExactly('/dashboard/self') |
| 816 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 817 | }); |
| 818 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 819 | test('A fires an error event when not logged in', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 820 | element.userModel.setAccount(undefined); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 821 | const loggedInErrorSpy = sinon.spy(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 822 | element.addEventListener('show-auth-required', loggedInErrorSpy); |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 823 | pressAndReleaseKeyOn(element, 65, null, 'a'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 824 | await element.updateComplete; |
| 825 | assertIsDefined(element.replyOverlay); |
| 826 | assert.isFalse(element.replyOverlay.opened); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 827 | assert.isTrue(loggedInErrorSpy.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 828 | }); |
| 829 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 830 | test('shift A does not open reply overlay', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 831 | pressAndReleaseKeyOn(element, 65, 'shift', 'a'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 832 | await element.updateComplete; |
| 833 | assertIsDefined(element.replyOverlay); |
| 834 | assert.isFalse(element.replyOverlay.opened); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 835 | }); |
| 836 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 837 | test('A toggles overlay when logged in', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 838 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 839 | ...createChangeViewChange(), |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 840 | revisions: createRevisions(1), |
| 841 | messages: createChangeMessages(1), |
| 842 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 843 | element.change.labels = {}; |
| 844 | await element.updateComplete; |
Dmitrii Filippov | 77e5f7f | 2020-07-10 18:39:45 +0200 | [diff] [blame] | 845 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 846 | const openSpy = sinon.spy(element, 'openReplyDialog'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 847 | |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 848 | pressAndReleaseKeyOn(element, 65, null, 'a'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 849 | await element.updateComplete; |
| 850 | assertIsDefined(element.replyOverlay); |
| 851 | assert.isTrue(element.replyOverlay.opened); |
| 852 | element.replyOverlay.close(); |
| 853 | assert.isFalse(element.replyOverlay.opened); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 854 | assert( |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 855 | openSpy.lastCall.calledWithExactly(FocusTarget.ANY), |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 856 | 'openReplyDialog should have been passed ANY' |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 857 | ); |
| 858 | assert.equal(openSpy.callCount, 1); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 859 | }); |
| 860 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 861 | test('fullscreen-overlay-opened hides content', async () => { |
| 862 | element.loggedIn = true; |
| 863 | element.loading = false; |
| 864 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 865 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 866 | labels: {}, |
| 867 | actions: { |
| 868 | abandon: { |
| 869 | enabled: true, |
| 870 | label: 'Abandon', |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 871 | method: HttpMethod.POST, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 872 | title: 'Abandon', |
| 873 | }, |
| 874 | }, |
| 875 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 876 | await element.updateComplete; |
| 877 | const handlerSpy = sinon.spy(element, 'handleHideBackgroundContent'); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 878 | const overlay = queryAndAssert<GrOverlay>(element, '#replyOverlay'); |
| 879 | overlay.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 880 | new CustomEvent('fullscreen-overlay-opened', { |
| 881 | composed: true, |
| 882 | bubbles: true, |
| 883 | }) |
| 884 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 885 | await element.updateComplete; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 886 | assert.isTrue(handlerSpy.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 887 | assertIsDefined(element.mainContent); |
| 888 | assertIsDefined(element.actions); |
| 889 | assert.isTrue(element.mainContent.classList.contains('overlayOpen')); |
| 890 | assert.equal(getComputedStyle(element.actions).display, 'flex'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 891 | }); |
| 892 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 893 | test('fullscreen-overlay-closed shows content', async () => { |
| 894 | element.loggedIn = true; |
| 895 | element.loading = false; |
| 896 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 897 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 898 | labels: {}, |
| 899 | actions: { |
| 900 | abandon: { |
| 901 | enabled: true, |
| 902 | label: 'Abandon', |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 903 | method: HttpMethod.POST, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 904 | title: 'Abandon', |
| 905 | }, |
| 906 | }, |
| 907 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 908 | await element.updateComplete; |
| 909 | const handlerSpy = sinon.spy(element, 'handleShowBackgroundContent'); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 910 | const overlay = queryAndAssert<GrOverlay>(element, '#replyOverlay'); |
| 911 | overlay.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 912 | new CustomEvent('fullscreen-overlay-closed', { |
| 913 | composed: true, |
| 914 | bubbles: true, |
| 915 | }) |
| 916 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 917 | await element.updateComplete; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 918 | assert.isTrue(handlerSpy.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 919 | assertIsDefined(element.mainContent); |
| 920 | assert.isFalse(element.mainContent.classList.contains('overlayOpen')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 921 | }); |
| 922 | |
| 923 | test('expand all messages when expand-diffs fired', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 924 | assertIsDefined(element.fileList); |
| 925 | assertIsDefined(element.fileListHeader); |
| 926 | const handleExpand = sinon.stub(element.fileList, 'expandAllDiffs'); |
| 927 | element.fileListHeader.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 928 | new CustomEvent('expand-diffs', { |
| 929 | composed: true, |
| 930 | bubbles: true, |
| 931 | }) |
| 932 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 933 | assert.isTrue(handleExpand.called); |
| 934 | }); |
| 935 | |
| 936 | test('collapse all messages when collapse-diffs fired', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 937 | assertIsDefined(element.fileList); |
| 938 | assertIsDefined(element.fileListHeader); |
| 939 | const handleCollapse = sinon.stub(element.fileList, 'collapseAllDiffs'); |
| 940 | element.fileListHeader.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 941 | new CustomEvent('collapse-diffs', { |
| 942 | composed: true, |
| 943 | bubbles: true, |
| 944 | }) |
| 945 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 946 | assert.isTrue(handleCollapse.called); |
| 947 | }); |
| 948 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 949 | test('X should expand all messages', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 950 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 951 | const handleExpand = sinon.stub( |
| 952 | element.messagesList!, |
| 953 | 'handleExpandCollapse' |
| 954 | ); |
| 955 | pressAndReleaseKeyOn(element, 88, null, 'x'); |
| 956 | assert(handleExpand.calledWith(true)); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 957 | }); |
| 958 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 959 | test('Z should collapse all messages', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 960 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 961 | const handleExpand = sinon.stub( |
| 962 | element.messagesList!, |
| 963 | 'handleExpandCollapse' |
| 964 | ); |
| 965 | pressAndReleaseKeyOn(element, 90, null, 'z'); |
| 966 | assert(handleExpand.calledWith(false)); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 967 | }); |
| 968 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 969 | test('d should open download overlay', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 970 | assertIsDefined(element.downloadOverlay); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 971 | const stub = sinon |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 972 | .stub(element.downloadOverlay, 'open') |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 973 | .returns(Promise.resolve()); |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 974 | pressAndReleaseKeyOn(element, 68, null, 'd'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 975 | assert.isTrue(stub.called); |
| 976 | }); |
| 977 | |
Chris Poucet | dd2d010 | 2022-05-13 14:09:39 +0200 | [diff] [blame] | 978 | test(', should open diff preferences', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 979 | assertIsDefined(element.fileList); |
| 980 | await element.fileList.updateComplete; |
| 981 | assertIsDefined(element.fileList.diffPreferencesDialog); |
| 982 | const stub = sinon.stub(element.fileList.diffPreferencesDialog, 'open'); |
| 983 | element.loggedIn = false; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 984 | pressAndReleaseKeyOn(element, 188, null, ','); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 985 | assert.isFalse(stub.called); |
| 986 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 987 | element.loggedIn = true; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 988 | pressAndReleaseKeyOn(element, 188, null, ','); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 989 | assert.isTrue(stub.called); |
| 990 | }); |
| 991 | |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 992 | test('m should toggle diff mode', async () => { |
| 993 | const updatePreferencesStub = stubUsers('updatePreferences'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 994 | await element.updateComplete; |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 995 | |
| 996 | const prefs = { |
| 997 | ...createDefaultPreferences(), |
| 998 | diff_view: DiffViewMode.SIDE_BY_SIDE, |
| 999 | }; |
Chris Poucet | efcdb20 | 2021-11-22 23:54:26 +0100 | [diff] [blame] | 1000 | element.userModel.setPreferences(prefs); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1001 | element.handleToggleDiffMode(); |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 1002 | assert.isTrue( |
| 1003 | updatePreferencesStub.calledWith({diff_view: DiffViewMode.UNIFIED}) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1004 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1005 | |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 1006 | const newPrefs = { |
| 1007 | ...createDefaultPreferences(), |
| 1008 | diff_view: DiffViewMode.UNIFIED, |
| 1009 | }; |
Chris Poucet | efcdb20 | 2021-11-22 23:54:26 +0100 | [diff] [blame] | 1010 | element.userModel.setPreferences(newPrefs); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1011 | await element.updateComplete; |
| 1012 | element.handleToggleDiffMode(); |
Dhruv Srivastava | 80d34f4 | 2021-10-18 16:45:02 +0200 | [diff] [blame] | 1013 | assert.isTrue( |
| 1014 | updatePreferencesStub.calledWith({diff_view: DiffViewMode.SIDE_BY_SIDE}) |
| 1015 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1016 | }); |
| 1017 | }); |
| 1018 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1019 | suite('thread list and change log tabs', () => { |
| 1020 | setup(() => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1021 | element.changeNum = TEST_NUMERIC_CHANGE_ID; |
| 1022 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 1023 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1024 | patchNum: 1 as RevisionPatchSetNum, |
Kasper Nilsson | 9c1a3db | 2018-10-19 15:11:07 -0700 | [diff] [blame] | 1025 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1026 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1027 | ...createChangeViewChange(), |
Becky Siegel | 9b03dd2 | 2017-10-26 14:57:32 -0700 | [diff] [blame] | 1028 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1029 | rev2: createRevision(2), |
| 1030 | rev1: createRevision(1), |
| 1031 | rev13: createRevision(13), |
| 1032 | rev3: createRevision(3), |
Kasper Nilsson | f074373 | 2016-10-18 13:01:10 -0700 | [diff] [blame] | 1033 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1034 | current_revision: 'rev3' as CommitId, |
| 1035 | status: ChangeStatus.NEW, |
Kasper Nilsson | f074373 | 2016-10-18 13:01:10 -0700 | [diff] [blame] | 1036 | labels: { |
| 1037 | test: { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1038 | all: [], |
Kasper Nilsson | f074373 | 2016-10-18 13:01:10 -0700 | [diff] [blame] | 1039 | default_value: 0, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1040 | values: {}, |
Kasper Nilsson | f074373 | 2016-10-18 13:01:10 -0700 | [diff] [blame] | 1041 | approved: {}, |
| 1042 | }, |
| 1043 | }, |
| 1044 | }; |
Milutin Kristofic | 8803ea0 | 2020-12-09 23:34:39 +0100 | [diff] [blame] | 1045 | const relatedChanges = element.shadowRoot!.querySelector( |
| 1046 | '#relatedChanges' |
| 1047 | ) as GrRelatedChangesList; |
| 1048 | sinon.stub(relatedChanges, 'reload'); |
Han-Wen Nienhuys | 577ce0a | 2021-08-11 12:11:17 +0200 | [diff] [blame] | 1049 | sinon.stub(element, 'loadData').returns(Promise.resolve()); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1050 | sinon.spy(element, 'paramsChanged'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1051 | element.params = createAppElementChangeViewParams(); |
Kasper Nilsson | 34a5d89 | 2018-04-11 11:10:53 -0700 | [diff] [blame] | 1052 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1053 | }); |
| 1054 | |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 1055 | suite('Comments tab', () => { |
| 1056 | setup(async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1057 | element.changeNum = TEST_NUMERIC_CHANGE_ID; |
| 1058 | element.change = { |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 1059 | ...createChangeViewChange(), |
| 1060 | revisions: { |
| 1061 | rev2: createRevision(2), |
| 1062 | rev1: createRevision(1), |
| 1063 | rev13: createRevision(13), |
| 1064 | rev3: createRevision(3), |
| 1065 | rev4: createRevision(4), |
| 1066 | }, |
| 1067 | current_revision: 'rev4' as CommitId, |
| 1068 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1069 | element.commentThreads = THREADS; |
| 1070 | await element.updateComplete; |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 1071 | const paperTabs = element.shadowRoot!.querySelector('#primaryTabs')!; |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 1072 | const tabs = paperTabs.querySelectorAll('paper-tab'); |
| 1073 | assert.isTrue(tabs.length > 1); |
| 1074 | assert.equal(tabs[1].dataset.name, 'comments'); |
| 1075 | tap(tabs[1]); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1076 | await element.updateComplete; |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 1077 | }); |
| 1078 | |
| 1079 | test('commentId overrides unresolveOnly default', async () => { |
| 1080 | const threadList = queryAndAssert<GrThreadList>( |
| 1081 | element, |
| 1082 | 'gr-thread-list' |
| 1083 | ); |
| 1084 | assert.isTrue(element.unresolvedOnly); |
| 1085 | assert.isNotOk(element.scrollCommentId); |
| 1086 | assert.isTrue(threadList.unresolvedOnly); |
| 1087 | |
| 1088 | element.scrollCommentId = 'abcd' as UrlEncodedCommentId; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1089 | await element.updateComplete; |
Dhruv Srivastava | b213a1f | 2021-11-19 14:45:40 +0100 | [diff] [blame] | 1090 | assert.isFalse(threadList.unresolvedOnly); |
| 1091 | }); |
| 1092 | }); |
| 1093 | |
| 1094 | suite('Findings robot-comment tab', () => { |
Frank Borden | 0a05fa1 | 2021-08-09 13:50:52 +0200 | [diff] [blame] | 1095 | setup(async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1096 | element.changeNum = TEST_NUMERIC_CHANGE_ID; |
| 1097 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1098 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1099 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1100 | rev2: createRevision(2), |
| 1101 | rev1: createRevision(1), |
| 1102 | rev13: createRevision(13), |
| 1103 | rev3: createRevision(3), |
| 1104 | rev4: createRevision(4), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1105 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1106 | current_revision: 'rev4' as CommitId, |
Kasper Nilsson | bbd2867 | 2018-08-01 10:23:23 -0700 | [diff] [blame] | 1107 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1108 | element.commentThreads = THREADS; |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 1109 | element.showFindingsTab = true; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1110 | await element.updateComplete; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1111 | const paperTabs = element.shadowRoot!.querySelector('#primaryTabs')!; |
Ben Rohlfs | 36be36d | 2022-06-24 18:10:45 +0200 | [diff] [blame] | 1112 | const tabs = paperTabs.querySelectorAll('paper-tab'); |
| 1113 | assert.isTrue(tabs.length > 3); |
| 1114 | assert.equal(tabs[3].dataset.name, 'findings'); |
| 1115 | tap(tabs[3]); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1116 | await element.updateComplete; |
Kasper Nilsson | bbd2867 | 2018-08-01 10:23:23 -0700 | [diff] [blame] | 1117 | }); |
Milutin Kristofic | 7a86db1 | 2019-08-07 15:26:13 +0200 | [diff] [blame] | 1118 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1119 | test('robot comments count per patchset', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1120 | const count = element.robotCommentCountPerPatchSet(THREADS); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1121 | const expectedCount = { |
| 1122 | 2: 1, |
| 1123 | 3: 1, |
| 1124 | 4: 2, |
| 1125 | }; |
| 1126 | assert.deepEqual(count, expectedCount); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1127 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1128 | element.computeText(createRevision(2), THREADS), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1129 | 'Patchset 2 (1 finding)' |
| 1130 | ); |
| 1131 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1132 | element.computeText(createRevision(4), THREADS), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1133 | 'Patchset 4 (2 findings)' |
| 1134 | ); |
| 1135 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1136 | element.computeText(createRevision(5), THREADS), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1137 | 'Patchset 5' |
| 1138 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1139 | }); |
Milutin Kristofic | 7a86db1 | 2019-08-07 15:26:13 +0200 | [diff] [blame] | 1140 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1141 | test('only robot comments are rendered', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1142 | assert.equal(element.computeRobotCommentThreads().length, 2); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1143 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1144 | ( |
| 1145 | element.computeRobotCommentThreads()[0] |
| 1146 | .comments[0] as RobotCommentInfo |
| 1147 | ).robot_id, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1148 | 'rc1' |
| 1149 | ); |
| 1150 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1151 | ( |
| 1152 | element.computeRobotCommentThreads()[1] |
| 1153 | .comments[0] as RobotCommentInfo |
| 1154 | ).robot_id, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1155 | 'rc2' |
| 1156 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1157 | }); |
| 1158 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1159 | test('changing patchsets resets robot comments', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1160 | assertIsDefined(element.change); |
| 1161 | const newChange = {...element.change}; |
| 1162 | newChange.current_revision = 'rev3' as CommitId; |
| 1163 | element.change = newChange; |
| 1164 | await element.updateComplete; |
| 1165 | assert.equal(element.computeRobotCommentThreads().length, 1); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1166 | }); |
| 1167 | |
| 1168 | test('Show more button is hidden', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1169 | assert.isNull(element.shadowRoot!.querySelector('.show-robot-comments')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1170 | }); |
| 1171 | |
| 1172 | suite('robot comments show more button', () => { |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1173 | setup(async () => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1174 | const arr = []; |
| 1175 | for (let i = 0; i <= 30; i++) { |
| 1176 | arr.push(...THREADS); |
| 1177 | } |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1178 | element.commentThreads = arr; |
| 1179 | await element.updateComplete; |
Milutin Kristofic | 7a86db1 | 2019-08-07 15:26:13 +0200 | [diff] [blame] | 1180 | }); |
| 1181 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1182 | test('Show more button is rendered', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1183 | assert.isOk(element.shadowRoot!.querySelector('.show-robot-comments')); |
| 1184 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1185 | element.computeRobotCommentThreads().length, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1186 | ROBOT_COMMENTS_LIMIT |
| 1187 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1188 | }); |
| 1189 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1190 | test('Clicking show more button renders all comments', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1191 | tap(element.shadowRoot!.querySelector('.show-robot-comments')!); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1192 | await element.updateComplete; |
| 1193 | assert.equal(element.computeRobotCommentThreads().length, 62); |
Milutin Kristofic | 7a86db1 | 2019-08-07 15:26:13 +0200 | [diff] [blame] | 1194 | }); |
| 1195 | }); |
Andrew Bonventre | 547b8ab | 2015-12-01 01:02:00 -0500 | [diff] [blame] | 1196 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1197 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1198 | test('reply button is not visible when logged out', async () => { |
| 1199 | assertIsDefined(element.replyBtn); |
| 1200 | element.loggedIn = false; |
| 1201 | await element.updateComplete; |
| 1202 | assert.equal(getComputedStyle(element.replyBtn).display, 'none'); |
| 1203 | element.loggedIn = true; |
| 1204 | await element.updateComplete; |
| 1205 | assert.notEqual(getComputedStyle(element.replyBtn).display, 'none'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1206 | }); |
| 1207 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1208 | test('download tap calls handleOpenDownloadDialog', () => { |
| 1209 | assertIsDefined(element.actions); |
| 1210 | const openDialogStub = sinon.stub(element, 'handleOpenDownloadDialog'); |
| 1211 | element.actions.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1212 | new CustomEvent('download-tap', { |
| 1213 | composed: true, |
| 1214 | bubbles: true, |
| 1215 | }) |
| 1216 | ); |
| 1217 | assert.isTrue(openDialogStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1218 | }); |
| 1219 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1220 | test('fetches the server config on attached', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1221 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1222 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1223 | element.serverConfig!.user.anonymous_coward_name, |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1224 | 'test coward name' |
| 1225 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1226 | }); |
| 1227 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1228 | test('changeStatuses', async () => { |
| 1229 | element.loading = false; |
| 1230 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1231 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1232 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1233 | rev2: createRevision(2), |
| 1234 | rev1: createRevision(1), |
| 1235 | rev13: createRevision(13), |
| 1236 | rev3: createRevision(3), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1237 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1238 | current_revision: 'rev3' as CommitId, |
Dmitrii Filippov | 3bf6889 | 2020-07-12 00:19:10 +0200 | [diff] [blame] | 1239 | status: ChangeStatus.MERGED, |
| 1240 | work_in_progress: true, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1241 | labels: { |
| 1242 | test: { |
| 1243 | all: [], |
| 1244 | default_value: 0, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1245 | values: {}, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1246 | approved: {}, |
| 1247 | }, |
| 1248 | }, |
| 1249 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1250 | element.mergeable = true; |
| 1251 | await element.updateComplete; |
Frank Borden | 8860337 | 2021-06-02 16:50:51 +0200 | [diff] [blame] | 1252 | const expectedStatuses = [ChangeStates.MERGED, ChangeStates.WIP]; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1253 | assert.deepEqual(element.changeStatuses, expectedStatuses); |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 1254 | const statusChips = |
| 1255 | element.shadowRoot!.querySelectorAll('gr-change-status'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1256 | assert.equal(statusChips.length, 2); |
| 1257 | }); |
| 1258 | |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1259 | suite('ChangeStatus revert', () => { |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1260 | test('do not show any chip if no revert created', async () => { |
Dhruv Srivastava | 4b634ac | 2021-04-19 12:18:53 +0200 | [diff] [blame] | 1261 | const change = { |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1262 | ...createParsedChange(), |
Dhruv Srivastava | 4b634ac | 2021-04-19 12:18:53 +0200 | [diff] [blame] | 1263 | messages: createChangeMessages(2), |
| 1264 | }; |
| 1265 | const getChangeStub = stubRestApi('getChange'); |
| 1266 | getChangeStub.onFirstCall().returns( |
| 1267 | Promise.resolve({ |
| 1268 | ...createChange(), |
| 1269 | }) |
| 1270 | ); |
| 1271 | getChangeStub.onSecondCall().returns( |
| 1272 | Promise.resolve({ |
| 1273 | ...createChange(), |
| 1274 | }) |
| 1275 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1276 | element.change = change; |
| 1277 | element.mergeable = true; |
| 1278 | element.currentRevisionActions = {submit: {enabled: true}}; |
| 1279 | assert.isTrue(element.isSubmitEnabled()); |
| 1280 | await element.updateComplete; |
| 1281 | element.computeRevertSubmitted(element.change); |
| 1282 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1283 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1284 | element.changeStatuses?.includes(ChangeStates.REVERT_SUBMITTED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1285 | ); |
| 1286 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1287 | element.changeStatuses?.includes(ChangeStates.REVERT_CREATED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1288 | ); |
Dhruv Srivastava | 4b634ac | 2021-04-19 12:18:53 +0200 | [diff] [blame] | 1289 | }); |
| 1290 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1291 | test('do not show any chip if all reverts are abandoned', async () => { |
Dhruv Srivastava | 4a557f2 | 2021-04-21 14:10:09 +0200 | [diff] [blame] | 1292 | const change = { |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1293 | ...createParsedChange(), |
Dhruv Srivastava | 4a557f2 | 2021-04-21 14:10:09 +0200 | [diff] [blame] | 1294 | messages: createChangeMessages(2), |
| 1295 | }; |
| 1296 | change.messages[0].message = 'Created a revert of this change as 12345'; |
| 1297 | change.messages[0].tag = MessageTag.TAG_REVERT as ReviewInputTag; |
| 1298 | |
| 1299 | change.messages[1].message = 'Created a revert of this change as 23456'; |
| 1300 | change.messages[1].tag = MessageTag.TAG_REVERT as ReviewInputTag; |
| 1301 | |
| 1302 | const getChangeStub = stubRestApi('getChange'); |
| 1303 | getChangeStub.onFirstCall().returns( |
| 1304 | Promise.resolve({ |
| 1305 | ...createChange(), |
| 1306 | status: ChangeStatus.ABANDONED, |
| 1307 | }) |
| 1308 | ); |
| 1309 | getChangeStub.onSecondCall().returns( |
| 1310 | Promise.resolve({ |
| 1311 | ...createChange(), |
| 1312 | status: ChangeStatus.ABANDONED, |
| 1313 | }) |
| 1314 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1315 | element.change = change; |
| 1316 | element.mergeable = true; |
| 1317 | element.currentRevisionActions = {submit: {enabled: true}}; |
| 1318 | assert.isTrue(element.isSubmitEnabled()); |
| 1319 | await element.updateComplete; |
| 1320 | element.computeRevertSubmitted(element.change); |
| 1321 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1322 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1323 | element.changeStatuses?.includes(ChangeStates.REVERT_SUBMITTED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1324 | ); |
| 1325 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1326 | element.changeStatuses?.includes(ChangeStates.REVERT_CREATED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1327 | ); |
Dhruv Srivastava | 4a557f2 | 2021-04-21 14:10:09 +0200 | [diff] [blame] | 1328 | }); |
| 1329 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1330 | test('show revert created if no revert is merged', async () => { |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1331 | const change = { |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1332 | ...createParsedChange(), |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1333 | messages: createChangeMessages(2), |
| 1334 | }; |
| 1335 | change.messages[0].message = 'Created a revert of this change as 12345'; |
| 1336 | change.messages[0].tag = MessageTag.TAG_REVERT as ReviewInputTag; |
Dhruv Srivastava | 4a557f2 | 2021-04-21 14:10:09 +0200 | [diff] [blame] | 1337 | |
| 1338 | change.messages[1].message = 'Created a revert of this change as 23456'; |
| 1339 | change.messages[1].tag = MessageTag.TAG_REVERT as ReviewInputTag; |
| 1340 | |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1341 | const getChangeStub = stubRestApi('getChange'); |
| 1342 | getChangeStub.onFirstCall().returns( |
| 1343 | Promise.resolve({ |
| 1344 | ...createChange(), |
| 1345 | }) |
| 1346 | ); |
| 1347 | getChangeStub.onSecondCall().returns( |
| 1348 | Promise.resolve({ |
| 1349 | ...createChange(), |
| 1350 | }) |
| 1351 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1352 | element.change = change; |
| 1353 | element.mergeable = true; |
| 1354 | element.currentRevisionActions = {submit: {enabled: true}}; |
| 1355 | assert.isTrue(element.isSubmitEnabled()); |
| 1356 | await element.updateComplete; |
| 1357 | element.computeRevertSubmitted(element.change); |
| 1358 | // Wait for promises to settle. |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1359 | await flush(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1360 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1361 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1362 | element.changeStatuses?.includes(ChangeStates.REVERT_SUBMITTED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1363 | ); |
| 1364 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1365 | element.changeStatuses?.includes(ChangeStates.REVERT_CREATED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1366 | ); |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1367 | }); |
| 1368 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1369 | test('show revert submitted if revert is merged', async () => { |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1370 | const change = { |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1371 | ...createParsedChange(), |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1372 | messages: createChangeMessages(2), |
| 1373 | }; |
| 1374 | change.messages[0].message = 'Created a revert of this change as 12345'; |
| 1375 | change.messages[0].tag = MessageTag.TAG_REVERT as ReviewInputTag; |
| 1376 | const getChangeStub = stubRestApi('getChange'); |
| 1377 | getChangeStub.onFirstCall().returns( |
| 1378 | Promise.resolve({ |
| 1379 | ...createChange(), |
| 1380 | status: ChangeStatus.MERGED, |
| 1381 | }) |
| 1382 | ); |
| 1383 | getChangeStub.onSecondCall().returns( |
| 1384 | Promise.resolve({ |
| 1385 | ...createChange(), |
| 1386 | }) |
| 1387 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1388 | element.change = change; |
| 1389 | element.mergeable = true; |
| 1390 | element.currentRevisionActions = {submit: {enabled: true}}; |
| 1391 | assert.isTrue(element.isSubmitEnabled()); |
| 1392 | await element.updateComplete; |
| 1393 | element.computeRevertSubmitted(element.change); |
| 1394 | // Wait for promises to settle. |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1395 | await flush(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1396 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1397 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1398 | element.changeStatuses?.includes(ChangeStates.REVERT_CREATED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1399 | ); |
| 1400 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1401 | element.changeStatuses?.includes(ChangeStates.REVERT_SUBMITTED) |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1402 | ); |
Dhruv Srivastava | 69a5173 | 2021-04-14 18:23:00 +0200 | [diff] [blame] | 1403 | }); |
| 1404 | }); |
| 1405 | |
Chris Poucet | dd2d010 | 2022-05-13 14:09:39 +0200 | [diff] [blame] | 1406 | test('diff preferences open when open-diff-prefs is fired', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1407 | await element.updateComplete; |
| 1408 | assertIsDefined(element.fileList); |
| 1409 | assertIsDefined(element.fileListHeader); |
| 1410 | await element.fileList.updateComplete; |
| 1411 | const overlayOpenStub = sinon.stub(element.fileList, 'openDiffPrefs'); |
| 1412 | element.fileListHeader.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1413 | new CustomEvent('open-diff-prefs', { |
| 1414 | composed: true, |
| 1415 | bubbles: true, |
| 1416 | }) |
| 1417 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1418 | assert.isTrue(overlayOpenStub.called); |
| 1419 | }); |
| 1420 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1421 | test('prepareCommitMsgForLinkify', () => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1422 | let commitMessage = 'R=test@google.com'; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1423 | let result = element.prepareCommitMsgForLinkify(commitMessage); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1424 | assert.equal(result, 'R=\u200Btest@google.com'); |
| 1425 | |
| 1426 | commitMessage = 'R=test@google.com\nR=test@google.com'; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1427 | result = element.prepareCommitMsgForLinkify(commitMessage); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1428 | assert.equal(result, 'R=\u200Btest@google.com\nR=\u200Btest@google.com'); |
| 1429 | |
| 1430 | commitMessage = 'CC=test@google.com'; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1431 | result = element.prepareCommitMsgForLinkify(commitMessage); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1432 | assert.equal(result, 'CC=\u200Btest@google.com'); |
David Ostrovsky | a2401c1 | 2020-05-03 19:29:26 +0200 | [diff] [blame] | 1433 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1434 | |
| 1435 | test('_isSubmitEnabled', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1436 | assert.isFalse(element.isSubmitEnabled()); |
| 1437 | element.currentRevisionActions = {submit: {}}; |
| 1438 | assert.isFalse(element.isSubmitEnabled()); |
| 1439 | element.currentRevisionActions = {submit: {enabled: true}}; |
| 1440 | assert.isTrue(element.isSubmitEnabled()); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1441 | }); |
| 1442 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1443 | test('reload is called when an approved label is removed', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1444 | const vote: ApprovalInfo = { |
| 1445 | ...createApproval(), |
| 1446 | _account_id: 1 as AccountId, |
| 1447 | name: 'bojack', |
| 1448 | value: 1, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1449 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1450 | element.changeNum = TEST_NUMERIC_CHANGE_ID; |
| 1451 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 1452 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1453 | patchNum: 1 as RevisionPatchSetNum, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1454 | }; |
| 1455 | const change = { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1456 | ...createParsedChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1457 | owner: createAccountWithIdNameAndEmail(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1458 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1459 | rev2: createRevision(2), |
| 1460 | rev1: createRevision(1), |
| 1461 | rev13: createRevision(13), |
| 1462 | rev3: createRevision(3), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1463 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1464 | current_revision: 'rev3' as CommitId, |
| 1465 | status: ChangeStatus.NEW, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1466 | labels: { |
| 1467 | test: { |
| 1468 | all: [vote], |
| 1469 | default_value: 0, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1470 | values: {}, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1471 | approved: {}, |
| 1472 | }, |
| 1473 | }, |
| 1474 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1475 | element.change = change; |
| 1476 | await element.updateComplete; |
Ben Rohlfs | 66367b6 | 2021-04-30 10:06:32 +0200 | [diff] [blame] | 1477 | const reloadStub = sinon.stub(element, 'loadData'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1478 | const newChange = {...element.change}; |
| 1479 | (newChange.labels!.test! as DetailedLabelInfo).all = []; |
| 1480 | element.change = deepClone(newChange); |
| 1481 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1482 | assert.isFalse(reloadStub.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1483 | |
| 1484 | assert.isDefined(element.change); |
| 1485 | const testLabels: DetailedLabelInfo & QuickLabelInfo = |
| 1486 | newChange.labels!.test; |
| 1487 | assertIsDefined(testLabels); |
| 1488 | testLabels.all!.push(vote); |
| 1489 | testLabels.all!.push(vote); |
| 1490 | testLabels.approved = vote; |
| 1491 | element.change = deepClone(newChange); |
| 1492 | await element.updateComplete; |
| 1493 | assert.isFalse(reloadStub.called); |
| 1494 | |
| 1495 | assert.isDefined(element.change); |
| 1496 | (newChange.labels!.test! as DetailedLabelInfo).all = []; |
| 1497 | element.change = deepClone(newChange); |
| 1498 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1499 | assert.isTrue(reloadStub.called); |
| 1500 | assert.isTrue(reloadStub.calledOnce); |
| 1501 | }); |
| 1502 | |
| 1503 | test('reply button has updated count when there are drafts', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1504 | const getLabel = (canReview: boolean) => { |
| 1505 | element.change!.actions!.ready = {enabled: canReview}; |
| 1506 | return element.computeReplyButtonLabel(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1507 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1508 | element.change = createParsedChange(); |
| 1509 | element.change.actions = {}; |
| 1510 | element.diffDrafts = undefined; |
| 1511 | assert.equal(getLabel(false), 'Reply'); |
| 1512 | assert.equal(getLabel(true), 'Reply'); |
| 1513 | |
| 1514 | element.diffDrafts = {}; |
| 1515 | assert.equal(getLabel(false), 'Reply'); |
| 1516 | assert.equal(getLabel(true), 'Start Review'); |
| 1517 | |
| 1518 | element.diffDrafts = { |
| 1519 | 'file1.txt': [createDraft()], |
| 1520 | 'file2.txt': [createDraft(), createDraft()], |
| 1521 | }; |
| 1522 | assert.equal(getLabel(false), 'Reply (3)'); |
| 1523 | assert.equal(getLabel(true), 'Start Review (3)'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1524 | }); |
| 1525 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1526 | test('change num change', async () => { |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 1527 | const change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1528 | ...createChangeViewChange(), |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 1529 | labels: {}, |
| 1530 | } as ParsedChangeInfo; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1531 | element.changeNum = undefined; |
| 1532 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 1533 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1534 | patchNum: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1535 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1536 | element.change = change; |
| 1537 | assertIsDefined(element.fileList); |
| 1538 | assert.equal(element.fileList.numFilesShown, DEFAULT_NUM_FILES_SHOWN); |
| 1539 | element.fileList.numFilesShown = 150; |
Dhruv | 65b9726 | 2022-06-13 15:05:05 +0200 | [diff] [blame] | 1540 | element.fileList.selectedIndex = 15; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1541 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1542 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1543 | element.changeNum = 2 as NumericChangeId; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1544 | element.params = { |
| 1545 | ...createAppElementChangeViewParams(), |
| 1546 | changeNum: 2 as NumericChangeId, |
| 1547 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1548 | await element.updateComplete; |
| 1549 | assert.equal(element.fileList.numFilesShown, DEFAULT_NUM_FILES_SHOWN); |
Dhruv | 65b9726 | 2022-06-13 15:05:05 +0200 | [diff] [blame] | 1550 | assert.equal(element.fileList.selectedIndex, 0); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1551 | }); |
| 1552 | |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1553 | test('don’t reload entire page when patchRange changes', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1554 | const reloadStub = sinon |
Ben Rohlfs | 66367b6 | 2021-04-30 10:06:32 +0200 | [diff] [blame] | 1555 | .stub(element, 'loadData') |
Han-Wen Nienhuys | 577ce0a | 2021-08-11 12:11:17 +0200 | [diff] [blame] | 1556 | .callsFake(() => Promise.resolve()); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1557 | const reloadPatchDependentStub = sinon |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1558 | .stub(element, 'reloadPatchNumDependentResources') |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1559 | .callsFake(() => Promise.resolve([undefined, undefined, undefined])); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1560 | assertIsDefined(element.fileList); |
| 1561 | await element.fileList.updateComplete; |
| 1562 | const collapseStub = sinon.stub(element.fileList, 'collapseAllDiffs'); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1563 | const value: AppElementChangeViewParams = { |
| 1564 | ...createAppElementChangeViewParams(), |
| 1565 | view: GerritView.CHANGE, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1566 | patchNum: 1 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1567 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1568 | element.changeNum = undefined; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1569 | element.params = value; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1570 | await element.updateComplete; |
Dhruv Srivastava | 105fa21 | 2021-09-03 12:16:30 +0000 | [diff] [blame] | 1571 | assert.isTrue(reloadStub.calledOnce); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1572 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1573 | element.initialLoadComplete = true; |
Dhruv | 65b9726 | 2022-06-13 15:05:05 +0200 | [diff] [blame] | 1574 | element.fileList.selectedIndex = 15; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1575 | element.change = { |
Ben Rohlfs | d03b9b1 | 2021-05-12 12:04:50 +0200 | [diff] [blame] | 1576 | ...createChangeViewChange(), |
| 1577 | revisions: { |
| 1578 | rev1: createRevision(1), |
| 1579 | rev2: createRevision(2), |
| 1580 | }, |
| 1581 | }; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1582 | |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 1583 | value.basePatchNum = 1 as BasePatchSetNum; |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1584 | value.patchNum = 2 as RevisionPatchSetNum; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1585 | element.params = {...value}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1586 | await element.updateComplete; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1587 | await flush(); |
Dhruv | 65b9726 | 2022-06-13 15:05:05 +0200 | [diff] [blame] | 1588 | assert.equal(element.fileList.selectedIndex, 0); |
Dhruv Srivastava | 105fa21 | 2021-09-03 12:16:30 +0000 | [diff] [blame] | 1589 | assert.isFalse(reloadStub.calledTwice); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1590 | assert.isTrue(reloadPatchDependentStub.calledOnce); |
Dhruv Srivastava | 105fa21 | 2021-09-03 12:16:30 +0000 | [diff] [blame] | 1591 | assert.isTrue(collapseStub.calledTwice); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1592 | }); |
| 1593 | |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1594 | test('reload ported comments when patchNum changes', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1595 | assertIsDefined(element.fileList); |
Han-Wen Nienhuys | 577ce0a | 2021-08-11 12:11:17 +0200 | [diff] [blame] | 1596 | sinon.stub(element, 'loadData').callsFake(() => Promise.resolve()); |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 1597 | sinon.stub(element, 'loadAndSetCommitInfo'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1598 | await element.updateComplete; |
Chris Poucet | 6c6b54f | 2021-12-09 02:53:13 +0100 | [diff] [blame] | 1599 | const reloadPortedCommentsStub = sinon.stub( |
| 1600 | element.getCommentsModel(), |
| 1601 | 'reloadPortedComments' |
| 1602 | ); |
| 1603 | const reloadPortedDraftsStub = sinon.stub( |
| 1604 | element.getCommentsModel(), |
| 1605 | 'reloadPortedDrafts' |
| 1606 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1607 | sinon.stub(element.fileList, 'collapseAllDiffs'); |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1608 | |
| 1609 | const value: AppElementChangeViewParams = { |
| 1610 | ...createAppElementChangeViewParams(), |
| 1611 | view: GerritView.CHANGE, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1612 | patchNum: 1 as RevisionPatchSetNum, |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1613 | }; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1614 | element.params = value; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1615 | await element.updateComplete; |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1616 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1617 | element.initialLoadComplete = true; |
| 1618 | element.change = { |
Ben Rohlfs | d03b9b1 | 2021-05-12 12:04:50 +0200 | [diff] [blame] | 1619 | ...createChangeViewChange(), |
| 1620 | revisions: { |
| 1621 | rev1: createRevision(1), |
| 1622 | rev2: createRevision(2), |
| 1623 | }, |
| 1624 | }; |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1625 | |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 1626 | value.basePatchNum = 1 as BasePatchSetNum; |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1627 | value.patchNum = 2 as RevisionPatchSetNum; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1628 | element.params = {...value}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1629 | await element.updateComplete; |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1630 | assert.isTrue(reloadPortedCommentsStub.calledOnce); |
Ben Rohlfs | 718cec0 | 2021-11-03 09:04:15 +0100 | [diff] [blame] | 1631 | assert.isTrue(reloadPortedDraftsStub.calledOnce); |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 1632 | }); |
| 1633 | |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 1634 | test('do not reload entire page when patchRange doesnt change', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1635 | assertIsDefined(element.fileList); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1636 | const reloadStub = sinon |
Ben Rohlfs | 66367b6 | 2021-04-30 10:06:32 +0200 | [diff] [blame] | 1637 | .stub(element, 'loadData') |
Han-Wen Nienhuys | 577ce0a | 2021-08-11 12:11:17 +0200 | [diff] [blame] | 1638 | .callsFake(() => Promise.resolve()); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1639 | const collapseStub = sinon.stub(element.fileList, 'collapseAllDiffs'); |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 1640 | const value: AppElementChangeViewParams = |
| 1641 | createAppElementChangeViewParams(); |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1642 | element.params = value; |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 1643 | // change already loaded |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1644 | assert.isOk(element.changeNum); |
| 1645 | await element.updateComplete; |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 1646 | assert.isFalse(reloadStub.calledOnce); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1647 | element.initialLoadComplete = true; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1648 | element.params = {...value}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1649 | await element.updateComplete; |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 1650 | assert.isFalse(reloadStub.calledTwice); |
| 1651 | assert.isFalse(collapseStub.calledTwice); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1652 | }); |
| 1653 | |
Ben Rohlfs | c04f61a | 2021-12-02 14:36:54 +0100 | [diff] [blame] | 1654 | test('forceReload updates the change', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1655 | assertIsDefined(element.fileList); |
Ben Rohlfs | c04f61a | 2021-12-02 14:36:54 +0100 | [diff] [blame] | 1656 | const getChangeStub = stubRestApi('getChangeDetail').returns( |
| 1657 | Promise.resolve(createParsedChange()) |
| 1658 | ); |
| 1659 | const loadDataStub = sinon |
| 1660 | .stub(element, 'loadData') |
| 1661 | .callsFake(() => Promise.resolve()); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1662 | const collapseStub = sinon.stub(element.fileList, 'collapseAllDiffs'); |
Ben Rohlfs | c04f61a | 2021-12-02 14:36:54 +0100 | [diff] [blame] | 1663 | element.params = {...createAppElementChangeViewParams(), forceReload: true}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1664 | await element.updateComplete; |
Ben Rohlfs | c04f61a | 2021-12-02 14:36:54 +0100 | [diff] [blame] | 1665 | assert.isTrue(getChangeStub.called); |
| 1666 | assert.isTrue(loadDataStub.called); |
| 1667 | assert.isTrue(collapseStub.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1668 | // patchNum is set by changeChanged, so this verifies that change was set. |
| 1669 | assert.isOk(element.patchRange?.patchNum); |
Ben Rohlfs | c04f61a | 2021-12-02 14:36:54 +0100 | [diff] [blame] | 1670 | }); |
| 1671 | |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1672 | test('do not handle new change numbers', async () => { |
| 1673 | const recreateSpy = sinon.spy(); |
| 1674 | element.addEventListener('recreate-change-view', recreateSpy); |
| 1675 | |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 1676 | const value: AppElementChangeViewParams = |
| 1677 | createAppElementChangeViewParams(); |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1678 | element.params = value; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1679 | await element.updateComplete; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1680 | assert.isFalse(recreateSpy.calledOnce); |
| 1681 | |
| 1682 | value.changeNum = 555111333 as NumericChangeId; |
| 1683 | element.params = {...value}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1684 | await element.updateComplete; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 1685 | assert.isTrue(recreateSpy.calledOnce); |
| 1686 | }); |
| 1687 | |
Ben Rohlfs | bdf135d | 2021-12-20 15:09:02 +0100 | [diff] [blame] | 1688 | test('related changes are updated when loadData is called', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1689 | await element.updateComplete; |
Milutin Kristofic | 8803ea0 | 2020-12-09 23:34:39 +0100 | [diff] [blame] | 1690 | const relatedChanges = element.shadowRoot!.querySelector( |
| 1691 | '#relatedChanges' |
| 1692 | ) as GrRelatedChangesList; |
Ben Rohlfs | bdf135d | 2021-12-20 15:09:02 +0100 | [diff] [blame] | 1693 | const reloadStub = sinon.stub(relatedChanges, 'reload'); |
| 1694 | stubRestApi('getMergeable').returns( |
| 1695 | Promise.resolve({...createMergeable(), mergeable: true}) |
| 1696 | ); |
| 1697 | |
| 1698 | element.params = createAppElementChangeViewParams(); |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 1699 | element.getChangeModel().setState({ |
Ben Rohlfs | bdf135d | 2021-12-20 15:09:02 +0100 | [diff] [blame] | 1700 | loadingStatus: LoadingStatus.LOADED, |
| 1701 | change: { |
| 1702 | ...createChangeViewChange(), |
| 1703 | }, |
| 1704 | }); |
| 1705 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1706 | await element.loadData(true); |
| 1707 | assert.isFalse(navigateToChangeStub.called); |
Ben Rohlfs | bdf135d | 2021-12-20 15:09:02 +0100 | [diff] [blame] | 1708 | assert.isTrue(reloadStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1709 | }); |
| 1710 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1711 | test('computeCopyTextForTitle', () => { |
| 1712 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1713 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1714 | _number: 123 as NumericChangeId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1715 | subject: 'test subject', |
| 1716 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1717 | rev1: createRevision(1), |
| 1718 | rev3: createRevision(3), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1719 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1720 | current_revision: 'rev3' as CommitId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1721 | }; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1722 | sinon.stub(GerritNav, 'getUrlForChange').returns('/change/123'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1723 | assert.equal( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1724 | element.computeCopyTextForTitle(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1725 | `123: test subject | http://${location.host}/change/123` |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1726 | ); |
| 1727 | }); |
| 1728 | |
| 1729 | test('get latest revision', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1730 | let change: ChangeInfo = { |
| 1731 | ...createChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1732 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1733 | rev1: createRevision(1), |
| 1734 | rev3: createRevision(3), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1735 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1736 | current_revision: 'rev3' as CommitId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1737 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1738 | assert.equal(element.getLatestRevisionSHA(change), 'rev3'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1739 | change = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1740 | ...createChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1741 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1742 | rev1: createRevision(1), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1743 | }, |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1744 | current_revision: undefined, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1745 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1746 | assert.equal(element.getLatestRevisionSHA(change), 'rev1'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1747 | }); |
| 1748 | |
| 1749 | test('show commit message edit button', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1750 | const change = createParsedChange(); |
| 1751 | const mergedChanged: ParsedChangeInfo = { |
| 1752 | ...createParsedChange(), |
Dmitrii Filippov | 4e4522e | 2020-05-06 12:50:49 +0200 | [diff] [blame] | 1753 | status: ChangeStatus.MERGED, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1754 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1755 | assert.isTrue(element.computeHideEditCommitMessage(false, false, change)); |
| 1756 | assert.isTrue(element.computeHideEditCommitMessage(true, true, change)); |
| 1757 | assert.isTrue(element.computeHideEditCommitMessage(false, true, change)); |
| 1758 | assert.isFalse(element.computeHideEditCommitMessage(true, false, change)); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1759 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1760 | element.computeHideEditCommitMessage(true, false, mergedChanged) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1761 | ); |
| 1762 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1763 | element.computeHideEditCommitMessage(true, false, change, true) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1764 | ); |
| 1765 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1766 | element.computeHideEditCommitMessage(true, false, change, false) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1767 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1768 | }); |
| 1769 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1770 | test('handleCommitMessageSave trims trailing whitespace', async () => { |
| 1771 | element.change = createChangeViewChange(); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1772 | // Response code is 500, because we want to avoid window reloading |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 1773 | const putStub = stubRestApi('putChangeCommitMessage').returns( |
| 1774 | Promise.resolve(new Response(null, {status: 500})) |
| 1775 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1776 | await element.updateComplete; |
Frank Borden | 6988bdf | 2021-04-07 14:42:00 +0200 | [diff] [blame] | 1777 | const mockEvent = (content: string) => |
| 1778 | new CustomEvent('', {detail: {content}}); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1779 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1780 | assertIsDefined(element.commitMessageEditor); |
| 1781 | element.handleCommitMessageSave(mockEvent('test \n test ')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1782 | assert.equal(putStub.lastCall.args[1], 'test\n test'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1783 | element.commitMessageEditor.disabled = false; |
| 1784 | element.handleCommitMessageSave(mockEvent(' test\ntest')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1785 | assert.equal(putStub.lastCall.args[1], ' test\ntest'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1786 | element.commitMessageEditor.disabled = false; |
| 1787 | element.handleCommitMessageSave(mockEvent('\n\n\n\n\n\n\n\n')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1788 | assert.equal(putStub.lastCall.args[1], '\n\n\n\n\n\n\n\n'); |
| 1789 | }); |
| 1790 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1791 | test('topic is coalesced to null', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1792 | sinon.stub(element, 'changeChanged'); |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 1793 | element.getChangeModel().setState({ |
Ben Rohlfs | 61bafc2 | 2021-11-29 10:40:08 +0100 | [diff] [blame] | 1794 | loadingStatus: LoadingStatus.LOADED, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1795 | change: { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1796 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1797 | labels: {}, |
| 1798 | current_revision: 'foo' as CommitId, |
| 1799 | revisions: {foo: createRevision()}, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1800 | }, |
| 1801 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1802 | |
Dhruv Srivastava | 2112981 | 2021-12-02 15:48:03 +0100 | [diff] [blame] | 1803 | await element.performPostChangeLoadTasks(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1804 | assert.isNull(element.change!.topic); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1805 | }); |
| 1806 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1807 | test('commit sha is populated from getChangeDetail', async () => { |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 1808 | element.getChangeModel().setState({ |
Ben Rohlfs | 61bafc2 | 2021-11-29 10:40:08 +0100 | [diff] [blame] | 1809 | loadingStatus: LoadingStatus.LOADED, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1810 | change: { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1811 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1812 | labels: {}, |
| 1813 | current_revision: 'foo' as CommitId, |
| 1814 | revisions: {foo: createRevision()}, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1815 | }, |
| 1816 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1817 | |
Dhruv Srivastava | 2112981 | 2021-12-02 15:48:03 +0100 | [diff] [blame] | 1818 | await element.performPostChangeLoadTasks(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1819 | assert.equal('foo', element.commitInfo!.commit); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1820 | }); |
| 1821 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1822 | test('getBasePatchNum', async () => { |
| 1823 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1824 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1825 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1826 | '98da160735fb81604b4c40e93c368f380539dd0e': createRevision(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1827 | }, |
| 1828 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1829 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 1830 | basePatchNum: PARENT, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1831 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1832 | await element.updateComplete; |
| 1833 | assert.equal(element.getBasePatchNum(), PARENT); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1834 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1835 | element.prefs = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1836 | ...createPreferences(), |
| 1837 | default_base_for_merges: DefaultBase.FIRST_PARENT, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1838 | }; |
| 1839 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1840 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1841 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1842 | revisions: { |
| 1843 | '98da160735fb81604b4c40e93c368f380539dd0e': { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1844 | ...createRevision(1), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1845 | commit: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1846 | ...createCommit(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1847 | parents: [ |
| 1848 | { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1849 | commit: '6e12bdf1176eb4ab24d8491ba3b6d0704409cde8' as CommitId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1850 | subject: 'test', |
| 1851 | }, |
| 1852 | { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1853 | commit: '22f7db4754b5d9816fc581f3d9a6c0ef8429c841' as CommitId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1854 | subject: 'test3', |
| 1855 | }, |
| 1856 | ], |
| 1857 | }, |
| 1858 | }, |
| 1859 | }, |
| 1860 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1861 | await element.updateComplete; |
| 1862 | assert.equal(element.getBasePatchNum(), -1 as BasePatchSetNum); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1863 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1864 | element.patchRange.basePatchNum = PARENT; |
| 1865 | element.patchRange.patchNum = 1 as RevisionPatchSetNum; |
| 1866 | await element.updateComplete; |
| 1867 | assert.equal(element.getBasePatchNum(), PARENT); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1868 | }); |
| 1869 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1870 | test('openReplyDialog called with `ANY` when coming from tap event', async () => { |
| 1871 | await element.updateComplete; |
| 1872 | assertIsDefined(element.replyBtn); |
| 1873 | const openStub = sinon.stub(element, 'openReplyDialog'); |
| 1874 | tap(element.replyBtn); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1875 | assert( |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 1876 | openStub.lastCall.calledWithExactly(FocusTarget.ANY), |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1877 | 'openReplyDialog should have been passed ANY' |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1878 | ); |
| 1879 | assert.equal(openStub.callCount, 1); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1880 | }); |
| 1881 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1882 | test( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1883 | 'openReplyDialog called with `BODY` when coming from message reply' + |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1884 | 'event', |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1885 | async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1886 | await element.updateComplete; |
| 1887 | const openStub = sinon.stub(element, 'openReplyDialog'); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1888 | element.messagesList!.dispatchEvent( |
| 1889 | new CustomEvent('reply', { |
| 1890 | detail: {message: {message: 'text'}}, |
| 1891 | composed: true, |
| 1892 | bubbles: true, |
| 1893 | }) |
| 1894 | ); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 1895 | assert.isTrue(openStub.calledOnce); |
| 1896 | assert.equal(openStub.lastCall.args[0], FocusTarget.BODY); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1897 | } |
| 1898 | ); |
| 1899 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1900 | test('reply dialog focus can be controlled', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1901 | const openStub = sinon.stub(element, 'openReplyDialog'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1902 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1903 | const e = new CustomEvent('show-reply-dialog', { |
| 1904 | detail: {value: {ccsOnly: false}}, |
| 1905 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1906 | element.handleShowReplyDialog(e); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1907 | assert( |
| 1908 | openStub.lastCall.calledWithExactly(FocusTarget.REVIEWERS), |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1909 | 'openReplyDialog should have been passed REVIEWERS' |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1910 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1911 | assert.equal(openStub.callCount, 1); |
| 1912 | |
| 1913 | e.detail.value = {ccsOnly: true}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1914 | element.handleShowReplyDialog(e); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1915 | assert( |
| 1916 | openStub.lastCall.calledWithExactly(FocusTarget.CCS), |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1917 | 'openReplyDialog should have been passed CCS' |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1918 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1919 | assert.equal(openStub.callCount, 2); |
| 1920 | }); |
| 1921 | |
| 1922 | test('getUrlParameter functionality', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1923 | const locationStub = sinon.stub(element, 'getLocationSearch'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1924 | locationStub.returns('?test'); |
| 1925 | assert.equal(element._getUrlParameter('test'), 'test'); |
| 1926 | locationStub.returns('?test2=12&test=3'); |
| 1927 | assert.equal(element._getUrlParameter('test'), 'test'); |
| 1928 | locationStub.returns(''); |
| 1929 | assert.isNull(element._getUrlParameter('test')); |
| 1930 | locationStub.returns('?'); |
| 1931 | assert.isNull(element._getUrlParameter('test')); |
| 1932 | locationStub.returns('?test2'); |
| 1933 | assert.isNull(element._getUrlParameter('test')); |
| 1934 | }); |
| 1935 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1936 | test('revert dialog opened with revert param', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1937 | const awaitPluginsLoadedStub = sinon |
| 1938 | .stub(getPluginLoader(), 'awaitPluginsLoaded') |
| 1939 | .callsFake(() => Promise.resolve()); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1940 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1941 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 1942 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 1943 | patchNum: 2 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1944 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1945 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1946 | ...createChangeViewChange(), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1947 | revisions: { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1948 | rev1: createRevision(1), |
| 1949 | rev2: createRevision(2), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1950 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1951 | current_revision: 'rev1' as CommitId, |
Dmitrii Filippov | 4e4522e | 2020-05-06 12:50:49 +0200 | [diff] [blame] | 1952 | status: ChangeStatus.MERGED, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1953 | labels: {}, |
| 1954 | actions: {}, |
| 1955 | }; |
| 1956 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1957 | sinon.stub(element, '_getUrlParameter').callsFake(param => { |
| 1958 | assert.equal(param, 'revert'); |
| 1959 | return param; |
| 1960 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1961 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1962 | const promise = mockPromise(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1963 | assertIsDefined(element.actions); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1964 | sinon |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1965 | .stub(element.actions, 'showRevertDialog') |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1966 | .callsFake(() => promise.resolve()); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1967 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1968 | element.maybeShowRevertDialog(); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1969 | assert.isTrue(awaitPluginsLoadedStub.called); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1970 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1971 | }); |
| 1972 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1973 | suite('reply dialog tests', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1974 | setup(async () => { |
| 1975 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 1976 | ...createChangeViewChange(), |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1977 | // element has latest info |
| 1978 | revisions: {rev1: createRevision()}, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 1979 | messages: createChangeMessages(1), |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 1980 | current_revision: 'rev1' as CommitId, |
| 1981 | labels: {}, |
Dmitrii Filippov | 0695d40 | 2020-10-22 16:57:57 +0200 | [diff] [blame] | 1982 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1983 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1984 | }); |
| 1985 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1986 | test('show reply dialog on open-reply-dialog event', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1987 | const openReplyDialogStub = sinon.stub(element, 'openReplyDialog'); |
Tao Zhou | da7463c | 2020-07-14 11:17:20 +0200 | [diff] [blame] | 1988 | element.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 1989 | new CustomEvent('open-reply-dialog', { |
| 1990 | composed: true, |
| 1991 | bubbles: true, |
| 1992 | detail: {}, |
| 1993 | }) |
| 1994 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 1995 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 1996 | assert.isTrue(openReplyDialogStub.calledOnce); |
Tao Zhou | da7463c | 2020-07-14 11:17:20 +0200 | [diff] [blame] | 1997 | }); |
| 1998 | |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 1999 | test('reply from comment adds quote text', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2000 | const e = new CustomEvent('', { |
| 2001 | detail: {message: {message: 'quote text'}}, |
| 2002 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2003 | element.handleMessageReply(e); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 2004 | const dialog = await waitQueryAndAssert<GrReplyDialog>( |
| 2005 | element, |
| 2006 | '#replyDialog' |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2007 | ); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 2008 | const openSpy = sinon.spy(dialog, 'open'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2009 | await element.updateComplete; |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 2010 | await waitUntil(() => openSpy.called && !!openSpy.lastCall.args[1]); |
| 2011 | assert.equal(openSpy.lastCall.args[1], '> quote text\n\n'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2012 | }); |
| 2013 | }); |
| 2014 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2015 | test('header class computation', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2016 | assert.equal(element.computeHeaderClass(), 'header'); |
| 2017 | assertIsDefined(element.params); |
| 2018 | element.params.edit = true; |
| 2019 | assert.equal(element.computeHeaderClass(), 'header editMode'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2020 | }); |
| 2021 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2022 | test('maybeScrollToMessage', async () => { |
| 2023 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2024 | const scrollStub = sinon.stub(element.messagesList!, 'scrollToMessage'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2025 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2026 | element.maybeScrollToMessage(''); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2027 | assert.isFalse(scrollStub.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2028 | element.maybeScrollToMessage('message'); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2029 | assert.isFalse(scrollStub.called); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2030 | element.maybeScrollToMessage('#message-TEST'); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2031 | assert.isTrue(scrollStub.called); |
| 2032 | assert.equal(scrollStub.lastCall.args[0], 'TEST'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2033 | }); |
| 2034 | |
| 2035 | test('topic update reloads related changes', () => { |
Milutin Kristofic | 8803ea0 | 2020-12-09 23:34:39 +0100 | [diff] [blame] | 2036 | flush(); |
| 2037 | const relatedChanges = element.shadowRoot!.querySelector( |
| 2038 | '#relatedChanges' |
| 2039 | ) as GrRelatedChangesList; |
| 2040 | const reloadStub = sinon.stub(relatedChanges, 'reload'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2041 | element.dispatchEvent(new CustomEvent('topic-changed')); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2042 | assert.isTrue(reloadStub.calledOnce); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2043 | }); |
| 2044 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2045 | test('computeEditMode', async () => { |
| 2046 | const callCompute = async (params: AppElementChangeViewParams) => { |
| 2047 | element.params = params; |
| 2048 | await element.updateComplete; |
| 2049 | return element.getEditMode(); |
| 2050 | }; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2051 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2052 | await callCompute({ |
| 2053 | ...createAppElementChangeViewParams(), |
| 2054 | edit: true, |
| 2055 | basePatchNum: PARENT, |
| 2056 | patchNum: 1 as RevisionPatchSetNum, |
| 2057 | }) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2058 | ); |
| 2059 | assert.isFalse( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2060 | await callCompute({ |
| 2061 | ...createAppElementChangeViewParams(), |
| 2062 | basePatchNum: PARENT, |
| 2063 | patchNum: 1 as RevisionPatchSetNum, |
| 2064 | }) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2065 | ); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2066 | assert.isTrue( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2067 | await callCompute({ |
| 2068 | ...createAppElementChangeViewParams(), |
| 2069 | basePatchNum: 1 as BasePatchSetNum, |
| 2070 | patchNum: EDIT, |
| 2071 | }) |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2072 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2073 | }); |
| 2074 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2075 | test('processEdit', () => { |
| 2076 | element.patchRange = {}; |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2077 | const change: ParsedChangeInfo = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2078 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2079 | current_revision: 'foo' as CommitId, |
| 2080 | revisions: { |
Ben Rohlfs | 5e16702 | 2021-12-06 11:48:22 +0100 | [diff] [blame] | 2081 | foo: {...createRevision()}, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2082 | }, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2083 | }; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2084 | |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2085 | // With no edit, nothing happens. |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2086 | element.processEdit(change); |
| 2087 | assert.equal(element.patchRange.patchNum, undefined); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2088 | |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2089 | change.revisions['bar'] = { |
Ben Rohlfs | ef04317 | 2022-05-27 16:07:27 +0200 | [diff] [blame] | 2090 | _number: EDIT, |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2091 | basePatchNum: 1 as BasePatchSetNum, |
| 2092 | commit: { |
| 2093 | ...createCommit(), |
| 2094 | commit: 'bar' as CommitId, |
| 2095 | }, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2096 | fetch: {}, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2097 | }; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2098 | |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2099 | // When edit is set, but not patchNum, then switch to edit ps. |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2100 | element.processEdit(change); |
| 2101 | assert.equal(element.patchRange.patchNum, EDIT); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2102 | |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2103 | // When edit is set, but patchNum as well, then keep patchNum. |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2104 | element.patchRange.patchNum = 5 as RevisionPatchSetNum; |
Ben Rohlfs | 8ccb2d4 | 2021-12-08 11:22:20 +0100 | [diff] [blame] | 2105 | element.routerPatchNum = 5 as RevisionPatchSetNum; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2106 | element.processEdit(change); |
| 2107 | assert.equal(element.patchRange.patchNum, 5 as RevisionPatchSetNum); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2108 | }); |
| 2109 | |
Frank Borden | 8198a83 | 2022-04-11 17:31:15 +0200 | [diff] [blame] | 2110 | test('file-action-tap handling', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2111 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 2112 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 2113 | patchNum: 1 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2114 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2115 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2116 | ...createChangeViewChange(), |
Milutin Kristofic | bec88f1 | 2020-10-13 16:53:28 +0200 | [diff] [blame] | 2117 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2118 | assertIsDefined(element.fileList); |
| 2119 | assertIsDefined(element.fileListHeader); |
| 2120 | const fileList = element.fileList; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2121 | const Actions = GrEditConstants.Actions; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2122 | element.fileListHeader.editMode = true; |
| 2123 | await element.fileListHeader.updateComplete; |
| 2124 | await element.updateComplete; |
Frank Borden | 8198a83 | 2022-04-11 17:31:15 +0200 | [diff] [blame] | 2125 | const controls = queryAndAssert<GrEditControls>( |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2126 | element.fileListHeader, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2127 | '#editControls' |
Frank Borden | 8198a83 | 2022-04-11 17:31:15 +0200 | [diff] [blame] | 2128 | ); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2129 | const openDeleteDialogStub = sinon.stub(controls, 'openDeleteDialog'); |
| 2130 | const openRenameDialogStub = sinon.stub(controls, 'openRenameDialog'); |
| 2131 | const openRestoreDialogStub = sinon.stub(controls, 'openRestoreDialog'); |
| 2132 | const getEditUrlForDiffStub = sinon.stub(GerritNav, 'getEditUrlForDiff'); |
| 2133 | const navigateToRelativeUrlStub = sinon.stub( |
| 2134 | GerritNav, |
| 2135 | 'navigateToRelativeUrl' |
| 2136 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2137 | |
| 2138 | // Delete |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2139 | fileList.dispatchEvent( |
| 2140 | new CustomEvent('file-action-tap', { |
| 2141 | detail: {action: Actions.DELETE.id, path: 'foo'}, |
| 2142 | bubbles: true, |
| 2143 | composed: true, |
| 2144 | }) |
| 2145 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2146 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2147 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2148 | assert.isTrue(openDeleteDialogStub.called); |
| 2149 | assert.equal(openDeleteDialogStub.lastCall.args[0], 'foo'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2150 | |
| 2151 | // Restore |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2152 | fileList.dispatchEvent( |
| 2153 | new CustomEvent('file-action-tap', { |
| 2154 | detail: {action: Actions.RESTORE.id, path: 'foo'}, |
| 2155 | bubbles: true, |
| 2156 | composed: true, |
| 2157 | }) |
| 2158 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2159 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2160 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2161 | assert.isTrue(openRestoreDialogStub.called); |
| 2162 | assert.equal(openRestoreDialogStub.lastCall.args[0], 'foo'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2163 | |
| 2164 | // Rename |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2165 | fileList.dispatchEvent( |
| 2166 | new CustomEvent('file-action-tap', { |
| 2167 | detail: {action: Actions.RENAME.id, path: 'foo'}, |
| 2168 | bubbles: true, |
| 2169 | composed: true, |
| 2170 | }) |
| 2171 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2172 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2173 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2174 | assert.isTrue(openRenameDialogStub.called); |
| 2175 | assert.equal(openRenameDialogStub.lastCall.args[0], 'foo'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2176 | |
| 2177 | // Open |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2178 | fileList.dispatchEvent( |
| 2179 | new CustomEvent('file-action-tap', { |
| 2180 | detail: {action: Actions.OPEN.id, path: 'foo'}, |
| 2181 | bubbles: true, |
| 2182 | composed: true, |
| 2183 | }) |
| 2184 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2185 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2186 | |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2187 | assert.isTrue(getEditUrlForDiffStub.called); |
| 2188 | assert.equal(getEditUrlForDiffStub.lastCall.args[1], 'foo'); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 2189 | assert.equal( |
| 2190 | getEditUrlForDiffStub.lastCall.args[2], |
| 2191 | 1 as RevisionPatchSetNum |
| 2192 | ); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2193 | assert.isTrue(navigateToRelativeUrlStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2194 | }); |
| 2195 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2196 | test('selectedRevision updates when patchNum is changed', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2197 | const revision1: RevisionInfo = createRevision(1); |
| 2198 | const revision2: RevisionInfo = createRevision(2); |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 2199 | element.getChangeModel().setState({ |
Ben Rohlfs | 61bafc2 | 2021-11-29 10:40:08 +0100 | [diff] [blame] | 2200 | loadingStatus: LoadingStatus.LOADED, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 2201 | change: { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2202 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2203 | revisions: { |
| 2204 | aaa: revision1, |
| 2205 | bbb: revision2, |
| 2206 | }, |
| 2207 | labels: {}, |
| 2208 | actions: {}, |
| 2209 | current_revision: 'bbb' as CommitId, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 2210 | }, |
| 2211 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2212 | element.userModel.setPreferences(createPreferences()); |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 2213 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2214 | element.patchRange = {patchNum: 2 as RevisionPatchSetNum}; |
| 2215 | await element.performPostChangeLoadTasks(); |
| 2216 | assert.strictEqual(element.selectedRevision, revision2); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2217 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2218 | element.patchRange = {patchNum: 1 as RevisionPatchSetNum}; |
| 2219 | await element.updateComplete; |
| 2220 | assert.strictEqual(element.selectedRevision, revision1); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2221 | }); |
| 2222 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2223 | test('selectedRevision is assigned when patchNum is edit', async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2224 | const revision1 = createRevision(1); |
| 2225 | const revision2 = createRevision(2); |
| 2226 | const revision3 = createEditRevision(); |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 2227 | element.getChangeModel().setState({ |
Ben Rohlfs | 61bafc2 | 2021-11-29 10:40:08 +0100 | [diff] [blame] | 2228 | loadingStatus: LoadingStatus.LOADED, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 2229 | change: { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2230 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2231 | revisions: { |
| 2232 | aaa: revision1, |
| 2233 | bbb: revision2, |
| 2234 | ccc: revision3, |
| 2235 | }, |
| 2236 | labels: {}, |
| 2237 | actions: {}, |
| 2238 | current_revision: 'ccc' as CommitId, |
Ben Rohlfs | a16c51a | 2021-11-22 12:50:55 +0100 | [diff] [blame] | 2239 | }, |
| 2240 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2241 | stubRestApi('getPreferences').returns(Promise.resolve(createPreferences())); |
| 2242 | |
| 2243 | element.patchRange = {patchNum: EDIT}; |
Ben Rohlfs | 1fe7f4d | 2021-12-06 11:21:49 +0100 | [diff] [blame] | 2244 | await element.performPostChangeLoadTasks(); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2245 | assert.strictEqual(element.selectedRevision, revision3); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2246 | }); |
| 2247 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2248 | test('sendShowChangeEvent', () => { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2249 | const change = {...createChangeViewChange(), labels: {}}; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2250 | element.change = {...change}; |
| 2251 | element.patchRange = {patchNum: 4 as RevisionPatchSetNum}; |
| 2252 | element.mergeable = true; |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 2253 | const showStub = sinon.stub(element.jsAPI, 'handleEvent'); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2254 | element.sendShowChangeEvent(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2255 | assert.isTrue(showStub.calledOnce); |
Ben Rohlfs | a47355d | 2020-08-30 15:56:13 +0200 | [diff] [blame] | 2256 | assert.equal(showStub.lastCall.args[0], EventType.SHOW_CHANGE); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2257 | assert.deepEqual(showStub.lastCall.args[1], { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2258 | change, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2259 | patchNum: 4, |
| 2260 | info: {mergeable: true}, |
| 2261 | }); |
| 2262 | }); |
| 2263 | |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2264 | test('patch range changed', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2265 | element.patchRange = undefined; |
| 2266 | element.change = createChangeViewChange(); |
| 2267 | element.change.revisions = createRevisions(4); |
| 2268 | element.change.current_revision = '1' as CommitId; |
| 2269 | element.change = {...element.change}; |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2270 | |
| 2271 | const params = createAppElementChangeViewParams(); |
| 2272 | |
| 2273 | assert.isFalse(element.hasPatchRangeChanged(params)); |
| 2274 | assert.isFalse(element.hasPatchNumChanged(params)); |
| 2275 | |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 2276 | params.basePatchNum = PARENT; |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2277 | // undefined means navigate to latest patchset |
| 2278 | params.patchNum = undefined; |
| 2279 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2280 | element.patchRange = { |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2281 | patchNum: 2 as RevisionPatchSetNum, |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 2282 | basePatchNum: PARENT, |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2283 | }; |
| 2284 | |
| 2285 | assert.isTrue(element.hasPatchRangeChanged(params)); |
| 2286 | assert.isTrue(element.hasPatchNumChanged(params)); |
| 2287 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2288 | element.patchRange = { |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2289 | patchNum: 4 as RevisionPatchSetNum, |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 2290 | basePatchNum: PARENT, |
Dhruv Srivastava | 254b1da | 2021-10-27 12:32:44 +0200 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | assert.isFalse(element.hasPatchRangeChanged(params)); |
| 2294 | assert.isFalse(element.hasPatchNumChanged(params)); |
| 2295 | }); |
| 2296 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2297 | suite('handleEditTap', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2298 | let fireEdit: () => void; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2299 | |
| 2300 | setup(() => { |
| 2301 | fireEdit = () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2302 | assertIsDefined(element.actions); |
| 2303 | element.actions.dispatchEvent(new CustomEvent('edit-tap')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2304 | }; |
| 2305 | navigateToChangeStub.restore(); |
| 2306 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2307 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2308 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2309 | revisions: {rev1: createRevision()}, |
| 2310 | }; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2311 | }); |
| 2312 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2313 | test('edit exists in revisions', async () => { |
| 2314 | const promise = mockPromise(); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 2315 | sinon.stub(GerritNav, 'navigateToChange').callsFake((...args) => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2316 | assert.equal(args.length, 2); |
Ben Rohlfs | ef04317 | 2022-05-27 16:07:27 +0200 | [diff] [blame] | 2317 | assert.equal(args[1]!.patchNum, EDIT); // patchNum |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2318 | promise.resolve(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2319 | }); |
| 2320 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2321 | assertIsDefined(element.change); |
| 2322 | const newChange = {...element.change}; |
| 2323 | newChange.revisions.rev2 = createRevision(EDIT); |
| 2324 | element.change = newChange; |
| 2325 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2326 | |
| 2327 | fireEdit(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2328 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2329 | }); |
| 2330 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2331 | test('no edit exists in revisions, non-latest patchset', async () => { |
| 2332 | const promise = mockPromise(); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 2333 | sinon.stub(GerritNav, 'navigateToChange').callsFake((...args) => { |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 2334 | assert.equal(args.length, 2); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 2335 | assert.equal(args[1]!.patchNum, 1 as RevisionPatchSetNum); // patchNum |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 2336 | assert.equal(args[1]!.isEdit, true); // opt_isEdit |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2337 | promise.resolve(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2338 | }); |
| 2339 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2340 | assertIsDefined(element.change); |
| 2341 | const newChange = {...element.change}; |
| 2342 | newChange.revisions.rev2 = createRevision(2); |
| 2343 | element.change = newChange; |
| 2344 | element.patchRange = {patchNum: 1 as RevisionPatchSetNum}; |
| 2345 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2346 | |
| 2347 | fireEdit(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2348 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2349 | }); |
| 2350 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2351 | test('no edit exists in revisions, latest patchset', async () => { |
| 2352 | const promise = mockPromise(); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 2353 | sinon.stub(GerritNav, 'navigateToChange').callsFake((...args) => { |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 2354 | assert.equal(args.length, 2); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2355 | // No patch should be specified when patchNum == latest. |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 2356 | assert.isNotOk(args[1]!.patchNum); // patchNum |
| 2357 | assert.equal(args[1]!.isEdit, true); // opt_isEdit |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2358 | promise.resolve(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2359 | }); |
| 2360 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2361 | assertIsDefined(element.change); |
| 2362 | const newChange = {...element.change}; |
| 2363 | newChange.revisions.rev2 = createRevision(2); |
| 2364 | element.change = newChange; |
| 2365 | element.patchRange = {patchNum: 2 as RevisionPatchSetNum}; |
| 2366 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2367 | |
| 2368 | fireEdit(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2369 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2370 | }); |
| 2371 | }); |
| 2372 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2373 | test('handleStopEditTap', async () => { |
| 2374 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2375 | ...createChangeViewChange(), |
Milutin Kristofic | bec88f1 | 2020-10-13 16:53:28 +0200 | [diff] [blame] | 2376 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2377 | await element.updateComplete; |
| 2378 | assertIsDefined(element.metadata); |
| 2379 | assertIsDefined(element.actions); |
| 2380 | sinon.stub(element.metadata, 'computeLabelNames'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2381 | navigateToChangeStub.restore(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2382 | const promise = mockPromise(); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 2383 | sinon.stub(GerritNav, 'navigateToChange').callsFake((...args) => { |
Dhruv Srivastava | 0633ae1 | 2021-11-11 15:16:47 +0100 | [diff] [blame] | 2384 | assert.equal(args.length, 2); |
Ben Rohlfs | abaeacf | 2022-05-27 15:24:22 +0200 | [diff] [blame] | 2385 | assert.equal(args[1]!.patchNum, 1 as RevisionPatchSetNum); // patchNum |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2386 | promise.resolve(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2387 | }); |
| 2388 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2389 | element.patchRange = {patchNum: 1 as RevisionPatchSetNum}; |
| 2390 | element.actions.dispatchEvent( |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2391 | new CustomEvent('stop-edit-tap', {bubbles: false}) |
| 2392 | ); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2393 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2394 | }); |
| 2395 | |
| 2396 | suite('plugin endpoints', () => { |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2397 | test('endpoint params', async () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2398 | element.change = {...createChangeViewChange(), labels: {}}; |
| 2399 | element.selectedRevision = createRevision(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2400 | const promise = mockPromise(); |
Chris Poucet | d3f52fd | 2021-11-29 23:16:39 +0100 | [diff] [blame] | 2401 | window.Gerrit.install( |
| 2402 | promise.resolve, |
| 2403 | '0.1', |
| 2404 | 'http://some/plugins/url.js' |
| 2405 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2406 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2407 | const plugin: PluginApi = (await promise) as PluginApi; |
| 2408 | const hookEl = await plugin |
| 2409 | .hook('change-view-integration') |
| 2410 | .getLastAttached(); |
| 2411 | assert.strictEqual((hookEl as any).plugin, plugin); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2412 | assert.strictEqual((hookEl as any).change, element.change); |
| 2413 | assert.strictEqual((hookEl as any).revision, element.selectedRevision); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2414 | }); |
| 2415 | }); |
| 2416 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2417 | suite('getMergeability', () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2418 | let getMergeableStub: SinonStubbedMember<RestApiService['getMergeable']>; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2419 | setup(() => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2420 | element.change = {...createChangeViewChange(), labels: {}}; |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 2421 | getMergeableStub = stubRestApi('getMergeable').returns( |
| 2422 | Promise.resolve({...createMergeable(), mergeable: true}) |
| 2423 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2424 | }); |
| 2425 | |
| 2426 | test('merged change', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2427 | element.mergeable = null; |
| 2428 | element.change!.status = ChangeStatus.MERGED; |
| 2429 | return element.getMergeability().then(() => { |
| 2430 | assert.isFalse(element.mergeable); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2431 | assert.isFalse(getMergeableStub.called); |
| 2432 | }); |
| 2433 | }); |
| 2434 | |
| 2435 | test('abandoned change', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2436 | element.mergeable = null; |
| 2437 | element.change!.status = ChangeStatus.ABANDONED; |
| 2438 | return element.getMergeability().then(() => { |
| 2439 | assert.isFalse(element.mergeable); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2440 | assert.isFalse(getMergeableStub.called); |
| 2441 | }); |
| 2442 | }); |
| 2443 | |
| 2444 | test('open change', () => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2445 | element.mergeable = null; |
| 2446 | return element.getMergeability().then(() => { |
| 2447 | assert.isTrue(element.mergeable); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2448 | assert.isTrue(getMergeableStub.called); |
| 2449 | }); |
| 2450 | }); |
| 2451 | }); |
| 2452 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2453 | test('handleToggleStar called when star is tapped', async () => { |
| 2454 | element.change = { |
Dhruv Srivastava | da27659 | 2021-04-07 14:51:51 +0200 | [diff] [blame] | 2455 | ...createChangeViewChange(), |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2456 | owner: {_account_id: 1 as AccountId}, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2457 | starred: false, |
| 2458 | }; |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2459 | element.loggedIn = true; |
| 2460 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2461 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2462 | const stub = sinon.stub(element, 'handleToggleStar'); |
Paladox none | 70efbef | 2021-08-12 05:21:59 +0000 | [diff] [blame] | 2463 | |
| 2464 | const changeStar = queryAndAssert<GrChangeStar>(element, '#changeStar'); |
| 2465 | tap(queryAndAssert<HTMLButtonElement>(changeStar, 'button')!); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2466 | assert.isTrue(stub.called); |
| 2467 | }); |
| 2468 | |
| 2469 | suite('gr-reporting tests', () => { |
| 2470 | setup(() => { |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2471 | element.patchRange = { |
Ben Rohlfs | 58267b7 | 2022-05-27 15:59:18 +0200 | [diff] [blame] | 2472 | basePatchNum: PARENT, |
Dhruv Srivastava | 1c41a1b7 | 2021-03-11 16:24:53 +0100 | [diff] [blame] | 2473 | patchNum: 1 as RevisionPatchSetNum, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2474 | }; |
Dhruv Srivastava | 2112981 | 2021-12-02 15:48:03 +0100 | [diff] [blame] | 2475 | sinon |
| 2476 | .stub(element, 'performPostChangeLoadTasks') |
| 2477 | .returns(Promise.resolve(false)); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2478 | sinon.stub(element, 'getMergeability').returns(Promise.resolve()); |
| 2479 | sinon.stub(element, 'getLatestCommitMessage').returns(Promise.resolve()); |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 2480 | sinon |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2481 | .stub(element, 'reloadPatchNumDependentResources') |
Dhruv Srivastava | 09a1b5a | 2021-01-20 09:28:15 +0100 | [diff] [blame] | 2482 | .returns(Promise.resolve([undefined, undefined, undefined])); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2483 | }); |
| 2484 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2485 | test("don't report changeDisplayed on reply", async () => { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2486 | const changeDisplayStub = sinon.stub( |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 2487 | element.reporting, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2488 | 'changeDisplayed' |
| 2489 | ); |
| 2490 | const changeFullyLoadedStub = sinon.stub( |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 2491 | element.reporting, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2492 | 'changeFullyLoaded' |
| 2493 | ); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2494 | element.handleReplySent(); |
| 2495 | await element.updateComplete; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 2496 | assert.isFalse(changeDisplayStub.called); |
| 2497 | assert.isFalse(changeFullyLoadedStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2498 | }); |
| 2499 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2500 | test('report changeDisplayed on paramsChanged', async () => { |
Ben Rohlfs | b7ef7f7 | 2022-06-10 12:17:28 +0200 | [diff] [blame] | 2501 | stubRestApi('getChangeOrEditFiles').resolves({ |
| 2502 | 'a-file.js': {}, |
| 2503 | }); |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2504 | const changeDisplayStub = sinon.stub( |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 2505 | element.reporting, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2506 | 'changeDisplayed' |
| 2507 | ); |
| 2508 | const changeFullyLoadedStub = sinon.stub( |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 2509 | element.reporting, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2510 | 'changeFullyLoaded' |
| 2511 | ); |
Dhruv Srivastava | 49f0a7a | 2021-10-06 12:03:01 +0100 | [diff] [blame] | 2512 | // reset so reload is triggered |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2513 | element.changeNum = undefined; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 2514 | element.params = { |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2515 | ...createAppElementChangeViewParams(), |
Ben Rohlfs | a5356e9 | 2021-05-07 11:06:17 +0200 | [diff] [blame] | 2516 | changeNum: TEST_NUMERIC_CHANGE_ID, |
Dmitrii Filippov | 78448cd | 2020-10-26 17:39:11 +0100 | [diff] [blame] | 2517 | project: TEST_PROJECT_NAME, |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 2518 | }; |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 2519 | element.getChangeModel().setState({ |
Dhruv Srivastava | 2112981 | 2021-12-02 15:48:03 +0100 | [diff] [blame] | 2520 | loadingStatus: LoadingStatus.LOADED, |
| 2521 | change: { |
| 2522 | ...createChangeViewChange(), |
| 2523 | labels: {}, |
| 2524 | current_revision: 'foo' as CommitId, |
| 2525 | revisions: {foo: createRevision()}, |
| 2526 | }, |
| 2527 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2528 | await element.updateComplete; |
Ben Rohlfs | 71a8dee | 2021-06-22 10:06:15 +0200 | [diff] [blame] | 2529 | await flush(); |
| 2530 | assert.isTrue(changeDisplayStub.called); |
| 2531 | assert.isTrue(changeFullyLoadedStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2532 | }); |
| 2533 | }); |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 2534 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2535 | test('calculateHasParent', () => { |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 2536 | const changeId = '123' as ChangeId; |
| 2537 | const relatedChanges: RelatedChangeAndCommitInfo[] = []; |
| 2538 | |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2539 | assert.equal(element.calculateHasParent(changeId, relatedChanges), false); |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 2540 | |
| 2541 | relatedChanges.push({ |
| 2542 | ...createRelatedChangeAndCommitInfo(), |
| 2543 | change_id: '123' as ChangeId, |
| 2544 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2545 | assert.equal(element.calculateHasParent(changeId, relatedChanges), false); |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 2546 | |
| 2547 | relatedChanges.push({ |
| 2548 | ...createRelatedChangeAndCommitInfo(), |
| 2549 | change_id: '234' as ChangeId, |
| 2550 | }); |
Chris Poucet | 973ecc9 | 2022-06-13 10:44:07 +0200 | [diff] [blame] | 2551 | assert.equal(element.calculateHasParent(changeId, relatedChanges), true); |
Milutin Kristofic | e9ddfa4 | 2021-04-20 23:34:45 +0200 | [diff] [blame] | 2552 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2553 | }); |