Skip to content

Commit

Permalink
File Radar Extension (jupyter-server#158)
Browse files Browse the repository at this point in the history
* add file radar extension

* add extension to plugin list

* explicitly calculate coverage from all files

* jest config point at ts

* working tests

* remove unnecessary testing logic

* add yarn.lock back in and remove unused imports in test/utils

* bump test coverage threshold
  • Loading branch information
Zsailer authored and GitHub Enterprise committed Sep 17, 2021
1 parent 7de0c65 commit e073208
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ config.coverageThreshold = {
global: {
functions: 90,
lines: 85,
statements: -15
statements: -20
}
};
config.collectCoverageFrom = ['src/**/*.{ts,tsx}'];

module.exports = config;
37 changes: 37 additions & 0 deletions src/fileradar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IMainMenu } from '@jupyterlab/mainmenu';

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

/**
* Build an external links menu item.
*/
export const FileRadarPlugin: JupyterFrontEndPlugin<void> = {
id: 'data_studio:file_radar_plugin',
autoStart: true,
requires: [IMainMenu],
activate: (app: JupyterFrontEnd, mainMenu: IMainMenu) => {
console.log('JupyterLab extension "File Radar" is activated!');

const radarUrl =
'rdar://new/problem/component=ACI%20Data%20Studio&version=Support';
const commandID = 'help:file-radar';

app.commands.addCommand(commandID, {
label: 'File a Radar',
isEnabled: () => true,
isVisible: () => true,
execute: () => {
window.open(radarUrl);
}
});

mainMenu.helpMenu.addGroup([
{
command: commandID
}
]);
}
};
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application';

import { ExternalLinksPlugin } from './externallinks';
import { kernelStatusPlugin } from './status';
import { FileRadarPlugin } from './fileradar';

const plugins: JupyterFrontEndPlugin<any>[] = [
kernelStatusPlugin,
ExternalLinksPlugin
ExternalLinksPlugin,
FileRadarPlugin
];

export default plugins;
65 changes: 65 additions & 0 deletions test/fileradar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// import { CommandRegistry } from '@lumino/commands';

import { JupyterLab } from '@jupyterlab/application';

import { MainMenu } from '@jupyterlab/mainmenu';
import { CommandRegistry } from '@lumino/commands';
import { JupyterServer } from '@jupyterlab/testutils';

import { FileRadarPlugin } from '../src/fileradar';

jest.useFakeTimers(); // Keep at the Top of the file
const server = new JupyterServer();

beforeAll(async () => {
jest.setTimeout(20000);
await server.start();
});

afterAll(async () => {
await server.shutdown();
});

describe('status', () => {
let app: JupyterLab;
let registry: CommandRegistry;
let mainMenu: MainMenu;

beforeEach(async () => {
// Wait for the server to start before creating the application
// so we pick up the page config (base url, etc.)
app = new JupyterLab();
registry = app.commands;
mainMenu = new MainMenu(registry);
});

it('should handle file radar link', () => {
FileRadarPlugin.activate(app, mainMenu);
const registry = app.commands;
const helpMenu = mainMenu.helpMenu;
const commandID = 'help:file-radar';

// Assert that the command is registered when the
// extension is activated.
expect(registry.hasCommand(commandID)).toEqual(true);
// Assert that the helpmenu includes the new item.
expect(helpMenu.items).toEqual(
expect.arrayContaining([expect.objectContaining({ command: commandID })])
);

// Set up a spy to see if the window opens
// a radar.
const closeSpy = jest.fn();
window.open = jest.fn().mockReturnValue({ close: closeSpy });
window.close = jest.fn();

// Execute the command and assert that a radar is opened.
registry.execute(commandID);
expect(window.open).toHaveBeenCalled();
expect(window.open).toHaveBeenCalledWith(
'rdar://new/problem/component=ACI%20Data%20Studio&version=Support'
);

jest.runAllTimers();
});
});
1 change: 0 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@jupyterlab/notebook';

import { NBTestUtils } from '@jupyterlab/testutils';

/**
* Create a notebook widget factory.
*/
Expand Down

0 comments on commit e073208

Please sign in to comment.