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

This commit is contained in:
Bruno Quaresma 2023-06-15 13:18:19 -03:00 committed by GitHub
parent f61001d049
commit e4d23ff5fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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,
@ -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(

View File

@ -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)