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