Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {assert} from 'chai'; |
| 6 | import {MrEditStatus} from './mr-edit-status.js'; |
| 7 | |
| 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('mr-edit-status', () => { |
| 12 | beforeEach(() => { |
| 13 | element = document.createElement('mr-edit-status'); |
| 14 | element.statuses = [ |
| 15 | {'status': 'New'}, |
| 16 | {'status': 'Old'}, |
| 17 | {'status': 'Duplicate'}, |
| 18 | ]; |
| 19 | document.body.appendChild(element); |
| 20 | }); |
| 21 | |
| 22 | afterEach(() => { |
| 23 | document.body.removeChild(element); |
| 24 | }); |
| 25 | |
| 26 | it('initializes', () => { |
| 27 | assert.instanceOf(element, MrEditStatus); |
| 28 | }); |
| 29 | |
| 30 | it('delta empty when no changes', () => { |
| 31 | assert.deepEqual(element.delta, {}); |
| 32 | }); |
| 33 | |
| 34 | it('change status', async () => { |
| 35 | element.initialStatus = 'New'; |
| 36 | |
| 37 | await element.updateComplete; |
| 38 | |
| 39 | const statusInput = element.shadowRoot.querySelector('select'); |
| 40 | statusInput.value = 'Old'; |
| 41 | statusInput.dispatchEvent(new Event('change')); |
| 42 | |
| 43 | await element.updateComplete; |
| 44 | |
| 45 | assert.deepEqual(element.delta, {status: 'Old'}); |
| 46 | }); |
| 47 | |
| 48 | it('mark as duplicate', async () => { |
| 49 | element.initialStatus = 'New'; |
| 50 | |
| 51 | await element.updateComplete; |
| 52 | |
| 53 | const statusInput = element.shadowRoot.querySelector('select'); |
| 54 | statusInput.value = 'Duplicate'; |
| 55 | statusInput.dispatchEvent(new Event('change')); |
| 56 | |
| 57 | await element.updateComplete; |
| 58 | |
| 59 | element.shadowRoot.querySelector('#mergedIntoInput').value = 'proj:123'; |
| 60 | assert.deepEqual(element.delta, { |
| 61 | status: 'Duplicate', |
| 62 | mergedInto: 'proj:123', |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | it('remove mark as duplicate', async () => { |
| 67 | element.initialStatus = 'Duplicate'; |
| 68 | element.mergedInto = 'chromium:1234'; |
| 69 | |
| 70 | await element.updateComplete; |
| 71 | |
| 72 | const statusInput = element.shadowRoot.querySelector('select'); |
| 73 | statusInput.value = 'New'; |
| 74 | statusInput.dispatchEvent(new Event('change')); |
| 75 | |
| 76 | await element.updateComplete; |
| 77 | |
| 78 | assert.deepEqual(element.delta, { |
| 79 | status: 'New', |
| 80 | mergedInto: '', |
| 81 | }); |
| 82 | }); |
| 83 | }); |