web.spec.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // @ts-check
  2. const { test, expect, defineConfig } = require("@playwright/test");
  3. test("button click", async ({ page }) => {
  4. await page.goto("http://localhost:9999");
  5. // Expect the page to contain the counter text.
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("hello axum! 0");
  8. // Expect the title to contain the counter text.
  9. await expect(page).toHaveTitle("hello axum! 0");
  10. // Click the increment button.
  11. let button = page.locator("button.increment-button");
  12. await button.click();
  13. // Expect the page to contain the updated counter text.
  14. await expect(main).toContainText("hello axum! 1");
  15. // Expect the title to contain the updated counter text.
  16. await expect(page).toHaveTitle("hello axum! 1");
  17. });
  18. test("svg", async ({ page }) => {
  19. await page.goto("http://localhost:9999");
  20. // Expect the page to contain the svg.
  21. const svg = page.locator("svg");
  22. // Expect the svg to contain the circle.
  23. const circle = svg.locator("circle");
  24. await expect(circle).toHaveAttribute("cx", "50");
  25. await expect(circle).toHaveAttribute("cy", "50");
  26. await expect(circle).toHaveAttribute("r", "40");
  27. await expect(circle).toHaveAttribute("stroke", "green");
  28. await expect(circle).toHaveAttribute("fill", "yellow");
  29. });
  30. test("raw attribute", async ({ page }) => {
  31. await page.goto("http://localhost:9999");
  32. // Expect the page to contain the div with the raw attribute.
  33. const div = page.locator("div.raw-attribute-div");
  34. await expect(div).toHaveAttribute("raw-attribute", "raw-attribute-value");
  35. });
  36. test("hidden attribute", async ({ page }) => {
  37. await page.goto("http://localhost:9999");
  38. // Expect the page to contain the div with the hidden attribute.
  39. const div = page.locator("div.hidden-attribute-div");
  40. await expect(div).toHaveAttribute("hidden", "true");
  41. });
  42. test("dangerous inner html", async ({ page }) => {
  43. await page.goto("http://localhost:9999");
  44. // Expect the page to contain the div with the dangerous inner html.
  45. const div = page.locator("div.dangerous-inner-html-div");
  46. await expect(div).toContainText("hello dangerous inner html");
  47. });
  48. test("input value", async ({ page }) => {
  49. await page.goto("http://localhost:9999");
  50. // Expect the page to contain the input with the value.
  51. const input = page.locator("input");
  52. await expect(input).toHaveValue("hello input");
  53. });
  54. test("style", async ({ page }) => {
  55. await page.goto("http://localhost:9999");
  56. // Expect the page to contain the div with the style.
  57. const div = page.locator("div.style-div");
  58. await expect(div).toHaveText("colored text");
  59. await expect(div).toHaveCSS("color", "rgb(255, 0, 0)");
  60. });
  61. test("eval", async ({ page }) => {
  62. await page.goto("http://localhost:9999");
  63. // Expect the page to contain the div with the eval and have no text.
  64. const div = page.locator("div.eval-result");
  65. await expect(div).toHaveText("");
  66. // Click the button to run the eval.
  67. let button = page.locator("button.eval-button");
  68. await button.click();
  69. // Check that the title changed.
  70. await expect(page).toHaveTitle("Hello from Dioxus Eval!");
  71. // Check that the div has the eval value.
  72. await expect(div).toHaveText("returned eval value");
  73. });
  74. test("prevent default", async ({ page }) => {
  75. await page.goto("http://localhost:9999");
  76. // Expect the page to contain the div with the eval and have no text.
  77. const a = page.locator("a.prevent-default");
  78. await expect(a).toHaveText("View source");
  79. // Click the <a> element to change the text
  80. await a.click();
  81. // Check that the <a> element changed.
  82. await expect(a).toHaveText("Psych!");
  83. });
  84. test("onmounted", async ({ page }) => {
  85. await page.goto("http://localhost:9999");
  86. // Expect the onmounted event to be called exactly once.
  87. const mountedDiv = page.locator("div.onmounted-div");
  88. await expect(mountedDiv).toHaveText("onmounted was called 1 times");
  89. });
  90. test("web-sys closure", async ({ page }) => {
  91. await page.goto("http://localhost:9999");
  92. // wait until the div is mounted
  93. const scrollDiv = page.locator("div#web-sys-closure-div");
  94. await scrollDiv.waitFor({ state: "attached" });
  95. await page.keyboard.press("Enter");
  96. await expect(scrollDiv).toHaveText("the keydown event was triggered");
  97. });
  98. test("document elements", async ({ page }) => {
  99. await page.goto("http://localhost:9999");
  100. // wait until the meta element is mounted
  101. const meta = page.locator("meta#meta-head[name='testing']");
  102. await meta.waitFor({ state: "attached" });
  103. await expect(meta).toHaveAttribute("data", "dioxus-meta-element");
  104. const link = page.locator("link#link-head[rel='stylesheet']");
  105. await link.waitFor({ state: "attached" });
  106. await expect(link).toHaveAttribute(
  107. "href",
  108. "https://fonts.googleapis.com/css?family=Roboto+Mono"
  109. );
  110. const stylesheet = page.locator("link#stylesheet-head[rel='stylesheet']");
  111. await stylesheet.waitFor({ state: "attached" });
  112. await expect(stylesheet).toHaveAttribute(
  113. "href",
  114. "https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
  115. );
  116. const script = page.locator("script#script-head");
  117. await script.waitFor({ state: "attached" });
  118. await expect(script).toHaveAttribute("async", "true");
  119. const style = page.locator("style#style-head");
  120. await style.waitFor({ state: "attached" });
  121. const main = page.locator("#main");
  122. await expect(main).toHaveCSS("font-family", "Roboto");
  123. });