Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
| 3 | * Copyright (C) 2017 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Paladox none | a4b816b | 2017-06-18 20:21:37 +0000 | [diff] [blame] | 17 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 18 | import '../../../test/common-test-setup-karma'; |
| 19 | import './gr-group'; |
| 20 | import {GrGroup} from './gr-group'; |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 21 | import { |
| 22 | addListenerForTest, |
| 23 | mockPromise, |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 24 | queryAndAssert, |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 25 | stubRestApi, |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 26 | } from '../../../test/test-utils'; |
| 27 | import {createGroupInfo} from '../../../test/test-data-generators.js'; |
| 28 | import {GroupId, GroupInfo, GroupName} from '../../../types/common'; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 29 | import {GrAutocomplete} from '../../shared/gr-autocomplete/gr-autocomplete'; |
| 30 | import {GrButton} from '../../shared/gr-button/gr-button'; |
| 31 | import {GrCopyClipboard} from '../../shared/gr-copy-clipboard/gr-copy-clipboard'; |
| 32 | import {GrSelect} from '../../shared/gr-select/gr-select'; |
Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 33 | |
| 34 | const basicFixture = fixtureFromElement('gr-group'); |
| 35 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 36 | suite('gr-group tests', () => { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 37 | let element: GrGroup; |
| 38 | let groupStub: sinon.SinonStub; |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 39 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 40 | const group: GroupInfo = { |
| 41 | ...createGroupInfo('6a1e70e1a88782771a91808c8af9bbb7a9871389'), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 42 | url: '#/admin/groups/uuid-6a1e70e1a88782771a91808c8af9bbb7a9871389', |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 43 | options: { |
| 44 | visible_to_all: false, |
| 45 | }, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 46 | description: 'Gerrit Site Administrators', |
| 47 | group_id: 1, |
| 48 | owner: 'Administrators', |
| 49 | owner_id: '6a1e70e1a88782771a91808c8af9bbb7a9871389', |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 50 | name: 'Administrators' as GroupName, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 51 | }; |
Paladox none | a4b816b | 2017-06-18 20:21:37 +0000 | [diff] [blame] | 52 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 53 | setup(async () => { |
Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 54 | element = basicFixture.instantiate(); |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 55 | await element.updateComplete; |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 56 | groupStub = stubRestApi('getGroupConfig').returns(Promise.resolve(group)); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 57 | }); |
Paladox none | a4b816b | 2017-06-18 20:21:37 +0000 | [diff] [blame] | 58 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 59 | test('loading displays before group config is loaded', () => { |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 60 | assert.isTrue( |
| 61 | queryAndAssert<HTMLDivElement>(element, '#loading').classList.contains( |
| 62 | 'loading' |
| 63 | ) |
| 64 | ); |
| 65 | assert.isFalse( |
| 66 | getComputedStyle(queryAndAssert<HTMLDivElement>(element, '#loading')) |
| 67 | .display === 'none' |
| 68 | ); |
| 69 | assert.isTrue( |
| 70 | queryAndAssert<HTMLDivElement>( |
| 71 | element, |
| 72 | '#loadedContent' |
| 73 | ).classList.contains('loading') |
| 74 | ); |
| 75 | assert.isTrue( |
| 76 | getComputedStyle( |
| 77 | queryAndAssert<HTMLDivElement>(element, '#loadedContent') |
| 78 | ).display === 'none' |
| 79 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 80 | }); |
Paladox none | a4b816b | 2017-06-18 20:21:37 +0000 | [diff] [blame] | 81 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 82 | test('default values are populated with internal group', async () => { |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 83 | stubRestApi('getIsGroupOwner').returns(Promise.resolve(true)); |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 84 | element.groupId = '1' as GroupId; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 85 | await element.loadGroup(); |
| 86 | assert.isTrue(element.groupIsInternal); |
| 87 | assert.isFalse( |
| 88 | queryAndAssert<GrSelect>(element, '#visibleToAll').bindValue |
| 89 | ); |
Paladox none | a4b816b | 2017-06-18 20:21:37 +0000 | [diff] [blame] | 90 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 91 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 92 | test('default values with external group', async () => { |
Tao Zhou | 4cd35cb | 2020-07-22 11:28:22 +0200 | [diff] [blame] | 93 | const groupExternal = {...group}; |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 94 | groupExternal.id = 'external-group-id' as GroupId; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 95 | groupStub.restore(); |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 96 | groupStub = stubRestApi('getGroupConfig').returns( |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 97 | Promise.resolve(groupExternal) |
| 98 | ); |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 99 | stubRestApi('getIsGroupOwner').returns(Promise.resolve(true)); |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 100 | element.groupId = '1' as GroupId; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 101 | await element.loadGroup(); |
| 102 | assert.isFalse(element.groupIsInternal); |
| 103 | assert.isFalse( |
| 104 | queryAndAssert<GrSelect>(element, '#visibleToAll').bindValue |
| 105 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 106 | }); |
| 107 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 108 | test('rename group', async () => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 109 | const groupName = 'test-group'; |
| 110 | const groupName2 = 'test-group2'; |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 111 | element.groupId = '1' as GroupId; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 112 | element.groupConfig = { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 113 | name: groupName as GroupName, |
| 114 | id: '1' as GroupId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 115 | }; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 116 | element.originalName = groupName as GroupName; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 117 | |
Ben Rohlfs | 3a6ff7e | 2021-01-18 14:08:39 +0100 | [diff] [blame] | 118 | stubRestApi('getIsGroupOwner').returns(Promise.resolve(true)); |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 119 | stubRestApi('saveGroupName').returns( |
| 120 | Promise.resolve({...new Response(), status: 200}) |
| 121 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 122 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 123 | const button = queryAndAssert<GrButton>(element, '#inputUpdateNameBtn'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 124 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 125 | await element.loadGroup(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 126 | assert.isTrue(button.hasAttribute('disabled')); |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 127 | assert.isFalse( |
| 128 | queryAndAssert<HTMLHeadingElement>(element, '#Title').classList.contains( |
| 129 | 'edited' |
| 130 | ) |
| 131 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 132 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 133 | queryAndAssert<GrAutocomplete>(element, '#groupNameInput').text = |
| 134 | groupName2; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 135 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 136 | await element.updateComplete; |
| 137 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 138 | assert.isFalse(button.hasAttribute('disabled')); |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 139 | assert.isTrue( |
| 140 | queryAndAssert<HTMLHeadingElement>( |
| 141 | element, |
| 142 | '#groupName' |
| 143 | ).classList.contains('edited') |
| 144 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 145 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 146 | await element.handleSaveName(); |
| 147 | assert.isTrue(button.disabled); |
| 148 | assert.isFalse( |
| 149 | queryAndAssert<HTMLHeadingElement>(element, '#Title').classList.contains( |
| 150 | 'edited' |
| 151 | ) |
| 152 | ); |
| 153 | assert.equal(element.originalName, groupName2); |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 154 | }); |
| 155 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 156 | test('rename group owner', async () => { |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 157 | const groupName = 'test-group'; |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 158 | element.groupId = '1' as GroupId; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 159 | element.groupConfig = { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 160 | name: groupName as GroupName, |
| 161 | id: '1' as GroupId, |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 162 | }; |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 163 | element.groupConfigOwner = 'testId'; |
| 164 | element.groupOwner = true; |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 165 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 166 | stubRestApi('getIsGroupOwner').returns(Promise.resolve(true)); |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 167 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 168 | const button = queryAndAssert<GrButton>(element, '#inputUpdateOwnerBtn'); |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 169 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 170 | await element.loadGroup(); |
| 171 | assert.isTrue(button.disabled); |
| 172 | assert.isFalse( |
| 173 | queryAndAssert<HTMLHeadingElement>(element, '#Title').classList.contains( |
| 174 | 'edited' |
| 175 | ) |
| 176 | ); |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 177 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 178 | queryAndAssert<GrAutocomplete>(element, '#groupOwnerInput').text = |
| 179 | 'testId2'; |
Tao Zhou | 0a3c986 | 2020-04-08 14:45:37 +0200 | [diff] [blame] | 180 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 181 | await element.updateComplete; |
| 182 | assert.isFalse(button.disabled); |
| 183 | assert.isTrue( |
| 184 | queryAndAssert<HTMLHeadingElement>( |
| 185 | element, |
| 186 | '#groupOwner' |
| 187 | ).classList.contains('edited') |
| 188 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 189 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 190 | await element.handleSaveOwner(); |
| 191 | assert.isTrue(button.disabled); |
| 192 | assert.isFalse( |
| 193 | queryAndAssert<HTMLHeadingElement>(element, '#Title').classList.contains( |
| 194 | 'edited' |
| 195 | ) |
| 196 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 197 | }); |
| 198 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 199 | test('test for undefined group name', async () => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 200 | groupStub.restore(); |
| 201 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 202 | stubRestApi('getGroupConfig').returns(Promise.resolve(undefined)); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 203 | |
| 204 | assert.isUndefined(element.groupId); |
| 205 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 206 | element.groupId = '1' as GroupId; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 207 | |
| 208 | assert.isDefined(element.groupId); |
| 209 | |
| 210 | // Test that loading shows instead of filling |
| 211 | // in group details |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 212 | await element.loadGroup(); |
| 213 | assert.isTrue( |
| 214 | queryAndAssert<HTMLDivElement>(element, '#loading').classList.contains( |
| 215 | 'loading' |
| 216 | ) |
| 217 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 218 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 219 | assert.isTrue(element.loading); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 220 | }); |
| 221 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 222 | test('test fire event', async () => { |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 223 | element.groupConfig = { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 224 | name: 'test-group' as GroupName, |
| 225 | id: '1' as GroupId, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 226 | }; |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 227 | element.groupId = 'gg' as GroupId; |
| 228 | stubRestApi('saveGroupName').returns( |
| 229 | Promise.resolve({...new Response(), status: 200}) |
| 230 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 231 | |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 232 | const showStub = sinon.stub(element, 'dispatchEvent'); |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 233 | await element.handleSaveName(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 234 | assert.isTrue(showStub.called); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 235 | }); |
| 236 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 237 | test('computeGroupDisabled', () => { |
| 238 | element.isAdmin = true; |
| 239 | element.groupOwner = false; |
| 240 | element.groupIsInternal = true; |
| 241 | assert.equal(element.computeGroupDisabled(), false); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 242 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 243 | element.isAdmin = false; |
| 244 | assert.equal(element.computeGroupDisabled(), true); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 245 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 246 | element.groupOwner = true; |
| 247 | assert.equal(element.computeGroupDisabled(), false); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 248 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 249 | element.groupOwner = false; |
| 250 | assert.equal(element.computeGroupDisabled(), true); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 251 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 252 | element.groupIsInternal = false; |
| 253 | assert.equal(element.computeGroupDisabled(), true); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 254 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 255 | element.isAdmin = true; |
| 256 | assert.equal(element.computeGroupDisabled(), true); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 257 | }); |
| 258 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 259 | test('computeLoadingClass', () => { |
| 260 | element.loading = true; |
| 261 | assert.equal(element.computeLoadingClass(), 'loading'); |
| 262 | element.loading = false; |
| 263 | assert.equal(element.computeLoadingClass(), ''); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 264 | }); |
| 265 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 266 | test('fires page-error', async () => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 267 | groupStub.restore(); |
| 268 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 269 | element.groupId = '1' as GroupId; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 270 | |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 271 | const response = {...new Response(), status: 404}; |
| 272 | stubRestApi('getGroupConfig').callsFake((_, errFn) => { |
| 273 | if (errFn !== undefined) { |
| 274 | errFn(response); |
| 275 | } else { |
| 276 | assert.fail('errFn is undefined'); |
| 277 | } |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 278 | return Promise.resolve(undefined); |
Dmitrii Filippov | 7d4f2f3 | 2020-06-28 23:14:26 +0200 | [diff] [blame] | 279 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 280 | |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 281 | const promise = mockPromise(); |
Ben Rohlfs | a76c82f | 2021-01-22 22:22:32 +0100 | [diff] [blame] | 282 | addListenerForTest(document, 'page-error', e => { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 283 | assert.deepEqual((e as CustomEvent).detail.response, response); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 284 | promise.resolve(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 285 | }); |
| 286 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 287 | await element.loadGroup(); |
Chris Poucet | a2e173e | 2021-08-31 01:04:04 +0000 | [diff] [blame] | 288 | await promise; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 289 | }); |
Paladox none | 54505fc | 2020-05-11 10:34:08 +0000 | [diff] [blame] | 290 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 291 | test('uuid', async () => { |
| 292 | element.groupConfig = { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 293 | id: '6a1e70e1a88782771a91808c8af9bbb7a9871389' as GroupId, |
Paladox none | 54505fc | 2020-05-11 10:34:08 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 296 | await element.updateComplete; |
David Pursehouse | 7d65d0a | 2020-05-14 17:27:10 +0900 | [diff] [blame] | 297 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 298 | assert.equal( |
| 299 | element.groupConfig.id, |
| 300 | queryAndAssert<GrCopyClipboard>(element, '#uuid').text |
| 301 | ); |
| 302 | |
| 303 | element.groupConfig = { |
Paladox none | a26c394 | 2021-10-29 00:28:01 +0000 | [diff] [blame] | 304 | id: 'user%2Fgroup' as GroupId, |
David Pursehouse | 7d65d0a | 2020-05-14 17:27:10 +0900 | [diff] [blame] | 305 | }; |
| 306 | |
Paladox none | aaf24dc | 2021-10-29 13:55:14 +0000 | [diff] [blame^] | 307 | await element.updateComplete; |
| 308 | |
| 309 | assert.equal( |
| 310 | 'user/group', |
| 311 | queryAndAssert<GrCopyClipboard>(element, '#uuid').text |
| 312 | ); |
Paladox none | 54505fc | 2020-05-11 10:34:08 +0000 | [diff] [blame] | 313 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 314 | }); |