Skip to content

fix: Display correct page after renaming org slug #2659

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

Merged
merged 2 commits into from
Jun 10, 2025
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
17 changes: 17 additions & 0 deletions frontend/src/__mocks__/api/users/me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mockAPIUser = {
id: "740d7b63-b257-4311-ba3f-adc46a5fafb8",
email: "test-user@example.com",
name: "Test User",
is_verified: false,
is_superuser: false,
orgs: [
{
id: "e21ab647-2d0e-489d-97d1-88ac91774942",
name: "test org",
slug: "test-org",
role: 10,
},
],
};

export default mockAPIUser;
46 changes: 46 additions & 0 deletions frontend/src/pages/org/settings/components/general.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect, fixture } from "@open-wc/testing";
import { html } from "lit";
import { restore, stub } from "sinon";

import "./general";

import type { OrgSettingsGeneral } from "./general";

import mockAPIUser from "@/__mocks__/api/users/me.js";
import { AppStateService } from "@/utils/state";

describe("btrix-org-settings-general", () => {
beforeEach(() => {
AppStateService.resetAll();
window.localStorage.clear();
window.sessionStorage.clear();
stub(window.history, "pushState");
});

afterEach(() => {
restore();
});

describe("#renameOrg", () => {
it("redirects to the correct page", async () => {
const el = await fixture<OrgSettingsGeneral>(
html`<btrix-org-settings-general></btrix-org-settings-general>`,
);

stub(el.navigate, "to");
stub(el.api, "fetch").callsFake(async (path) => {
if (path === "/users/me") {
return Promise.resolve(mockAPIUser);
}
return Promise.resolve({});
});

// @ts-expect-error renameOrg is private
await el.renameOrg({ name: "Fake Org Name 2", slug: "fake-org-name-2" });

expect(el.navigate.to).to.have.been.calledWith(
"/orgs/fake-org-name-2/settings",
);
});
});
});
2 changes: 0 additions & 2 deletions frontend/src/pages/org/settings/components/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ export class OrgSettingsGeneral extends BtrixElement {

AppStateService.updateUser(formatAPIUser(user), slug);

await this.updateComplete;

this.navigate.to(`${this.navigate.orgBasePath}/settings`);
}

Expand Down
Loading