Skip to content

Commit bd11b85

Browse files
jvigliottaakhenry
authored andcommitted
[Notebook] Browse Bar holding onto stale model, reverts changes (#7944)
* moving rename methods to appActions * importing back into original test * reverting * add the ability to change the name in the browse bar * add test to verify entries are not being lost * addding aria labels for tests * when an object is changed, store the whole new object, not just the name * typo!
1 parent db9c923 commit bd11b85

File tree

4 files changed

+86
-11
lines changed

4 files changed

+86
-11
lines changed

e2e/appActions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,21 @@ async function linkParameterToObject(page, parameterName, objectName) {
682682
await page.getByLabel('Save').click();
683683
}
684684

685+
/**
686+
* Rename the currently viewed `domainObject` from the browse bar.
687+
*
688+
* @param {import('@playwright/test').Page} page
689+
* @param {string} newName
690+
*/
691+
async function renameCurrentObjectFromBrowseBar(page, newName) {
692+
const nameInput = page.getByLabel('Browse bar object name');
693+
await nameInput.click();
694+
await nameInput.fill('');
695+
await nameInput.fill(newName);
696+
// Click the browse bar container to save changes
697+
await page.getByLabel('Browse bar', { exact: true }).click();
698+
}
699+
685700
export {
686701
createDomainObjectWithDefaults,
687702
createExampleTelemetryObject,
@@ -693,6 +708,7 @@ export {
693708
linkParameterToObject,
694709
navigateToObjectWithFixedTimeBounds,
695710
navigateToObjectWithRealTime,
711+
renameCurrentObjectFromBrowseBar,
696712
setEndOffset,
697713
setFixedIndependentTimeConductorBounds,
698714
setFixedTimeMode,

e2e/tests/functional/plugins/notebook/notebook.e2e.spec.js

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ This test suite is dedicated to tests which verify the basic operations surround
2626

2727
import { fileURLToPath } from 'url';
2828

29-
import { createDomainObjectWithDefaults } from '../../../../appActions.js';
29+
import {
30+
createDomainObjectWithDefaults,
31+
renameCurrentObjectFromBrowseBar
32+
} from '../../../../appActions.js';
3033
import { copy, paste, selectAll } from '../../../../helper/hotkeys/hotkeys.js';
3134
import * as nbUtils from '../../../../helper/notebookUtils.js';
3235
import { expect, streamToString, test } from '../../../../pluginFixtures.js';
@@ -596,4 +599,61 @@ test.describe('Notebook entry tests', () => {
596599
await expect(await page.locator(`text="${TEST_TEXT.repeat(1)}"`).count()).toEqual(1);
597600
await expect(await page.locator(`text="${TEST_TEXT.repeat(2)}"`).count()).toEqual(0);
598601
});
602+
603+
test('When changing the name of a notebook in the browse bar, new notebook changes are not lost', async ({
604+
page
605+
}) => {
606+
const TEST_TEXT = 'Do not lose me!';
607+
const FIRST_NEW_NAME = 'New Name';
608+
const SECOND_NEW_NAME = 'Second New Name';
609+
610+
await page.goto(notebookObject.url);
611+
612+
await page.getByLabel('Expand My Items folder').click();
613+
614+
await renameCurrentObjectFromBrowseBar(page, FIRST_NEW_NAME);
615+
616+
// verify the name change in tree and browse bar
617+
await verifyNameChange(page, FIRST_NEW_NAME);
618+
619+
// enter one entry
620+
await enterAndCommitTextEntry(page, TEST_TEXT);
621+
622+
// verify the entry is present
623+
await expect(await page.locator(`text="${TEST_TEXT}"`).count()).toEqual(1);
624+
625+
// change the name
626+
await renameCurrentObjectFromBrowseBar(page, SECOND_NEW_NAME);
627+
628+
// verify the name change in tree and browse bar
629+
await verifyNameChange(page, SECOND_NEW_NAME);
630+
631+
// verify the entry is still present
632+
await expect(await page.locator(`text="${TEST_TEXT}"`).count()).toEqual(1);
633+
});
599634
});
635+
636+
/**
637+
* Enter text into the last notebook entry and commit it.
638+
*
639+
* @param {import('@playwright/test').Page} page
640+
* @param {string} text
641+
*/
642+
async function enterAndCommitTextEntry(page, text) {
643+
await nbUtils.addNotebookEntry(page);
644+
await nbUtils.enterTextInLastEntry(page, text);
645+
await nbUtils.commitEntry(page);
646+
}
647+
648+
/**
649+
* Verify the name change in the tree and browse bar.
650+
*
651+
* @param {import('@playwright/test').Page} page
652+
* @param {string} newName
653+
*/
654+
async function verifyNameChange(page, newName) {
655+
await expect(
656+
page.getByRole('treeitem').locator('.is-navigated-object .c-tree__item__name')
657+
).toHaveText(newName);
658+
await expect(page.getByLabel('Browse bar object name')).toHaveText(newName);
659+
}

src/ui/layout/BrowseBar.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
at runtime from the About dialog for additional information.
2121
-->
2222
<template>
23-
<div class="l-browse-bar">
23+
<div class="l-browse-bar" aria-label="Browse bar">
2424
<div class="l-browse-bar__start">
2525
<button
2626
v-if="hasParent"
@@ -35,6 +35,7 @@
3535
</div>
3636
<span
3737
ref="objectName"
38+
aria-label="Browse bar object name"
3839
class="l-browse-bar__object-name c-object-label__name"
3940
:class="{ 'c-input-inline': isPersistable }"
4041
:contenteditable="isNameEditable"

src/ui/router/Browse.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ class Browse {
8080
this.#openmct.layout.$refs.browseBar.viewKey = viewProvider.key;
8181
}
8282

83-
#updateDocumentTitleOnNameMutation(newName) {
84-
if (typeof newName === 'string' && newName !== document.title) {
85-
document.title = newName;
86-
this.#openmct.layout.$refs.browseBar.domainObject = {
87-
...this.#openmct.layout.$refs.browseBar.domainObject,
88-
name: newName
89-
};
83+
#handleBrowseObjectUpdate(newObject) {
84+
this.#openmct.layout.$refs.browseBar.domainObject = newObject;
85+
86+
if (typeof newObject.name === 'string' && newObject.name !== document.title) {
87+
document.title = newObject.name;
9088
}
9189
}
9290

@@ -120,8 +118,8 @@ class Browse {
120118
document.title = this.#browseObject.name; //change document title to current object in main view
121119
this.#unobserve = this.#openmct.objects.observe(
122120
this.#browseObject,
123-
'name',
124-
this.#updateDocumentTitleOnNameMutation.bind(this)
121+
'*',
122+
this.#handleBrowseObjectUpdate.bind(this)
125123
);
126124
const currentProvider = this.#openmct.objectViews.getByProviderKey(currentViewKey);
127125
if (currentProvider && currentProvider.canView(this.#browseObject, this.#openmct.router.path)) {

0 commit comments

Comments
 (0)