Skip to content

Commit be34cd3

Browse files
Backport PR #16584: Fix the identifier to download licenses in JSON format (#16592)
Co-authored-by: João Palmeiro <joaommpalmeiro@gmail.com>
1 parent 2521f5e commit be34cd3

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

galata/test/jupyterlab/help.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
*/
55

66
import { 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

825
test('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+
});

galata/test/jupyterlab/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,22 @@ export async function dragCellTo(
7373
await page.waitForCondition(options.stopCondition);
7474
await page.mouse.up();
7575
}
76+
77+
/**
78+
* Check if a given string value is valid JSON.
79+
*/
80+
export function isValidJSON(value: string): boolean {
81+
try {
82+
JSON.parse(value);
83+
return true;
84+
} catch (e) {
85+
return false;
86+
}
87+
}
88+
89+
/**
90+
* Check if a given string value is empty (excluding spaces).
91+
*/
92+
export function isBlank(value: string): boolean {
93+
return value.trim().length === 0;
94+
}

packages/help-extension/src/licenses.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export namespace Licenses {
183183
icon: spreadsheetIcon
184184
},
185185
json: {
186-
id: 'csv',
186+
id: 'json',
187187
title: 'JSON',
188188
icon: jsonIcon
189189
}

0 commit comments

Comments
 (0)