Skip to content
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
66 changes: 66 additions & 0 deletions __test__/projects/getProjectSelectionFromPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,69 @@ test("It moves specification ID to version ID if needed", () => {
expect(sut.version!.id).toEqual("bar/baz")
expect(sut.specification!.id).toEqual("hello")
})

test("It supports specifications with spaces in their names", () => {
const sut = getProjectSelectionFromPath({
path: "/acme/foo/main/openapi with spaces.yml",
projects: [
{
id: 'acme-foo',
name: 'foo',
displayName: "Ulrik's Playground",
versions: [{
id: 'main',
name: 'main',
specifications: [{
id: "openapi with spaces.yml",
name: "openapi with spaces.yml",
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
}],
url: 'https://github.com/acme/foo-openapi/tree/main',
isDefault: true
}],
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
url: 'https://github.com/acme/foo-openapi',
owner: 'acme',
ownerUrl: 'https://github.com/acme'
}
]
})
expect(sut.project!.owner).toEqual("acme")
expect(sut.project!.name).toEqual("foo")
expect(sut.version!.id).toEqual("main")
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
})

test("It supports specifications with URL-encoded spaces in their names", () => {
const sut = getProjectSelectionFromPath({
path: "/acme/foo/main/openapi%20with%20spaces.yml",
projects: [
{
id: 'acme-foo',
name: 'foo',
displayName: "Ulrik's Playground",
versions: [{
id: 'main',
name: 'main',
specifications: [{
id: "openapi with spaces.yml",
name: "openapi with spaces.yml",
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
}],
url: 'https://github.com/acme/foo-openapi/tree/main',
isDefault: true
}],
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
url: 'https://github.com/acme/foo-openapi',
owner: 'acme',
ownerUrl: 'https://github.com/acme'
}
]
})
expect(sut.project!.owner).toEqual("acme")
expect(sut.project!.name).toEqual("foo")
expect(sut.version!.id).toEqual("main")
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function getProjectSelectionFromPath({
if (path.startsWith("/")) {
path = path.substring(1)
}
path = decodeURIComponent(path)
const { owner: _owner, projectName: _projectName, versionId, specificationId } = guessSelection(path)
// If no project is selected and the user only has a single project then we select that.
let owner = _owner
Expand Down
Loading