paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2020 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 5 | */ |
Frank Borden | be9451a | 2022-09-12 15:44:29 +0200 | [diff] [blame] | 6 | import '../../../test/common-test-setup'; |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 7 | import './gr-reply-dialog'; |
| 8 | import { |
| 9 | queryAndAssert, |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 10 | stubRestApi, |
Frank Borden | 7b24f73 | 2022-09-12 14:29:32 +0200 | [diff] [blame] | 11 | waitEventLoop, |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 12 | } from '../../../test/test-utils'; |
Chris Poucet | 2f6c017 | 2022-10-25 07:00:53 +0200 | [diff] [blame] | 13 | |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 14 | import {GrReplyDialog} from './gr-reply-dialog'; |
Frank Borden | e1ba821 | 2022-08-29 15:20:01 +0200 | [diff] [blame] | 15 | import {fixture, html, assert} from '@open-wc/testing'; |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 16 | import { |
| 17 | AccountId, |
| 18 | NumericChangeId, |
| 19 | PatchSetNum, |
| 20 | Timestamp, |
| 21 | } from '../../../types/common'; |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 22 | import {createChange} from '../../../test/test-data-generators'; |
Frank Borden | 5ebe7bb | 2022-08-29 17:09:35 +0200 | [diff] [blame] | 23 | import {GrButton} from '../../shared/gr-button/gr-button'; |
Chris Poucet | e3d6686 | 2022-10-26 11:19:50 +0200 | [diff] [blame] | 24 | import {testResolver} from '../../../test/common-test-setup'; |
| 25 | import {pluginLoaderToken} from '../../shared/gr-js-api-interface/gr-plugin-loader'; |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 26 | |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 27 | suite('gr-reply-dialog-it tests', () => { |
| 28 | let element: GrReplyDialog; |
| 29 | let changeNum: NumericChangeId; |
| 30 | let patchNum: PatchSetNum; |
| 31 | |
| 32 | const setupElement = (element: GrReplyDialog) => { |
| 33 | element.change = { |
| 34 | ...createChange(), |
| 35 | _number: changeNum, |
| 36 | labels: { |
| 37 | Verified: { |
| 38 | values: { |
| 39 | '-1': 'Fails', |
| 40 | ' 0': 'No score', |
| 41 | '+1': 'Verified', |
| 42 | }, |
| 43 | default_value: 0, |
| 44 | }, |
| 45 | 'Code-Review': { |
| 46 | values: { |
| 47 | '-2': 'This shall not be submitted', |
| 48 | '-1': 'I would prefer this is not submitted as is', |
| 49 | ' 0': 'No score', |
| 50 | '+1': 'Looks good to me, but someone else must approve', |
| 51 | '+2': 'Looks good to me, approved', |
| 52 | }, |
| 53 | all: [{_account_id: 42 as AccountId, value: 0}], |
| 54 | default_value: 0, |
| 55 | }, |
| 56 | }, |
| 57 | }; |
| 58 | element.patchNum = patchNum; |
| 59 | element.permittedLabels = { |
| 60 | 'Code-Review': ['-1', ' 0', '+1'], |
| 61 | Verified: ['-1', ' 0', '+1'], |
| 62 | }; |
| 63 | }; |
| 64 | |
| 65 | setup(async () => { |
| 66 | changeNum = 42 as NumericChangeId; |
| 67 | patchNum = 1 as PatchSetNum; |
| 68 | |
| 69 | stubRestApi('getAccount').returns( |
| 70 | Promise.resolve({ |
| 71 | _account_id: 42 as AccountId, |
| 72 | registered_on: '' as Timestamp, |
| 73 | }) |
| 74 | ); |
| 75 | |
| 76 | element = await fixture<GrReplyDialog>(html` |
| 77 | <gr-reply-dialog></gr-reply-dialog> |
| 78 | `); |
| 79 | setupElement(element); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 80 | |
| 81 | await element.updateComplete; |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 82 | }); |
| 83 | |
Frank Borden | 7b24f73 | 2022-09-12 14:29:32 +0200 | [diff] [blame] | 84 | test('submit blocked when invalid email is supplied to ccs', async () => { |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 85 | const sendStub = sinon.stub(element, 'send').returns(Promise.resolve()); |
| 86 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 87 | element.ccsList!.entry!.setText('test'); |
Frank Borden | 5ebe7bb | 2022-08-29 17:09:35 +0200 | [diff] [blame] | 88 | queryAndAssert<GrButton>(element, 'gr-button.send').click(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 89 | assert.isFalse(element.ccsList!.submitEntryText()); |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 90 | assert.isFalse(sendStub.called); |
Frank Borden | 7b24f73 | 2022-09-12 14:29:32 +0200 | [diff] [blame] | 91 | await waitEventLoop(); |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 92 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 93 | element.ccsList!.entry!.setText('test@test.test'); |
Frank Borden | 5ebe7bb | 2022-08-29 17:09:35 +0200 | [diff] [blame] | 94 | queryAndAssert<GrButton>(element, 'gr-button.send').click(); |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 95 | assert.isTrue(sendStub.called); |
| 96 | }); |
| 97 | |
| 98 | test('lgtm plugin', async () => { |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 99 | window.Gerrit.install( |
| 100 | plugin => { |
| 101 | const replyApi = plugin.changeReply(); |
| 102 | replyApi.addReplyTextChangedCallback(text => { |
| 103 | const label = 'Code-Review'; |
| 104 | const labelValue = replyApi.getLabelValue(label); |
| 105 | if (labelValue && labelValue === ' 0' && text.indexOf('LGTM') === 0) { |
| 106 | replyApi.setLabelValue(label, '+1'); |
| 107 | } |
| 108 | }); |
| 109 | }, |
| 110 | undefined, |
| 111 | 'http://test.com/plugins/lgtm.js' |
| 112 | ); |
Frank Borden | dedd671 | 2022-08-22 10:56:11 +0200 | [diff] [blame] | 113 | element = await fixture(html`<gr-reply-dialog></gr-reply-dialog>`); |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 114 | setupElement(element); |
Chris Poucet | e3d6686 | 2022-10-26 11:19:50 +0200 | [diff] [blame] | 115 | const pluginLoader = testResolver(pluginLoaderToken); |
Chris Poucet | 2f6c017 | 2022-10-25 07:00:53 +0200 | [diff] [blame] | 116 | pluginLoader.loadPlugins([]); |
| 117 | await pluginLoader.awaitPluginsLoaded(); |
Frank Borden | 7b24f73 | 2022-09-12 14:29:32 +0200 | [diff] [blame] | 118 | await waitEventLoop(); |
Frank Borden | 7b24f73 | 2022-09-12 14:29:32 +0200 | [diff] [blame] | 119 | await waitEventLoop(); |
paladox | 88aca97 | 2022-03-09 21:51:23 +0000 | [diff] [blame] | 120 | const labelScoreRows = queryAndAssert( |
| 121 | element.getLabelScores(), |
| 122 | 'gr-label-score-row[name="Code-Review"]' |
| 123 | ); |
| 124 | const selectedBtn = queryAndAssert( |
| 125 | labelScoreRows, |
| 126 | 'gr-button[data-value="+1"]' |
| 127 | ); |
| 128 | assert.isOk(selectedBtn); |
| 129 | }); |
| 130 | }); |