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

Realm chooser drop down should default to currently displayed realm if it is writable #1654

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/host/app/components/operator-mode/code-submode.gts
Original file line number Diff line number Diff line change
Expand Up @@ -611,16 +611,16 @@ export default class CodeSubmode extends Component<Signature> {

if (sourceInstance && this.realm.canWrite(sourceInstance.id)) {
destinationRealm = this.realm.url(sourceInstance.id);
}

if (
} else if (
definitionClass?.ref &&
this.realm.canWrite(definitionClass.ref.module)
) {
destinationRealm = this.realm.url(definitionClass.ref.module);
}

if (!destinationRealm && this.realm.defaultWritableRealm) {
} else if (
this.realm.canWrite(this.operatorModeStateService.realmURL.href)
) {
destinationRealm = this.operatorModeStateService.realmURL.href;
} else if (this.realm.defaultWritableRealm) {
destinationRealm = this.realm.defaultWritableRealm.path;
}

Expand Down
41 changes: 38 additions & 3 deletions packages/host/tests/acceptance/code-submode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,30 @@ const notFoundAdoptionInstance = `{

module('Acceptance | code submode tests', function (_hooks) {
module('multiple realms', function (hooks) {
let personalRealmURL: string;
let additionalRealmURL: string;
let catalogRealmURL: string;

setupApplicationTest(hooks);
setupLocalIndexing(hooks);
setupServerSentEvents(hooks);
let { setActiveRealms } = setupMockMatrix(hooks, {
loggedInAs: '@testuser:staging',
});

async function openNewFileModal(menuSelection: string) {
await waitFor('[data-test-new-file-button]');
await click('[data-test-new-file-button]');
await click(`[data-test-boxel-menu-item-text="${menuSelection}"]`);
}

hooks.beforeEach(async function () {
let realmServerService = this.owner.lookup(
'service:realm-server',
) as RealmServerService;
const personalRealmURL = `${realmServerService.url}testuser/personal/`;
const additionalRealmURL = `${realmServerService.url}testuser/aaa/`; // writeable realm that is lexically before the personal realm
const catalogRealmURL = `${realmServerService.url}catalog/`;
personalRealmURL = `${realmServerService.url}testuser/personal/`;
additionalRealmURL = `${realmServerService.url}testuser/aaa/`; // writeable realm that is lexically before the personal realm
catalogRealmURL = `${realmServerService.url}catalog/`;
setActiveRealms([catalogRealmURL, additionalRealmURL, personalRealmURL]);

await setupAcceptanceTestRealm({
Expand Down Expand Up @@ -475,6 +485,31 @@ module('Acceptance | code submode tests', function (_hooks) {
.dom('[data-test-card-url-bar-realm-info]')
.containsText(`in Test User's Workspace`);
});

test('first item in add file realm dropdown is the currently displayed realm', async function (assert) {
await visitOperatorMode({
submode: 'code',
});

await waitFor('[data-test-file]');
await openNewFileModal('Card Definition');
assert
.dom('[data-test-selected-realm]')
.containsText(
`Test User's Workspace`,
'the selected (default) realm is correct',
);
await click('[data-test-cancel-create-file]');

await visitOperatorMode({
submode: 'code',
codePath: `${additionalRealmURL}hello.txt`,
});
await openNewFileModal('Card Definition');
assert
.dom('[data-test-selected-realm]')
.containsText(`Additional Workspace`, 'the selected realm is correct');
});
});

module('single realm', function (hooks) {
Expand Down