redirect.spec.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { expect, Page, test } from "@playwright/test";
  2. import path from "path";
  3. import { fileURLToPath } from "url";
  4. const filename = fileURLToPath(import.meta.url);
  5. const dirname = path.dirname(filename);
  6. const confirmSettings = async (page: Page) => {
  7. const confirmPreferenceButton = page.getByRole("button", {
  8. name: /confirm preferences/i,
  9. });
  10. await confirmPreferenceButton.click();
  11. const configSaveButton = page.getByRole("button", {
  12. name: /save/i,
  13. });
  14. await configSaveButton.click();
  15. const confirmChanges = page.getByRole("button", {
  16. name: /yes, close settings/i,
  17. });
  18. await confirmChanges.click();
  19. };
  20. test("should redirect to /app after uploading a project zip", async ({
  21. page,
  22. }) => {
  23. await page.goto("/");
  24. const fileInput = page.getByLabel("Upload a .zip");
  25. const filePath = path.join(dirname, "fixtures/project.zip");
  26. await fileInput.setInputFiles(filePath);
  27. await page.waitForURL("/app");
  28. });
  29. test("should redirect to /app after selecting a repo", async ({ page }) => {
  30. await page.goto("/");
  31. await confirmSettings(page);
  32. // enter a github token to view the repositories
  33. const connectToGitHubButton = page.getByRole("button", {
  34. name: /connect to github/i,
  35. });
  36. await connectToGitHubButton.click();
  37. const tokenInput = page.getByLabel(/github token\*/i);
  38. await tokenInput.fill("fake-token");
  39. const submitButton = page.getByTestId("connect-to-github");
  40. await submitButton.click();
  41. // select a repository
  42. const repoDropdown = page.getByLabel(/github repository/i);
  43. await repoDropdown.click();
  44. const repoItem = page.getByTestId("github-repo-item").first();
  45. await repoItem.click();
  46. await page.waitForURL("/app");
  47. expect(page.url()).toBe("http://127.0.0.1:3000/app");
  48. });