Skip to content

Commit

Permalink
Merge pull request #1654 from cardstack/cs-7308-realm-chooser-dropdow…
Browse files Browse the repository at this point in the history
…n-in-new-card-defintion-modal-should

Realm chooser drop down should default to currently displayed realm if it is writable
  • Loading branch information
habdelra authored Oct 4, 2024
2 parents e3912b1 + c424910 commit 0bfe82a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
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

0 comments on commit 0bfe82a

Please sign in to comment.