Adrià Vilanova MartÃnez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 1 | // Copyright 2021 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 React from 'react'; |
| 6 | import {assert} from 'chai'; |
| 7 | import {cleanup, render} from '@testing-library/react'; |
| 8 | import AttachmentUploader from 'react/issue-wizard/AttachmentUploader.tsx'; |
| 9 | |
| 10 | describe('IssueWizard Attachment Uploader', () => { |
| 11 | afterEach(cleanup); |
| 12 | |
| 13 | it('render', () => { |
| 14 | render(<AttachmentUploader files={[]} setFiles={()=>{}}/>) |
| 15 | const uploadButton = document.getElementById('file-uploader'); |
| 16 | assert.isNotNull(uploadButton); |
| 17 | }); |
| 18 | |
| 19 | it('render files name', () => { |
| 20 | const files = [ |
| 21 | {name: '1.txt'}, |
| 22 | {name: '2.txt'}, |
| 23 | {name: '3.txt'}, |
| 24 | ]; |
| 25 | render(<AttachmentUploader files={files} setFiles={()=>{}}/>) |
| 26 | const items = document.querySelectorAll('li'); |
| 27 | assert.equal(items.length, 3); |
| 28 | |
| 29 | assert.include(items[0].textContent, '1.txt'); |
| 30 | assert.include(items[1].textContent, '2.txt'); |
| 31 | assert.include(items[2].textContent, '3.txt'); |
| 32 | }); |
| 33 | |
| 34 | it('remove files', () => { |
| 35 | let files = [ |
| 36 | {name: '1.txt'}, |
| 37 | {name: '2.txt'}, |
| 38 | {name: '3.txt'}, |
| 39 | ]; |
| 40 | render(<AttachmentUploader files={files} setFiles={(f: Array<any>)=>{files = f;}} setSubmitEnable={()=>{}}/>) |
| 41 | const items = document.querySelectorAll('li'); |
| 42 | assert.equal(items.length, 3); |
| 43 | |
| 44 | const removeButton = items[1].querySelector('button'); |
| 45 | assert.isNotNull(removeButton); |
| 46 | |
| 47 | removeButton?.click(); |
| 48 | assert.equal(files.length, 2); |
| 49 | assert.equal(files[0].name, '1.txt'); |
| 50 | assert.equal(files[1].name, '3.txt'); |
| 51 | }) |
| 52 | }); |