Skip to content

Commit

Permalink
Merge pull request #107 from xuwei-k/invalid-input-test
Browse files Browse the repository at this point in the history
add more tests

[skip ci]
  • Loading branch information
xuwei-k authored Mar 11, 2024
2 parents e3c8c0a + feb2c2e commit 6eb07c5
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,34 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
getTextboxById(page, "rule_name")
}

private def selectedDialect(page: Page): String = {
page.getByLabel("dialect").all().asScala.map(_.inputValue()).toList match {
private def singleOrError[A](list: List[A]): A = {
list match {
case List(value) =>
value
case Nil =>
sys.error("not found dialect")
sys.error("not found")
case values =>
sys.error(s"found multi values ${values}")
}
}

private def selectedDialect(page: Page): String = {
singleOrError(
page.getByLabel("dialect").all().asScala.map(_.inputValue()).toList
)
}

private def infoElem(page: Page): Locator = {
singleOrError(
page.locator("pre").all().asScala.filter(_.getAttribute("id") == "info").toList
)
}

"change input" in withBrowser { page =>
setInput(page, "class A")
assert(infoElem(page).getAttribute("class") == "alert alert-success")
val info = infoElem(page).textContent()
Seq("ast: ", "fmt: ", " ms").forall(info contains _)
val expect = Seq(
"""Defn.Class.After_4_6_0(""",
""" Nil,""",
Expand Down Expand Up @@ -402,4 +417,9 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
input = "aaa\n",
)
}

"invalid input" in withBrowser { page =>
setInput(page, "def")
assert(infoElem(page).getAttribute("class") == "alert alert-danger")
}
}

0 comments on commit 6eb07c5

Please sign in to comment.