Skip to content

fix(site): add test and fix username params in terminal #8052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2023
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
15 changes: 15 additions & 0 deletions site/src/pages/TerminalPage/TerminalPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "../../testHelpers/renderHelpers"
import { server } from "../../testHelpers/server"
import TerminalPage, { Language } from "./TerminalPage"
import * as API from "api/api"

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

describe("TerminalPage", () => {
it("loads the right workspace data", async () => {
const spy = jest
.spyOn(API, "getWorkspaceByOwnerAndName")
.mockResolvedValue(MockWorkspace)
await renderTerminal(`/${MockUser.username}/${MockWorkspace.name}/terminal`)
await waitFor(() => {
expect(API.getWorkspaceByOwnerAndName).toHaveBeenCalledWith(
MockUser.username,
MockWorkspace.name,
)
})
spy.mockRestore()
})

it("shows an error if fetching workspace fails", async () => {
// Given
server.use(
Expand Down
4 changes: 3 additions & 1 deletion site/src/pages/TerminalPage/TerminalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const TerminalPage: FC = () => {
const navigate = useNavigate()
const styles = useStyles()
const { proxy } = useProxy()
const { username, workspace: workspaceName } = useParams()
const params = useParams() as { username: string; workspace: string }
const username = params.username.replace("@", "")
const workspaceName = params.workspace
const xtermRef = useRef<HTMLDivElement>(null)
const [terminal, setTerminal] = useState<XTerm.Terminal | null>(null)
const [fitAddon, setFitAddon] = useState<FitAddon | null>(null)
Expand Down