1
0

fullstack.spec.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // @ts-check
  2. const { test, expect } = require("@playwright/test");
  3. test("hydration", async ({ page }) => {
  4. await page.goto("http://localhost:3333");
  5. // Expect the page to contain the pending text.
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("Server said: ...");
  8. // Expect the page to contain the counter text.
  9. await expect(main).toContainText("hello axum! 12345");
  10. // Expect the title to contain the counter text.
  11. await expect(page).toHaveTitle("hello axum! 12345");
  12. // Click the increment button.
  13. let button = page.locator("button.increment-button");
  14. await button.click();
  15. // Click the server button.
  16. let serverButton = page.locator("button.server-button");
  17. await serverButton.click();
  18. // Expect the page to contain the updated counter text.
  19. await expect(main).toContainText("hello axum! 12346");
  20. // Expect the title to contain the updated counter text.
  21. await expect(page).toHaveTitle("hello axum! 12346");
  22. // Expect the page to contain the updated counter text.
  23. await expect(main).toContainText("Server said: Hello from the server!");
  24. // Make sure the error that was thrown on the server is shown in the error boundary on the client
  25. const errors = page.locator("#errors");
  26. await expect(errors).toContainText("Hmm, something went wrong.");
  27. // Expect the onmounted event to be called exactly once.
  28. const mountedDiv = page.locator("div.onmounted-div");
  29. await expect(mountedDiv).toHaveText("onmounted was called 1 times");
  30. });
  31. test("document elements", async ({ page }) => {
  32. await page.goto("http://localhost:3333");
  33. // wait until the meta element is mounted
  34. const meta = page.locator("meta#meta-head[name='testing']");
  35. await meta.waitFor({ state: "attached" });
  36. await expect(meta).toHaveAttribute("data", "dioxus-meta-element");
  37. const link = page.locator("link#link-head[rel='stylesheet']");
  38. await link.waitFor({ state: "attached" });
  39. await expect(link).toHaveAttribute(
  40. "href",
  41. "https://fonts.googleapis.com/css?family=Roboto+Mono"
  42. );
  43. const stylesheet = page.locator("link#stylesheet-head[rel='stylesheet']");
  44. await stylesheet.waitFor({ state: "attached" });
  45. await expect(stylesheet).toHaveAttribute(
  46. "href",
  47. "https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
  48. );
  49. const script = page.locator("script#script-head");
  50. await script.waitFor({ state: "attached" });
  51. await expect(script).toHaveAttribute("async", "true");
  52. const style = page.locator("style#style-head");
  53. await style.waitFor({ state: "attached" });
  54. const main = page.locator("#main");
  55. await expect(main).toHaveCSS("font-family", "Roboto");
  56. });
  57. test("websockets", async ({ page }) => {
  58. await page.goto("http://localhost:3333");
  59. // wait until the websocket div is mounted
  60. const wsDiv = page.locator("div#websocket-div");
  61. await expect(wsDiv).toHaveText("Received: HELLO WORLD");
  62. });