| Four screens, in Nim c69a09b nandi 8h ago | 1 | ## The state record, and the few questions it answers itself. |
| 2 | |
| 3 | import std/[tables, unittest] |
| 4 | import frq/[cells, model] |
| 5 | |
| 6 | suite "initState": |
| 7 | test "starts on the connect screen, not connected": |
| 8 | let s = initState() |
| 9 | check s.screen == scConnect |
| 10 | check s.status == "Not connected" |
| 11 | check not s.connecting |
| 12 | |
| 13 | test "the form is filled in with the defaults the screen shows": |
| 14 | let s = initState() |
| 15 | check s.formHost == defaultHost |
| 16 | check s.formPort == defaultPort |
| 17 | check s.formTls |
| 18 | check s.formNick == "frq-guest" |
| 19 | check s.authMode == amGuest |
| 20 | |
| 21 | test "at-present, because a fresh conversation is at its end": |
| 22 | check initState().atPresent |
| 23 | |
| 24 | test "nothing is attached, replied to or being edited": |
| 25 | let s = initState() |
| 26 | check not s.attachment.has |
| 27 | check not s.replyingTo.has |
| 28 | check not s.editing.has |
| 29 | check not s.lightbox.has |
| 30 | |
| 31 | suite "wide": |
| 32 | test "a phone-width window is not wide": |
| 33 | var s = initState(); s.windowWidth = 420 |
| 34 | check not s.wide |
| 35 | test "past wideWidth it is": |
| 36 | var s = initState(); s.windowWidth = wideWidth |
| 37 | check s.wide |
| 38 | test "a window that has not reported yet is not": |
| 39 | # windowWidth starts at 0, and guessing wide would put a 320pt list beside |
| 40 | # a conversation on a phone. |
| 41 | check not initState().wide |
| 42 | |
| 43 | suite "currentRoom": |
| 44 | test "the room `current` names": |
| 45 | var s = initState() |
| 46 | s.rooms["#test"] = initRoom("#test") |
| 47 | s.current = "#test" |
| 48 | check s.currentRoom.name == "#test" |
| 49 | |
| 50 | test "an empty room where nothing is current": |
| 51 | # A value rather than an Option: every screen that asks is about to read |
| 52 | # `.messages`, and an empty list is the honest answer for "no room". |
| 53 | check initState().currentRoom.name == "" |
| 54 | |
| 55 | test "an empty room where `current` names one that is gone": |
| 56 | var s = initState(); s.current = "#vanished" |
| 57 | check s.currentRoom.name == "" |
| 58 | |
| 59 | suite "the constants the screens share": |
| 60 | test "popular channels are the discover list": |
| 61 | check popularChannels.len == 6 |
| 62 | check popularChannels[0][0] == "#general" |