Skip to content

Commit

Permalink
Merge pull request #8118 from blink1073/fix-widget-tracker
Browse files Browse the repository at this point in the history
Fix Widget Tracker in 1.2.x
  • Loading branch information
Steven Silvester committed Mar 29, 2020
2 parents a3f96f2 + 4ae0616 commit 276951f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
name: Windows
strategy:
matrix:
group: [python, integrity, application, apputils, cells, codeeditor, codemirror, completer, console, coreutils, csvviewer, docmanager, docregistry, filebrowser, fileeditor, imageviewer, inspector, logconsole, mainmenu, nbformat, notebook, observables, outputarea, rendermime, services, settingregistry, statedb, statusbar, terminal, ui-components]
group: [javascript, python, integrity]
fail-fast: false
runs-on: windows-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions jupyterlab/browser_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def filter(self, record):
# known startup error message
if 'paste' in record.msg:
return
# handle known shutdown message
if 'Stream is closed' in record.msg:
return
return super().filter(record)

def emit(self, record):
Expand Down
4 changes: 2 additions & 2 deletions jupyterlab/tests/test_jupyterlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_install_and_uninstall_pinned_folder(self):
stdout=subprocess.PIPE,
universal_newlines=True,
check=True,
cwd=base_dir
cwd=str(base_dir)
).stdout.strip()
for name in self.pinned_packages
]
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_build_custom_minimal_core_config(self):
pkg = pjoin(app_dir, 'static', 'package.json')
with open(pkg) as fid:
data = json.load(fid)
assert list(data['jupyterlab']['extensions'].keys()) == [
assert sorted(data['jupyterlab']['extensions'].keys()) == [
'@jupyterlab/application-extension',
'@jupyterlab/apputils-extension',
'@jupyterlab/mock-extension',
Expand Down
8 changes: 7 additions & 1 deletion packages/apputils/src/widgettracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class WidgetTracker<T extends Widget = Widget>
pool.current = focus.currentWidget;
return;
}

this.onCurrentChanged(widget);
this._currentChanged.emit(widget);
}, this);
Expand Down Expand Up @@ -216,11 +217,16 @@ export class WidgetTracker<T extends Widget = Widget>
* the tracker can be checked with the `has()` method. The promise this method
* returns resolves after the widget has been added and saved to an underlying
* restoration connector, if one is available.
*
* The newly added widget becomes the current widget unless the focus tracker
* already had a focused widget.
*/
async add(widget: T): Promise<void> {
this._focusTracker.add(widget);
await this._pool.add(widget);
this._pool.current = widget;
if (!this._focusTracker.activeWidget) {
this._pool.current = widget;
}
}

/**
Expand Down
14 changes: 10 additions & 4 deletions scripts/ci_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ fi


if [[ $GROUP == docs ]]; then

# Run the link check - allow for a link to fail once
# Run the link check - allow for a link to fail once (--lf means only run last failed)
py.test --check-links -k .md . || py.test --check-links -k .md --lf .

# Build the docs
jlpm build:packages
jlpm docs

# Verify tutorial docs build
# Verify sphinx docs build
pushd docs
pip install sphinx sphinx-copybutton sphinx_rtd_theme recommonmark
make linkcheck
make html

# Remove internal sphinx files and use pytest-check-links on the generated html
rm build/html/genindex.html
rm build/html/search.html
py.test --check-links -k .html build/html || py.test --check-links -k .html --lf build/html

popd

fi


Expand Down Expand Up @@ -214,6 +219,7 @@ if [[ $GROUP == usage ]]; then
python -m jupyterlab.selenium_check

# Make sure we can non-dev install.
pip install virtualenv
virtualenv -p $(which python3) test_install
./test_install/bin/pip install -q ".[test]" # this populates <sys_prefix>/share/jupyter/lab
./test_install/bin/python -m jupyterlab.browser_check
Expand Down
43 changes: 41 additions & 2 deletions tests/test-apputils/src/widgettracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,54 @@ describe('@jupyterlab/apputils', () => {
});

describe('#currentChanged', () => {
it('should emit when the current widget has been updated', async () => {
it('should emit for the first added widget', async () => {
const widget = createWidget();
let promise = signalToPromise(tracker.currentChanged);
void tracker.add(widget);
await promise;
widget.dispose();
});

it('should emit when a widget is added and there is another widget that does not have focus', async () => {
const widget = createWidget();
const widget2 = createWidget();
await tracker.add(widget);
let promise = signalToPromise(tracker.currentChanged);
await tracker.add(widget2);
await promise;
widget.dispose();
widget2.dispose();
});

it('should not emit when a widget is added and there is another widget that has focus', async () => {
const widget = createWidget();
const widget2 = createWidget();
Widget.attach(widget, document.body);
focus(widget);
void tracker.add(widget);
await tracker.add(widget);
let called = false;
tracker.currentChanged.connect(() => {
called = true;
});
await tracker.add(widget2);
expect(called).to.equal(false);
widget.dispose();
widget2.dispose();
});

it('should emit when the focus changes', async () => {
const widget = createWidget();
const widget2 = createWidget();
Widget.attach(widget, document.body);
Widget.attach(widget2, document.body);
focus(widget);
await tracker.add(widget);
await tracker.add(widget2);
let promise = signalToPromise(tracker.currentChanged);
focus(widget2);
await promise;
widget.dispose();
widget2.dispose();
});
});

Expand Down

0 comments on commit 276951f

Please sign in to comment.