Skip to content

Commit

Permalink
Updates window title to match (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbs authored Oct 24, 2023
1 parent 3633f7a commit a2769ff
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Portal displaying our projects that are documented with OpenAPI. Hosted on [docs
Create a file named `.env.local` in the root of the project with the following contents. Make sure to replace any placeholders and generate a random secret using OpenSSL.

```
NEXT_PUBLIC_SHAPE_DOCS_TITLE='Shape Docs'
SHAPE_DOCS_BASE_URL='https://docs.shapetools.io'
AUTH0_SECRET='use [openssl rand -hex 32] to generate a 32 bytes value'
AUTH0_BASE_URL='http://dev.local:3000'
Expand All @@ -39,6 +40,7 @@ Each environment variable is described in the table below.

|Environment Variable|Description|
|-|-|
|NEXT_PUBLIC_SHAPE_DOCS_TITLE|Title of the portal. Displayed to the user in the browser.|
|SHAPE_DOCS_BASE_URL|The URL where Shape Docs is hosted.|
|AUTH0_SECRET|A long secret value used to encrypt the session cookie. Generate it using `openssl rand -hex 32`.|AUTH0_BASE_URL|The base URL of your Auth0 application. `http://dev.local:3000` during development.|
|AUTH0_ISSUER_BASE_URL|The URL of your Auth0 tenant domain.|
Expand Down
5 changes: 4 additions & 1 deletion __test__/projects/CachingProjectDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import Project from "../../src/features/projects/domain/Project"
import CachingProjectDataSource from "../../src/features/projects/domain/CachingProjectDataSource"

test("It caches projects read from the data source", async () => {
const projects = [{
const projects: Project[] = [{
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "baz.yml",
name: "baz.yml",
Expand All @@ -16,6 +18,7 @@ test("It caches projects read from the data source", async () => {
}, {
id: "hello",
name: "hello",
isDefault: false,
specifications: [{
id: "world.yml",
name: "world.yml",
Expand Down
26 changes: 26 additions & 0 deletions __test__/projects/ProjectPageState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ test("It gracefully errors when no project has been selected", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}, {
id: "bar",
name: "bar",
displayName: "bar",
versions: []
}]
})
Expand All @@ -38,13 +40,16 @@ test("It selects the first version and specification of the specified project",
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}, {
id: "bar",
name: "bar",
displayName: "bar",
versions: [{
id: "baz1",
name: "baz1",
isDefault: false,
specifications: [{
id: "hello1",
name: "hello1.yml",
Expand All @@ -57,6 +62,7 @@ test("It selects the first version and specification of the specified project",
}, {
id: "baz2",
name: "baz2",
isDefault: false,
specifications: []
}]
}]
Expand All @@ -74,17 +80,21 @@ test("It selects the first specification of the specified project and version",
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}, {
id: "bar",
name: "bar",
displayName: "bar",
versions: [{
id: "baz1",
name: "baz1",
isDefault: false,
specifications: []
}, {
id: "baz2",
name: "baz2",
isDefault: false,
specifications: [{
id: "hello1",
name: "hello1.yml",
Expand All @@ -106,17 +116,21 @@ test("It selects the specification of the specified version", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}, {
id: "bar",
name: "bar",
displayName: "bar",
versions: [{
id: "baz1",
name: "baz1",
isDefault: false,
specifications: []
}, {
id: "baz2",
name: "baz2",
isDefault: false,
specifications: [{
id: "hello1",
name: "hello1.yml",
Expand All @@ -143,17 +157,21 @@ test("It selects the specified project, version, and specification", async () =>
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}, {
id: "bar",
name: "bar",
displayName: "bar",
versions: [{
id: "baz1",
name: "baz1",
isDefault: false,
specifications: []
}, {
id: "baz2",
name: "baz2",
isDefault: false,
specifications: [{
id: "hello1",
name: "hello1.yml",
Expand All @@ -178,6 +196,7 @@ test("It errors when the selected project cannot be found", async () => {
projects: [{
id: "bar",
name: "bar",
displayName: "bar",
versions: []
}]
})
Expand All @@ -191,9 +210,11 @@ test("It errors when the selected version cannot be found", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "baz",
name: "baz",
isDefault: false,
specifications: []
}]
}]
Expand All @@ -209,9 +230,11 @@ test("It errors when the selected specification cannot be found", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "hello",
name: "hello.yml",
Expand All @@ -229,6 +252,7 @@ test("It errors when the selected project has no versions", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: []
}]
})
Expand All @@ -242,9 +266,11 @@ test("It errors when the selected version has no specifications", async () => {
projects: [{
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: []
}]
}]
Expand Down
13 changes: 13 additions & 0 deletions __test__/projects/projectNavigator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ test("It navigates to first specification when changing version", async () => {
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "baz.yml",
name: "baz.yml",
Expand All @@ -17,6 +19,7 @@ test("It navigates to first specification when changing version", async () => {
}, {
id: "hello",
name: "hello",
isDefault: false,
specifications: [{
id: "world.yml",
name: "world.yml",
Expand All @@ -27,6 +30,7 @@ test("It navigates to first specification when changing version", async () => {
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: []
},
specification: {
Expand All @@ -51,9 +55,11 @@ test("It navigates when selecting specification", async () => {
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "hello.yml",
name: "hello.yml",
Expand All @@ -64,6 +70,7 @@ test("It navigates when selecting specification", async () => {
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "hello.yml",
name: "hello.yml",
Expand Down Expand Up @@ -95,11 +102,13 @@ test("It navigates even when new specification could not be found", async () =>
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: []
},
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: []
},
specification: {
Expand All @@ -124,9 +133,11 @@ test("It finds a specification with the same name when changing version", async
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: [{
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "hello.yml",
name: "hello.yml",
Expand All @@ -139,6 +150,7 @@ test("It finds a specification with the same name when changing version", async
}, {
id: "baz",
name: "baz",
isDefault: false,
specifications: [{
id: "moon.yml",
name: "moon.yml",
Expand All @@ -161,6 +173,7 @@ test("It finds a specification with the same name when changing version", async
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: []
},
specification: {
Expand Down
102 changes: 102 additions & 0 deletions __test__/projects/updateWindowTitle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import updateWindowTitle from "../../src/features/projects/domain/updateWindowTitle"

test("It uses default title when there is no selection", async () => {
const store: { title: string } = { title: "" }
updateWindowTitle(store, "Shape Docs")
expect(store.title).toEqual("Shape Docs")
})

test("It leaves out specification when the specification has a generic name", async () => {
const store: { title: string } = { title: "" }
updateWindowTitle(store, "Shape Docs", {
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: []
},
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "hello.yml",
name: "hello.yml",
url: "https://example.com/hello.yml"
}, {
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}]
},
specification: {
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}
})
expect(store.title).toEqual("foo / bar")
})

test("It leaves out version when it is the defualt version", async () => {
const store: { title: string } = { title: "" }
updateWindowTitle(store, "Shape Docs", {
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: []
},
version: {
id: "bar",
name: "bar",
isDefault: true,
specifications: [{
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}]
},
specification: {
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}
})
expect(store.title).toEqual("foo")
})

test("It adds version when it is not the defualt version", async () => {
const store: { title: string } = { title: "" }
updateWindowTitle(store, "Shape Docs", {
project: {
id: "foo",
name: "foo",
displayName: "foo",
versions: []
},
version: {
id: "bar",
name: "bar",
isDefault: false,
specifications: [{
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}]
},
specification: {
id: "openapi.yml",
name: "openapi.yml",
url: "https://example.com/openapi.yml"
}
})
expect(store.title).toEqual("foo / bar")
})

// } else if (selection.version.isDefault) {
// storage.title = selection.project.displayName
// } else {
// storage.title = `${selection.project.displayName} / ${selection.version.name}`
// }
// }
Loading

0 comments on commit a2769ff

Please sign in to comment.