44 */
55
66import { expect , test } from '@jupyterlab/galata' ;
7+ import { readFile } from 'fs/promises' ;
8+
9+ import { isBlank , isValidJSON } from './utils' ;
10+
11+ const licenseFormats = [
12+ {
13+ name : 'Markdown' ,
14+ extension : 'md' ,
15+ validation : ( value : string ) => ! isBlank ( value )
16+ } ,
17+ {
18+ name : 'CSV' ,
19+ extension : 'csv' ,
20+ validation : ( value : string ) => ! isBlank ( value )
21+ } ,
22+ { name : 'JSON' , extension : 'json' , validation : isValidJSON }
23+ ] ;
724
825test ( 'Switch back and forth to reference page' , async ( { page } ) => {
926 // The goal is to test switching back and forth with a tab containing an iframe
@@ -30,3 +47,29 @@ test('Switch back and forth to reference page', async ({ page }) => {
3047 page . locator ( '.jp-MarkdownCell .jp-InputArea-editor' )
3148 ) . toHaveText ( cellContent ) ;
3249} ) ;
50+
51+ test . describe ( 'Licenses' , ( ) => {
52+ licenseFormats . forEach ( licenseFormat => {
53+ test ( `Exporting licenses as ${ licenseFormat . name } must download a ${ licenseFormat . name } file` , async ( {
54+ page
55+ } ) => {
56+ await page . menu . clickMenuItem ( 'Help>Licenses' ) ;
57+
58+ const downloadPromise = page . waitForEvent ( 'download' ) ;
59+ await page
60+ . getByRole ( 'button' , {
61+ name : `Download All Licenses as ${ licenseFormat . name } `
62+ } )
63+ . click ( ) ;
64+ const download = await downloadPromise ;
65+
66+ const fileName = download . suggestedFilename ( ) ;
67+ const fileContent = await readFile ( await download . path ( ) , {
68+ encoding : 'utf8'
69+ } ) ;
70+
71+ expect ( fileName ) . toBe ( `jupyterlab-licenses.${ licenseFormat . extension } ` ) ;
72+ expect ( licenseFormat . validation ( fileContent ) ) . toBeTruthy ( ) ;
73+ } ) ;
74+ } ) ;
75+ } ) ;
0 commit comments