import { AppRoute } from "../../routes.defs";
import { default as buildRouteLink } from "./buildRouteLink";
describe("buildRouteLink", () => {
it(`should return path from route without transform when it gets called with a null as routeParams argument`, () => {
const routeName: AppRoute = AppRoute.HOME;
const link = buildRouteLink(routeName, null);
expect(link).toMatchInlineSnapshot(`"/"`);
});
it(`should return path from route without transform when it gets called with an empty object as routeParams argument`, () => {
const routeName: AppRoute = AppRoute.HOME;
const link = buildRouteLink(routeName, {});
expect(link).toMatchInlineSnapshot(`"/"`);
});
it(`should return path from route with params values when it gets called with an object containing values as routeParams argument`, () => {
const routeName: AppRoute = AppRoute.ORGANIZATION_DETAILS;
const link = buildRouteLink(routeName, {
orgSlug: "my-super-org",
});
expect(link).toMatchInlineSnapshot(`"/my-super-org"`);
});
it(`should return path from route with params values when it gets called with an object containing values and magic "*" value as routeParams argument`, () => {
const routeName: AppRoute = AppRoute.REPOSITORY_BROWSER_WITH_PATH;
const link = buildRouteLink(routeName, {
orgSlug: "my-super-org",
repoSlug: "my-super-repo",
currentRef: "main",
"*": "app.manifest.json",
});
expect(link).toMatchInlineSnapshot(
`"/my-super-org/my-super-repo/main/tree/app.manifest.json"`
);
});
it(`should return path from route with url encoded params values when it gets called with an object containing values as routeParams argument`, () => {
const routeName: AppRoute = AppRoute.REPOSITORY_BROWSER_WITH_PATH;
const link = buildRouteLink(routeName, {
orgSlug: "my-super-org",
repoSlug: "my-super-repo",
currentRef: "main",
"*": "app/services/auth/isExistingEmailAddress.ts",
});
expect(link).toMatchInlineSnapshot(
`"/my-super-org/my-super-repo/main/tree/app%2Fservices%2Fauth%2FisExistingEmailAddress.ts"`
);
});
it(`should return path from route with url encoded params values when it gets called without an options object`, () => {
const routeName: AppRoute = AppRoute.USER_DETAILS;
const link = buildRouteLink(routeName, {
username: "test-user",
});
expect(link).toMatchInlineSnapshot(`"/%40test-user"`);
});
it(`should return path from route with url encoded params values when it gets called with options.encodeURIComponent is set to true`, () => {
const routeName: AppRoute = AppRoute.USER_DETAILS;
const link = buildRouteLink(
routeName,
{
username: "test-user",
},
{ encodeURIComponent: true }
);
expect(link).toMatchInlineSnapshot(`"/%40test-user"`);
});
it(`should return path from route WITHOUT url encoded params values when it gets called with options.encodeURIComponent is set to false`, () => {
const routeName: AppRoute = AppRoute.USER_DETAILS;
const link = buildRouteLink(
routeName,
{
username: "test-user",
},
{ encodeURIComponent: false }
);
expect(link).toMatchInlineSnapshot(`"/@test-user"`);
});
});
describe("buildPathLink", () => {});