Skip to content

Commit

Permalink
fixing feedback from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
wrt95 committed Dec 18, 2023
1 parent ef0c588 commit c6dc8dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ const mockApp: string = 'app';

describe('PackagesRouter', () => {
describe('constructor', () => {
it('should initialize app and org properties', () => {
const packagesRouter = new PackagesRouter({ org: mockOrg, app: mockApp });

expect(packagesRouter['app']).toEqual(mockApp);
expect(packagesRouter['org']).toEqual(mockOrg);
});

it('should default to empty strings if app and org are not provided', () => {
const routerWithoutParams = new PackagesRouter({});
expect(routerWithoutParams['app']).toEqual('');
Expand All @@ -20,7 +13,7 @@ describe('PackagesRouter', () => {
});

describe('navigateToPackage', () => {
it('should navigate to the correct URL without subUrl', () => {
it('should navigate to the correct "editor/overview page when the location parameter is set to "editorOverview"', () => {
const packagesRouter = new PackagesRouter({ org: mockOrg, app: mockApp });
const expectedUrl = `/editor/${mockOrg}/${mockApp}/overview`;

Expand All @@ -36,19 +29,19 @@ describe('PackagesRouter', () => {
expect(assignMock).toHaveBeenCalledWith(expectedUrl);
});

it('should navigate to the correct URL with subUrl', () => {
it('should navigate to the correct URL and include queryParams', () => {
const packagesRouter = new PackagesRouter({ org: mockOrg, app: mockApp });

const mockSubUrl = '?layout=123';
const expectedUrl = `/editor/${mockOrg}/${mockApp}/ui-editor${mockSubUrl}`;
const mockQueryParams = '?layout=123';
const expectedUrl = `/editor/${mockOrg}/${mockApp}/ui-editor${mockQueryParams}`;

const assignMock = jest.fn();
Object.defineProperty(window, 'location', {
value: { assign: assignMock },
writable: true,
});

packagesRouter.navigateToPackage('editorUiEditor', mockSubUrl);
packagesRouter.navigateToPackage('editorUiEditor', mockQueryParams);

expect(assignMock).toHaveBeenCalledWith(expectedUrl);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type PackagesRoute =
| 'preview'
| 'editorPublish';

const packagesRoutes = {
const packagesRoutes: Record<PackagesRoute, string> = {
dashboard: '/dashboard',
editorOverview: '/editor/{{org}}/{{app}}/overview',
editorUiEditor: '/editor/{{org}}/{{app}}/ui-editor',
Expand All @@ -27,8 +27,8 @@ export class PackagesRouter {
this.org = this.paramsOptions.org ?? '';
}

public navigateToPackage(packageRoute: PackagesRoute, subUrl?: string): void {
window.location.assign(`${this.getPackageNavigationUrl(packageRoute)}${subUrl ? subUrl : ''}`);
public navigateToPackage(packageRoute: PackagesRoute, queryParams?: string): void {
window.location.assign(`${this.getPackageNavigationUrl(packageRoute)}${queryParams ?? ''}`);
}

public getPackageNavigationUrl(packageRoute: PackagesRoute): string {
Expand Down

0 comments on commit c6dc8dc

Please sign in to comment.