github.com/minio/console@v1.4.1/web-app/tests/permissions-6/filePreview.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2023 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import * as roles from "../utils/roles"; 18 import { Selector } from "testcafe"; 19 import * as functions from "../utils/functions"; 20 import { namedTestBucketBrowseButtonFor } from "../utils/functions"; 21 22 fixture("Test Preview page in Console").page("http://localhost:9090/"); 23 24 const bucketName = "preview"; 25 export const file = Selector(".ReactVirtualized__Table__rowColumn").withText( 26 "internode.png", 27 ); 28 export const fileScript = Selector( 29 ".ReactVirtualized__Table__rowColumn", 30 ).withText("filescript.pdf"); 31 32 export const pdfFile = Selector(".ReactVirtualized__Table__rowColumn").withText( 33 "file1.pdf", 34 ); 35 36 const bucketNameAction = namedTestBucketBrowseButtonFor(bucketName); 37 38 test 39 .before(async (t) => { 40 await functions.setUpNamedBucket(t, bucketName); 41 await functions.uploadNamedObjectToBucket( 42 t, 43 bucketName, 44 "internode.png", 45 "web-app/tests/uploads/internode.png", 46 ); 47 })("File can be previewed", async (t) => { 48 await t 49 .useRole(roles.admin) 50 .navigateTo(`http://localhost:9090/browser`) 51 .click(bucketNameAction) 52 .click(file) 53 .click(Selector(".objectActions button").withText("Preview")) 54 .expect(Selector(".dialogContent > div > img").exists) 55 .ok(); 56 }) 57 .after(async (t) => { 58 await functions.cleanUpNamedBucketAndUploads(t, bucketName); 59 }); 60 61 test 62 .before(async (t) => { 63 await functions.setUpNamedBucket(t, bucketName); 64 await functions.uploadNamedObjectToBucket( 65 t, 66 bucketName, 67 "file1.pdf", 68 "web-app/tests/uploads/file1.pdf", 69 ); 70 })("PDF File can be previewed", async (t) => { 71 await t 72 .useRole(roles.admin) 73 .navigateTo(`http://localhost:9090/browser`) 74 .click(bucketNameAction) 75 .click(pdfFile) 76 .click(Selector(".objectActions button").withText("Preview")) 77 .expect(Selector(".react-pdf__Page__canvas").exists) 78 .ok(); 79 }) 80 .after(async (t) => { 81 await functions.cleanUpNamedBucketAndUploads(t, bucketName); 82 }); 83 84 test 85 .before(async (t) => { 86 await functions.setUpNamedBucket(t, bucketName); 87 await functions.uploadNamedObjectToBucket( 88 t, 89 bucketName, 90 "filescript.pdf", 91 "web-app/tests/uploads/filescript.pdf", 92 ); 93 })("PDF with Alert doesn't execute script", async (t) => { 94 await t 95 .useRole(roles.admin) 96 .navigateTo(`http://localhost:9090/browser`) 97 .click(bucketNameAction) 98 .click(fileScript) 99 .click(Selector(".objectActions button").withText("Preview")) 100 .setNativeDialogHandler(() => false); 101 102 const history = await t.getNativeDialogHistory(); 103 104 await t.expect(history.length).eql(0); 105 }) 106 .after(async (t) => { 107 await functions.cleanUpNamedBucketAndUploads(t, bucketName); 108 });