Skip to content

Commit

Permalink
Missing workspace bug (#1533)
Browse files Browse the repository at this point in the history
* Add failing test for missing workspace

* Fix failing test
  • Loading branch information
jameskerr authored Mar 24, 2021
1 parent 61b2eb3 commit 1ab4585
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
34 changes: 21 additions & 13 deletions app/workspaces/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const SpinnerWrap = styled.div`
justify-content: center;
`

function GetWorkspace({children}) {
const workspace = useSelector(Current.getWorkspace)
if (!workspace) return <Redirect to="/workspaces" />
else return children
}

function InitWorkspace({children}) {
const dispatch = useDispatch()
const workspace = useSelector(Current.mustGetWorkspace)
Expand Down Expand Up @@ -50,18 +56,20 @@ function InitWorkspace({children}) {
export default function WorkspaceShow() {
const match = useRouteMatch<{workspaceId: string}>()
return (
<InitWorkspace>
<Switch>
<Route path={lakeImport.path}>
<LakeHome />
</Route>
<Route path={lakeShow.path}>
<LakeShow />
</Route>
<Route default>
<Redirect to={lakeImportPath(match.params.workspaceId)} />
</Route>
</Switch>
</InitWorkspace>
<GetWorkspace>
<InitWorkspace>
<Switch>
<Route path={lakeImport.path}>
<LakeHome />
</Route>
<Route path={lakeShow.path}>
<LakeShow />
</Route>
<Route default>
<Redirect to={lakeImportPath(match.params.workspaceId)} />
</Route>
</Switch>
</InitWorkspace>
</GetWorkspace>
)
}
19 changes: 16 additions & 3 deletions itest/lib/createTestBrim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {htmlContextMenu} from "src/js/test/locators"
import lib from "../../src/js/lib"
import {Locator} from "../../src/js/test/createLocator"
import appStep from "./appStep/api"
import takeScreenshot from "./appStep/api/takeScreenshot"
import waitForHook from "./appStep/api/waitForHook"
// TODO in a future PR: remove direct logStep uses here.
import logStep from "./appStep/util/logStep"
Expand Down Expand Up @@ -30,6 +31,11 @@ export default (name: string) => {
return waitForHook(app, name, opts)
},

navTo(path: string) {
// @ts-ignore
return app.client.execute((path) => navTo(path), path)
},

getApp() {
return app
},
Expand Down Expand Up @@ -65,6 +71,10 @@ export default (name: string) => {
})
},

takeScreenshot() {
return takeScreenshot(app)
},

clickAppMenuItem(id: string) {
return app.mainProcess.emit("spectron:clickAppMenuItem", id)
},
Expand All @@ -87,10 +97,13 @@ export default (name: string) => {
return appStep.rightClick(app, locator.css)
},

waitForText(locator: string, regex: RegExp) {
hasText(input: string | RegExp, locator: Locator | string = "body") {
return retryUntil(
async () => (await app.client.$(locator)).getText(),
(s) => regex.test(s)
() =>
app.client
.$(typeof locator === "string" ? locator : locator.css)
.then((el) => el.getText()),
(s) => (typeof input === "string" ? s.includes(input) : input.test(s))
)
},

Expand Down
15 changes: 15 additions & 0 deletions itest/tests/workspaces.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import createTestBrim from "itest/lib/createTestBrim"

describe("Workspace routes", () => {
const brim = createTestBrim("workspaces.test")

test("visiting a workspace that doesn't exist", async () => {
try {
await brim.navTo("/workspaces/none")
await brim.hasText("Choose a Workspace")
} catch (e) {
await brim.takeScreenshot()
throw e
}
})
})
1 change: 1 addition & 0 deletions src/js/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare global {
feature: (name: FeatureName, value: boolean) => void
tabHistories: Histories
windowHistory: BrowserHistory
navTo: (path: string) => void
}

interface Process {
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/WorkspacePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function WorkspacePicker() {
const current = useSelector(Workspaces.id(workspaceId))
return (
<WorkspacePickerWrapper onClick={() => dispatch(showWorkspaceMenu())}>
<label>{`${current.name}`}</label>
<label>{`${current?.name}`}</label>
<DropdownArrow />
</WorkspacePickerWrapper>
)
Expand Down
2 changes: 2 additions & 0 deletions src/js/initializers/initGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Feature from "../state/Feature"
import TabHistories from "../state/TabHistories"
import {Store} from "../state/types"
import {createMemoryHistory} from "history"
import tabHistory from "app/router/tab-history"

export default function initGlobals(store: Store) {
global.getState = store.getState
Expand All @@ -14,6 +15,7 @@ export default function initGlobals(store: Store) {
global.tabHistories = new Histories(TabHistories.selectAll(store.getState()))
global.windowHistory = createMemoryHistory()
global.windowHistory.replace(getUrlSearchParams().href)
global.navTo = (path) => store.dispatch(tabHistory.push(path))
}

function getWindowName() {
Expand Down

0 comments on commit 1ab4585

Please sign in to comment.