forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
765a2c4
commit 7b18f44
Showing
3 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { | ||
CustomEnvWidget, | ||
} from '@jupyterlab/ui-components'; | ||
import { framePromise, JupyterServer } from '@jupyterlab/testing'; | ||
import { PartialJSONObject, ReadonlyPartialJSONObject } from '@lumino/coreutils'; | ||
Check notice Code scanning / CodeQL Unused variable, import, function or class Note test
Unused import ReadonlyPartialJSONObject.
|
||
import { Widget } from '@lumino/widgets'; | ||
import { simulate } from 'simulate-event'; | ||
import { | ||
nullTranslator, | ||
} from '@jupyterlab/translation'; | ||
|
||
const server = new JupyterServer(); | ||
|
||
beforeAll(async () => { | ||
await server.start(); | ||
}, 30000); | ||
|
||
afterAll(async () => { | ||
await server.shutdown(); | ||
}); | ||
|
||
describe('@jupyterlab/ui-components', () => { | ||
describe('Custom env vars Widget', () => { | ||
let envConfiguration: PartialJSONObject = {}; | ||
let translator = nullTranslator; | ||
|
||
it('should render a widget', async () => { | ||
const widget = new CustomEnvWidget( | ||
envConfiguration, | ||
{}, | ||
formData => { | ||
envConfiguration = formData as PartialJSONObject; | ||
document.body.setAttribute( | ||
'data-custom-env-vars', | ||
JSON.stringify(envConfiguration) | ||
); | ||
}, | ||
true, | ||
translator | ||
); | ||
|
||
Widget.attach(widget, document.body); | ||
await framePromise(); | ||
let form = widget.node.getElementsByClassName('js-Dialog-form-custom-env').item(0); | ||
expect(form).not.toBeNull(); | ||
}); | ||
|
||
it('should render a checkbox for opening a widget', async () => { | ||
const widget = new CustomEnvWidget( | ||
envConfiguration, | ||
{}, | ||
formData => { | ||
envConfiguration = formData as PartialJSONObject; | ||
document.body.setAttribute( | ||
'data-custom-env-vars', | ||
JSON.stringify(envConfiguration) | ||
); | ||
}, | ||
false, | ||
translator | ||
); | ||
|
||
|
||
Widget.attach(widget, document.body); | ||
await framePromise(); | ||
await widget.renderPromise; | ||
let checkbox = widget.node.getElementsByClassName('jp-custom-env-vars-checkbox').item(0); | ||
simulate(checkbox as HTMLInputElement, 'change'); | ||
let form = widget.node.getElementsByClassName('js-Dialog-form-custom-env').item(0); | ||
expect(form).not.toBeNull(); | ||
}); | ||
|
||
it('should add more fields for setuping custom env variables', async () => { | ||
const widget = new CustomEnvWidget( | ||
envConfiguration, | ||
{}, | ||
formData => { | ||
envConfiguration = formData as PartialJSONObject; | ||
document.body.setAttribute( | ||
'data-custom-env-vars', | ||
JSON.stringify(envConfiguration) | ||
); | ||
}, | ||
true, | ||
translator | ||
); | ||
|
||
|
||
Widget.attach(widget, document.body); | ||
await framePromise(); | ||
await widget.renderPromise; | ||
let button = widget.node.getElementsByClassName('js-custom-env').item(0); | ||
if (button) { | ||
simulate(button as HTMLElement, 'click'); | ||
} else { | ||
throw new Error("There is no button"); | ||
} | ||
let form = widget.node.getElementsByClassName('js-Dialog-form-custom-env').item(0) as HTMLElement | null; | ||
if (!form) { | ||
throw new Error("There is no form for setuping custom env variables"); | ||
} else { | ||
const envNames = form.querySelectorAll('[data-name="env_name"]'); | ||
expect(envNames.length).toBe(2); | ||
} | ||
}); | ||
}); | ||
}); |