Skip to content

Commit e4d23ff

Browse files
fix(site): add test and fix username params in terminal (#8052)
1 parent f61001d commit e4d23ff

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

site/src/pages/TerminalPage/TerminalPage.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "../../testHelpers/renderHelpers"
1616
import { server } from "../../testHelpers/server"
1717
import TerminalPage, { Language } from "./TerminalPage"
18+
import * as API from "api/api"
1819

1920
Object.defineProperty(window, "matchMedia", {
2021
writable: true,
@@ -63,6 +64,20 @@ const expectTerminalText = (container: HTMLElement, text: string) => {
6364
}
6465

6566
describe("TerminalPage", () => {
67+
it("loads the right workspace data", async () => {
68+
const spy = jest
69+
.spyOn(API, "getWorkspaceByOwnerAndName")
70+
.mockResolvedValue(MockWorkspace)
71+
await renderTerminal(`/${MockUser.username}/${MockWorkspace.name}/terminal`)
72+
await waitFor(() => {
73+
expect(API.getWorkspaceByOwnerAndName).toHaveBeenCalledWith(
74+
MockUser.username,
75+
MockWorkspace.name,
76+
)
77+
})
78+
spy.mockRestore()
79+
})
80+
6681
it("shows an error if fetching workspace fails", async () => {
6782
// Given
6883
server.use(

site/src/pages/TerminalPage/TerminalPage.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ const TerminalPage: FC = () => {
7373
const navigate = useNavigate()
7474
const styles = useStyles()
7575
const { proxy } = useProxy()
76-
const { username, workspace: workspaceName } = useParams()
76+
const params = useParams() as { username: string; workspace: string }
77+
const username = params.username.replace("@", "")
78+
const workspaceName = params.workspace
7779
const xtermRef = useRef<HTMLDivElement>(null)
7880
const [terminal, setTerminal] = useState<XTerm.Terminal | null>(null)
7981
const [fitAddon, setFitAddon] = useState<FitAddon | null>(null)

0 commit comments

Comments
 (0)