-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginPageTest.scala
39 lines (31 loc) · 1.47 KB
/
LoginPageTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package tests
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.matchers.should.Matchers.*
import org.terminal21.client.components.*
import org.terminal21.client.*
import org.terminal21.model.CommandEvent
class LoginPageTest extends AnyFunSuiteLike:
class App:
given session: ConnectedSession = ConnectedSessionMock.newConnectedSessionMock
val login = LoginForm()
val page = new LoginPage
def allComponents: Seq[UiElement] = page.components(login, Events.Empty).view.flatMap(_.flat)
test("renders email input"):
new App:
allComponents should contain(page.emailInput)
test("renders password input"):
new App:
allComponents should contain(page.passwordInput)
test("renders submit button"):
new App:
allComponents should contain(page.submitButton)
test("user submits validated data"):
new App:
val eventsIt = page.controller.render(login).iterator // get the iterator before we fire the events, otherwise the iterator will be empty
session.fireEvents(
CommandEvent.onChange(page.emailInput, "an@email.com"),
CommandEvent.onChange(page.passwordInput, "secret"),
CommandEvent.onClick(page.submitButton),
CommandEvent.sessionClosed // every test should close the session so that the iterator doesn't block if converted to a list.
)
eventsIt.lastOption.map(_.model) should be(Some(LoginForm("an@email.com", "secret", true)))