redirect.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. });
  49. // FIXME: This fails because the MSW WS mocks change state too quickly,
  50. // missing the OPENING status where the initial query is rendered.
  51. test.fail(
  52. "should redirect the user to /app with their initial query after selecting a project",
  53. async ({ page }) => {
  54. await page.goto("/");
  55. await confirmSettings(page);
  56. // enter query
  57. const testQuery = "this is my test query";
  58. const textbox = page.getByPlaceholder(/what do you want to build/i);
  59. expect(textbox).not.toBeNull();
  60. await textbox.fill(testQuery);
  61. const fileInput = page.getByLabel("Upload a .zip");
  62. const filePath = path.join(dirname, "fixtures/project.zip");
  63. await fileInput.setInputFiles(filePath);
  64. await page.waitForURL("/app");
  65. // get user message
  66. const userMessage = page.getByTestId("user-message");
  67. expect(await userMessage.textContent()).toBe(testQuery);
  68. },
  69. );