Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate nbgrader widgets after they are disposed. #1773

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,33 @@ test('Open assignment list tab from menu', async({
page
}) => {

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(1);
// Check main menu exists
await expect(page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")')).toHaveCount(1);
await page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")').click();
const nbgrader_menu = page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")');
const assignmentList_menu = page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-assignment-list"]');
const tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
const lastTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");

await page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-assignment-list"]').click();
await expect(tabs).toHaveCount(1);

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(2);
// Check main menu exists
await expect(nbgrader_menu).toHaveCount(1);

var tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
var newTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");
await expect(newTab_label).toHaveText("Assignments");
// Open assignment list from the menu
await nbgrader_menu.click();
await assignmentList_menu.click();

await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Assignments");

// Close the last tab
await tabs.last().locator(".jp-icon-hover.lm-TabBar-tabCloseIcon").click();
await expect(tabs).toHaveCount(1);

// Open again
await nbgrader_menu.click();
await assignmentList_menu.click();

await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Assignments");
});

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,33 @@ test('Open course list tab from menu', async({
page
}) => {

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(1);
const nbgrader_menu = page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")');
const courseList_menu = page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-course-list"]');
const tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
const lastTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");

await expect(tabs).toHaveCount(1);

// Check main menu exists
await expect(page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")')).toHaveCount(1);
await page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")').click();
await expect(nbgrader_menu).toHaveCount(1);

await page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-course-list"]').click();
// Open course list from the menu
await nbgrader_menu.click();
await courseList_menu.click();

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(2);
await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Courses");

var tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
var newTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");
await expect(newTab_label).toHaveText("Courses");
// Close the last tab
await tabs.last().locator(".jp-icon-hover.lm-TabBar-tabCloseIcon").click();
await expect(tabs).toHaveCount(1);

// Open again
await nbgrader_menu.click();
await courseList_menu.click();

await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Courses");

});

Expand Down
31 changes: 23 additions & 8 deletions nbgrader/tests/labextension_ui-tests/tests/test_formgrader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,33 @@ test('Open assignment list tab from menu', async({
page
}) => {

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(1);
const nbgrader_menu = page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")');
const formgrader_menu = page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-formgrader"]');
const tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
const lastTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");

await expect(tabs).toHaveCount(1);

// Check main menu exists
await expect(page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")')).toHaveCount(1);
await page.locator('#jp-menu-panel div.lm-MenuBar-itemLabel.p-MenuBar-itemLabel:text("Nbgrader")').click();
await expect(nbgrader_menu).toHaveCount(1);

// Open course list from the menu
await nbgrader_menu.click();
await formgrader_menu.click();

await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Formgrader");

await page.locator('#jp-mainmenu-nbgrader-menu li[data-command="nbgrader:open-formgrader"]').click();
// Close the last tab
await tabs.last().locator(".jp-icon-hover.lm-TabBar-tabCloseIcon").click();
await expect(tabs).toHaveCount(1);

await expect(page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab")).toHaveCount(2);
// Open again
await nbgrader_menu.click();
await formgrader_menu.click();

var tabs = page.locator("#jp-main-dock-panel .lm-TabBar-tab.p-TabBar-tab");
var newTab_label = tabs.last().locator(".lm-TabBar-tabLabel.p-TabBar-tabLabel");
await expect(newTab_label).toHaveText("Formgrader");
await expect(tabs).toHaveCount(2);
await expect(lastTab_label).toHaveText("Formgrader");

});

Expand Down
2 changes: 1 addition & 1 deletion src/assignment_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const assignment_list_extension: JupyterFrontEndPlugin<void> = {
app.commands.addCommand(command,{
label: 'Assignment List',
execute: () => {
if(!widget){
if(!widget || widget.isDisposed){
const content = new AssignmentListWidget(app);
widget = new MainAreaWidget({content});
widget.id = 'nbgrader-assignment-list';
Expand Down
2 changes: 1 addition & 1 deletion src/course_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const course_list_extension: JupyterFrontEndPlugin<void> = {
app.commands.addCommand(command, {
label: 'Course List',
execute: () => {
if (!widget) {
if (!widget || widget.isDisposed) {
const content = new CourseListWidget(app);
widget = new MainAreaWidget({content});
widget.id = 'nbgrader-course-list'
Expand Down
2 changes: 1 addition & 1 deletion src/formgrader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const formgrader_extension: JupyterFrontEndPlugin<void> = {
app.commands.addCommand(command,{
label: 'Formgrader',
execute: async args => {
if(!widget){
if(!widget || widget.isDisposed){
const settings = ServerConnection.makeSettings();
const url = (args.url as string) || URLExt.join(settings.baseUrl, "formgrader");

Expand Down