Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Mar 10, 2024
1 parent 18f6222 commit a65f969
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ class IntegrationTest extends AnyFreeSpec with BeforeAndAfterAll {
}
}

private def clickButton(page: Page, f: Locator => Boolean): Unit = {
page.getByRole(AriaRole.BUTTON).all().asScala.find(f).getOrElse(sys.error("not found button")).click()
}

private def clickButtonById(page: Page, id: String): Unit = {
clickButton(page, _.getAttribute("id") == id)
}

private def clearLocalStorage(page: Page): Unit = {
page.getByRole(AriaRole.BUTTON).all().asScala.find(_.getAttribute("id") == "clear_local_storage").foreach(_.click())
clickButtonById(page, "clear_local_storage")
}

private def output(page: Page): Locator = {
Expand All @@ -60,13 +68,17 @@ class IntegrationTest extends AnyFreeSpec with BeforeAndAfterAll {
.getOrElse(sys.error("not found"))
}

private def setInput(page: Page, sourceCode: String): Unit = {
val input = page
private def inputElem(page: Page): Locator = {
page
.getByRole(AriaRole.TEXTBOX)
.all()
.asScala
.find(_.getAttribute("id") == "input_scala")
.getOrElse(sys.error("not found"))
}

private def setInput(page: Page, sourceCode: String): Unit = {
val input = inputElem(page)
input.fill(sourceCode)
input.press("\n")
}
Expand Down Expand Up @@ -124,4 +136,22 @@ class IntegrationTest extends AnyFreeSpec with BeforeAndAfterAll {
assert(output(page).textContent() == fromResource("tokens.txt"))
}
}

"format input" in withBrowser { (browser, page) =>
val notFormatted = Seq(
"""def a = """,
""" b""",
).mkString("\n")
setInput(page, notFormatted)
val input1 = inputElem(page).inputValue()
clickButtonById(page, "format_input")
val input2 = inputElem(page).inputValue()
assert(input1 != input2)
val formatted = Seq(
"""def a =""",
""" b""",
"",
).mkString("\n")
assert(inputElem(page).inputValue() == formatted)
}
}

0 comments on commit a65f969

Please sign in to comment.