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
85 changes: 0 additions & 85 deletions __test__/common/utils/url.test.ts

This file was deleted.

24 changes: 9 additions & 15 deletions __test__/projects/getSelection.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getSelection } from "../../src/features/projects/domain"

test("It selects the first project when there is only one project", () => {
test("It selects the first project when there is only one project and path is empty", () => {
const sut = getSelection({
path: "",
projects: [{
id: "foo",
name: "foo",
Expand All @@ -25,7 +26,7 @@ test("It selects the first project when there is only one project", () => {

test("It selects the first version and specification of the specified project", () => {
const sut = getSelection({
projectId: "bar",
path: "/bar",
projects: [{
id: "foo",
name: "foo",
Expand Down Expand Up @@ -63,8 +64,7 @@ test("It selects the first version and specification of the specified project",

test("It selects the first specification of the specified project and version", () => {
const sut = getSelection({
projectId: "bar",
versionId: "baz2",
path: "/bar/baz2",
projects: [{
id: "foo",
name: "foo",
Expand Down Expand Up @@ -98,8 +98,7 @@ test("It selects the first specification of the specified project and version",

test("It selects the specification of the specified version", () => {
const sut = getSelection({
projectId: "bar",
versionId: "baz2",
path: "/bar/baz2",
projects: [{
id: "foo",
name: "foo",
Expand Down Expand Up @@ -137,9 +136,7 @@ test("It selects the specification of the specified version", () => {

test("It selects the specified project, version, and specification", () => {
const sut = getSelection({
projectId: "bar",
versionId: "baz2",
specificationId: "hello2",
path: "/bar/baz2/hello2",
projects: [{
id: "foo",
name: "foo",
Expand Down Expand Up @@ -177,7 +174,7 @@ test("It selects the specified project, version, and specification", () => {

test("It returns a undefined project, version, and specification when the selected project cannot be found", () => {
const sut = getSelection({
projectId: "foo",
path: "/foo",
projects: [{
id: "bar",
name: "bar",
Expand All @@ -192,8 +189,7 @@ test("It returns a undefined project, version, and specification when the select

test("It returns a undefined version and specification when the selected version cannot be found", () => {
const sut = getSelection({
projectId: "foo",
versionId: "bar",
path: "/foo/bar",
projects: [{
id: "foo",
name: "foo",
Expand All @@ -213,9 +209,7 @@ test("It returns a undefined version and specification when the selected version

test("It returns a undefined specification when the selected specification cannot be found", () => {
const sut = getSelection({
projectId: "foo",
versionId: "bar",
specificationId: "baz",
path: "/foo/bar/baz",
projects: [{
id: "foo",
name: "foo",
Expand Down
151 changes: 92 additions & 59 deletions __test__/projects/projectNavigator.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { projectNavigator } from "../../src/features/projects/domain"
import { ProjectNavigator } from "../../src/features/projects/domain"

test("It navigates to the correct path", async () => {
let pushedPath: string | undefined
const router = {
push: (path: string) => {
pushedPath = path
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/"
}
},
replace: () => {}
}
projectNavigator.navigate(router, "foo", "bar", "hello.yml")
router: {
push: (path: string) => {
pushedPath = path
},
replace: () => {}
}
})
sut.navigate("foo", "bar", "hello.yml")
expect(pushedPath).toEqual("/foo/bar/hello.yml")
})

Expand Down Expand Up @@ -38,13 +45,20 @@ test("It navigates to first specification when changing version", async () => {
}]
}
let pushedPath: string | undefined
const router = {
push: (path: string) => {
pushedPath = path
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/"
}
},
replace: () => {}
}
projectNavigator.navigateToVersion(router, project, "hello", "baz.yml")
router: {
push: (path: string) => {
pushedPath = path
},
replace: () => {}
}
})
sut.navigateToVersion(project, "hello", "baz.yml")
expect(pushedPath).toEqual("/foo/hello/world.yml")
})

Expand Down Expand Up @@ -90,29 +104,39 @@ test("It finds a specification with the same name when changing version", async
}]
}
let pushedPath: string | undefined
const router = {
push: (path: string) => {
pushedPath = path
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/"
}
},
replace: () => {}
}
projectNavigator.navigateToVersion(router, project, "baz", "earth.yml")
router: {
push: (path: string) => {
pushedPath = path
},
replace: () => {}
}
})
sut.navigateToVersion(project, "baz", "earth.yml")
expect(pushedPath).toEqual("/foo/baz/earth.yml")
})

test("It skips navigating when URL matches selection", async () => {
let didNavigate = false
const router = {
push: () => {},
replace: () => {
didNavigate = true
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/foo/bar/baz"
}
},
router: {
push: () => {},
replace: () => {
didNavigate = true
}
}
}
projectNavigator.navigateIfNeeded(router, {
projectId: "foo",
versionId: "bar",
specificationId: "baz"
}, {
})
sut.navigateIfNeeded({
projectId: "foo",
versionId: "bar",
specificationId: "baz"
Expand All @@ -122,60 +146,69 @@ test("It skips navigating when URL matches selection", async () => {

test("It navigates when project ID in URL does not match ID of selected project", async () => {
let didNavigate = false
const router = {
push: () => {},
replace: () => {
didNavigate = true
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/hello/bar/baz"
}
},
router: {
push: () => {},
replace: () => {
didNavigate = true
}
}
}
projectNavigator.navigateIfNeeded(router, {
})
sut.navigateIfNeeded({
projectId: "foo",
versionId: "bar",
specificationId: "baz"
}, {
projectId: "hello",
versionId: "bar",
specificationId: "baz"
})
expect(didNavigate).toBeTruthy()
})

test("It navigates when version ID in URL does not match ID of selected version", async () => {
let didNavigate = false
const router = {
push: () => {},
replace: () => {
didNavigate = true
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/foo/hello/baz"
}
},
router: {
push: () => {},
replace: () => {
didNavigate = true
}
}
}
projectNavigator.navigateIfNeeded(router, {
})
sut.navigateIfNeeded({
projectId: "foo",
versionId: "bar",
specificationId: "baz"
}, {
projectId: "foo",
versionId: "hello",
specificationId: "baz"
})
expect(didNavigate).toBeTruthy()
})

test("It navigates when specification ID in URL does not match ID of selected specification", async () => {
let didNavigate = false
const router = {
push: () => {},
replace: () => {
didNavigate = true
const sut = new ProjectNavigator({
pathnameReader: {
get pathname() {
return "/foo/bar/hello"
}
},
router: {
push: () => {},
replace: () => {
didNavigate = true
}
}
}
projectNavigator.navigateIfNeeded(router, {
})
sut.navigateIfNeeded({
projectId: "foo",
versionId: "bar",
specificationId: "baz"
}, {
projectId: "foo",
versionId: "bar",
specificationId: "hello"
})
expect(didNavigate).toBeTruthy()
})
Loading