Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
| 3 | * Copyright 2023 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | import '../../../test/common-test-setup'; |
| 7 | import './gr-revision-parents'; |
| 8 | import {fixture, html, assert} from '@open-wc/testing'; |
| 9 | import {GrRevisionParents} from './gr-revision-parents'; |
| 10 | import {createRevision} from '../../../test/test-data-generators'; |
| 11 | import { |
| 12 | ChangeId, |
| 13 | ChangeStatus, |
Ben Rohlfs | ee000a8 | 2023-09-18 16:17:21 +0200 | [diff] [blame] | 14 | CommitId, |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 15 | NumericChangeId, |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 16 | ParentInfo, |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 17 | PatchSetNumber, |
| 18 | } from '../../../api/rest-api'; |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 19 | import {queryAll} from '../../../utils/common-util'; |
| 20 | |
| 21 | const PARENT_DEFAULT: ParentInfo = { |
| 22 | branch_name: 'refs/heads/master', |
| 23 | commit_id: '78e52ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 24 | is_merged_in_target_branch: true, |
| 25 | }; |
| 26 | |
| 27 | const PARENT_REBASED: ParentInfo = { |
| 28 | ...PARENT_DEFAULT, |
| 29 | commit_id: '00002ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 30 | }; |
| 31 | |
| 32 | const PARENT_OTHER_BRANCH: ParentInfo = { |
| 33 | ...PARENT_DEFAULT, |
| 34 | branch_name: 'refs/heads/otherbranch', |
| 35 | commit_id: '11112ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 36 | }; |
| 37 | |
| 38 | const PARENT_WEIRD: ParentInfo = { |
| 39 | ...PARENT_DEFAULT, |
| 40 | commit_id: '22222ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 41 | is_merged_in_target_branch: false, |
| 42 | }; |
| 43 | |
| 44 | const PARENT_CHANGE_123_1: ParentInfo = { |
| 45 | ...PARENT_DEFAULT, |
| 46 | commit_id: '12312ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 47 | is_merged_in_target_branch: false, |
| 48 | change_id: 'Idc69e6d7bba0ce0a9a0bdcd22adb506c0b76e628' as ChangeId, |
| 49 | change_number: 123 as NumericChangeId, |
| 50 | patch_set_number: 1 as PatchSetNumber, |
| 51 | change_status: ChangeStatus.NEW, |
| 52 | }; |
| 53 | |
| 54 | const PARENT_CHANGE_123_2: ParentInfo = { |
| 55 | ...PARENT_CHANGE_123_1, |
| 56 | commit_id: '12322ce873b1c08396422f51ad6aacf77ed95541' as CommitId, |
| 57 | patch_set_number: 2 as PatchSetNumber, |
| 58 | }; |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 59 | |
| 60 | suite('gr-revision-parents tests', () => { |
| 61 | let element: GrRevisionParents; |
| 62 | |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 63 | const setParents = async ( |
| 64 | parentLeft: ParentInfo, |
| 65 | parentRight: ParentInfo |
| 66 | ) => { |
| 67 | element.baseRevision = { |
| 68 | ...createRevision(1), |
| 69 | parents_data: [parentLeft], |
| 70 | }; |
| 71 | element.revision = { |
| 72 | ...createRevision(2), |
| 73 | parents_data: [parentRight], |
| 74 | }; |
| 75 | await element.updateComplete; |
| 76 | }; |
| 77 | |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 78 | setup(async () => { |
| 79 | element = await fixture(html`<gr-revision-parents></gr-revision-parents>`); |
| 80 | await element.updateComplete; |
| 81 | }); |
| 82 | |
| 83 | test('render empty', () => { |
| 84 | assert.shadowDom.equal(element, ''); |
| 85 | }); |
| 86 | |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 87 | test('render details: PARENT_DEFAULT', async () => { |
| 88 | element.showDetails = true; |
| 89 | await setParents(PARENT_DEFAULT, PARENT_DEFAULT); |
| 90 | assert.dom.equal( |
| 91 | queryAll(element, '.section')[0], |
Ben Rohlfs | ee000a8 | 2023-09-18 16:17:21 +0200 | [diff] [blame] | 92 | /* HTML */ ` |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 93 | <div class="section"> |
| 94 | <h4 class="heading-4">Patchset 1</h4> |
| 95 | <div>Target branch: master</div> |
| 96 | <div> |
| 97 | Base commit: |
| 98 | <gr-commit-info> </gr-commit-info> |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 99 | </div> |
| 100 | </div> |
Ben Rohlfs | ee000a8 | 2023-09-18 16:17:21 +0200 | [diff] [blame] | 101 | ` |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 102 | ); |
| 103 | }); |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 104 | |
| 105 | test('render details: PARENT_WEIRD', async () => { |
| 106 | element.showDetails = true; |
| 107 | await setParents(PARENT_WEIRD, PARENT_WEIRD); |
| 108 | assert.dom.equal( |
| 109 | queryAll(element, '.section')[0], |
| 110 | ` |
| 111 | <div class="section"> |
| 112 | <h4 class="heading-4">Patchset 1</h4> |
| 113 | <div>Target branch: master</div> |
| 114 | <div> |
| 115 | Base commit: |
| 116 | <gr-commit-info> </gr-commit-info> |
| 117 | </div> |
| 118 | <div> |
| 119 | <gr-icon icon="warning"> </gr-icon> |
| 120 | <span> |
| 121 | Warning: The base commit is not known (aka reachable) in the |
| 122 | target branch. |
| 123 | </span> |
| 124 | </div> |
| 125 | </div> |
| 126 | ` |
| 127 | ); |
| 128 | }); |
| 129 | |
| 130 | test('render details: PARENT_CHANGE_123_1', async () => { |
| 131 | element.showDetails = true; |
| 132 | await setParents(PARENT_CHANGE_123_1, PARENT_CHANGE_123_2); |
| 133 | assert.dom.equal( |
| 134 | queryAll(element, '.section')[0], |
| 135 | /* HTML */ ` |
| 136 | <div class="section"> |
| 137 | <h4 class="heading-4">Patchset 1</h4> |
| 138 | <div>Target branch: master</div> |
| 139 | <div> |
| 140 | Base commit: |
| 141 | <gr-commit-info> </gr-commit-info> |
| 142 | </div> |
| 143 | <div> |
| 144 | Base change: |
| 145 | <a href="/c/123"> 123 </a> |
| 146 | , patchset |
| 147 | <a href="/c/123/1"> 1 </a> |
| 148 | </div> |
| 149 | </div> |
| 150 | ` |
| 151 | ); |
| 152 | }); |
| 153 | |
| 154 | test('render message PARENT_DEFAULT vs PARENT_DEFAULT', async () => { |
| 155 | await setParents(PARENT_DEFAULT, PARENT_DEFAULT); |
| 156 | assert.shadowDom.equal(element, ''); |
| 157 | }); |
| 158 | |
| 159 | test('render message PARENT_DEFAULT vs PARENT_OTHER_BRANCH', async () => { |
| 160 | await setParents(PARENT_DEFAULT, PARENT_OTHER_BRANCH); |
| 161 | assert.shadowDom.equal( |
| 162 | element, |
| 163 | `<div class="messageContainer warning"> |
| 164 | <div class="icon"><gr-icon icon="warning"></gr-icon></div> |
| 165 | <div class="text"><p> |
| 166 | Patchset 1 and 2 are targeting different branches.<br/> |
Ben Rohlfs | 05bc55b | 2023-10-24 13:01:44 +0200 | [diff] [blame] | 167 | The diff below may not be meaningful and may<br/> |
| 168 | even be hiding relevant changes. |
| 169 | <a href="/Documentation/user-review-ui.html#hazardous-rebases">Learn more</a> |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 170 | </p><p><gr-button link="">Show details</gr-button></p></div></div>` |
| 171 | ); |
| 172 | }); |
| 173 | |
| 174 | test('render message PARENT_DEFAULT vs PARENT_WEIRD', async () => { |
| 175 | await setParents(PARENT_DEFAULT, PARENT_WEIRD); |
| 176 | assert.shadowDom.equal( |
| 177 | element, |
| 178 | `<div class="messageContainer warning"> |
| 179 | <div class="icon"><gr-icon icon="warning"></gr-icon></div> |
| 180 | <div class="text"><p> |
| 181 | Patchset 2 is based on a commit that neither exists in its |
| 182 | target branch, nor is it a commit of another active change.<br/> |
Ben Rohlfs | 05bc55b | 2023-10-24 13:01:44 +0200 | [diff] [blame] | 183 | The diff below may not be meaningful and may<br/> |
| 184 | even be hiding relevant changes. |
| 185 | <a href="/Documentation/user-review-ui.html#hazardous-rebases">Learn more</a> |
| 186 | </p><p><gr-button link="">Show details</gr-button></p></div></div>` |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 187 | ); |
| 188 | }); |
| 189 | |
| 190 | test('render message PARENT_DEFAULT vs PARENT_REBASED', async () => { |
| 191 | await setParents(PARENT_DEFAULT, PARENT_REBASED); |
| 192 | assert.shadowDom.equal( |
| 193 | element, |
| 194 | `<div class="messageContainer info"> |
| 195 | <div class="icon"><gr-icon icon="info"></gr-icon></div> |
| 196 | <div class="text"><p> |
| 197 | The change was rebased from <gr-commit-info></gr-commit-info> |
| 198 | onto <gr-commit-info></gr-commit-info>. |
| 199 | </p></div></div>` |
| 200 | ); |
| 201 | }); |
| 202 | |
| 203 | test('render message PARENT_CHANGE_123_1 vs PARENT_CHANGE_123_2', async () => { |
| 204 | await setParents(PARENT_CHANGE_123_1, PARENT_CHANGE_123_2); |
| 205 | assert.shadowDom.equal( |
| 206 | element, |
| 207 | `<div class="messageContainer info"> |
| 208 | <div class="icon"><gr-icon icon="info"></gr-icon></div> |
| 209 | <div class="text"><p> |
| 210 | The change was rebased from patchset |
| 211 | <a href="/c/123/1">1</a> onto |
| 212 | patchset |
| 213 | <a href="/c/123/2">2</a> of |
| 214 | change |
| 215 | <a href="/c/123">123</a>. |
| 216 | </p></div></div>` |
| 217 | ); |
| 218 | }); |
| 219 | |
| 220 | test('render message PARENT_DEFAULT vs PARENT_CHANGE_123_1', async () => { |
| 221 | await setParents(PARENT_DEFAULT, PARENT_CHANGE_123_1); |
| 222 | assert.shadowDom.equal( |
| 223 | element, |
| 224 | `<div class="messageContainer warning"> |
| 225 | <div class="icon"><gr-icon icon="warning"></gr-icon></div> |
| 226 | <div class="text"><p> |
| 227 | Patchset 1 is based on commit |
| 228 | <gr-commit-info></gr-commit-info> |
| 229 | in the target branch |
| 230 | (master).<br> |
| 231 | Patchset 2 is based on patchset |
| 232 | <a href="/c/123/1">1</a> |
| 233 | of change |
| 234 | <a href="/c/123">123</a>.<br> |
Ben Rohlfs | 05bc55b | 2023-10-24 13:01:44 +0200 | [diff] [blame] | 235 | The diff below may not be meaningful and may<br/> |
| 236 | even be hiding relevant changes. |
| 237 | <a href="/Documentation/user-review-ui.html#hazardous-rebases">Learn more</a> |
Ben Rohlfs | 0a707c9 | 2023-09-22 13:36:37 +0200 | [diff] [blame] | 238 | </p><p><gr-button link="">Show details</gr-button></p></div></div>` |
| 239 | ); |
| 240 | }); |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 241 | }); |