Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests #49

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 68 additions & 90 deletions src/Tests.roc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ platformSelectModel = inputAppNameModel |> applyAction TextSubmit
packageSelectModel = platformSelectModel |> applyAction SingleSelect
confirmationModel = packageSelectModel |> applyAction MultiConfirm
finishedModel = confirmationModel |> applyAction Finish
splashModel = typeSelectModel |> applyAction Secret

## ===============================
## model object tests
Expand Down Expand Up @@ -112,8 +113,58 @@ expect
&& (model.pageFirstItem == 0)
&& (model.menuRow == 2)

expect
# Test: transition from TypeSelect to Splash
model = splashModel
(model.state == Splash { config: emptyAppConfig })
&& (model.platformList == ["pf1", "pf2"])
&& (model.packageList == ["pk1", "pk2", "pk3"])
&& (model.cursor == { row: model.menuRow, col: 2 })
&& (model.screen == { height: 0, width: 0 })
&& (model.selected == [])
&& (model.pageFirstItem == 0)
&& (model.menuRow == 2)

## ===============================
## TypeSelect tests
## Exit tests

expect
# TEST: exit from TypeSelect
model = typeSelectModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from InputAppName
model = inputAppNameModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from PlatformSelect
model = platformSelectModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from PackageSelect
model = packageSelectModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from Confirmation
model = confirmationModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from Finished
model = finishedModel |> applyAction Exit
model.state == UserExited

expect
# TEST: exit from Splash
model = splashModel |> applyAction Exit
model.state == UserExited

## ===============================
## Cursor movement tests

expect
# TEST: move cursor down from top of menu
Expand All @@ -135,9 +186,24 @@ expect
model = typeSelectModel |> applyAction CursorDown |> applyAction CursorDown
model.cursor == { row: model.menuRow, col: 2 }

expect
# TEST: move cursor down with only one item in menu
model = { typeSelectModel & menu: ["App"] } |> applyAction CursorDown
model.cursor == { row: model.menuRow, col: 2 }

expect
# TEST: move cursor up with only one item in menu
model = { typeSelectModel & menu: ["App"] } |> applyAction CursorUp
model.cursor == { row: model.menuRow, col: 2 }

## ===============================
## InputAppName tests

expect
# TEST: InputAppName back to TypeSelect
model = inputAppNameModel |> applyAction GoBack
model.state == TypeSelect { config: emptyAppConfig }

expect
# TEST: InuptAppName to PlatformSelect w/ non-empty buffer
model =
Expand All @@ -163,12 +229,7 @@ expect
model.state == PlatformSelect { config: { emptyAppConfig & fileName: "main" } }

expect
# TEST: exit from InputAppName
model = inputAppNameModel |> applyAction Exit
model.state == UserExited

expect
# TEST: paginate InputAppName
# TEST: paginate InputAppName (should not change model)
model = inputAppNameModel |> Controller.paginate
model == inputAppNameModel

Expand Down Expand Up @@ -245,62 +306,6 @@ expect
model = inputAppNameModel |> applyAction TextBackspace
model == inputAppNameModel

# expect
# # TEST: PlatformSelect - moveCursor Up w/ only one item
# initModel = Model.init ["platform1"] [] |> Model.toInputAppNameState
# model = Model.toPlatformSelectState initModel
# newModel = model |> Model.moveCursor Up
# newModel == model

# expect
# # TEST: PlatformSelect - moveCursor Down w/ only one item
# initModel = Model.init ["platform1"] [] |> Model.toInputAppNameState
# model = Model.toPlatformSelectState initModel
# newModel = model |> Model.moveCursor Down
# newModel == model

# expect
# # TEST: PlatformSelect - moveCursor Up w/ cursor starting at bottom
# initModel =
# Model.init ["platform1", "platform2", "platform3"] []
# |> Model.toInputAppNameState
# |> Model.toPlatformSelectState
# model = { initModel &
# cursor: { row: initModel.menuRow + 2, col: 2 },
# }
# newModel = model |> Model.moveCursor Up
# newModel.cursor.row == model.menuRow + 1

# expect
# # TEST: PlatformSelect - moveCursor Down w/ cursor starting at top
# model =
# Model.init ["platform1", "platform2", "platform3"] []
# |> Model.toInputAppNameState
# |> Model.toPlatformSelectState
# newModel = model |> Model.moveCursor Down
# newModel.cursor.row == model.menuRow + 1

# expect
# # TEST: PlatformSelect - moveCursor Up w/ cursor starting at top
# model =
# Model.init ["platform1", "platform2", "platform3"] []
# |> Model.toInputAppNameState
# |> Model.toPlatformSelectState
# newModel = model |> Model.moveCursor Up
# newModel.cursor.row == model.menuRow + 2

# expect
# # TEST: PlatformSelect - moveCursor Down w/ cursor starting at bottom
# initModel =
# Model.init ["platform1", "platform2", "platform3"] []
# |> Model.toPlatformSelectState
# |> Model.toPlatformSelectState
# model = { initModel &
# cursor: { row: initModel.menuRow + 2, col: 2 },
# }
# newModel = model |> Model.moveCursor Down
# newModel.cursor.row == model.menuRow

# expect
# # TEST: PlatformSelect to InputAppName
# initModel =
Expand Down Expand Up @@ -330,30 +335,3 @@ expect
# == Search { searchBuffer: [], sender: Platform, config: { fileName: "a", platform: "b", packages: ["c", "d"], type: App } }
# && newModel.cursor.row
# == newModel.menuRow

# expect
# # TEST: PlatformSelect to UserExited
# model =
# Model.init [] []
# |> Model.toInputAppNameState
# |> Model.toPlatformSelectState
# newModel = Model.toUserExitedState model
# newModel.state == UserExited

# expect
# # TEST: PlatformSelect to PackageSelect
# initModel =
# Model.init ["b"] ["c", "d"]
# |> Model.toInputAppNameState
# |> Model.toPlatformSelectState
# model = { initModel &
# cursor: { row: initModel.menuRow, col: 2 },
# state: PlatformSelect { config: { fileName: "a", platform: "", packages: ["c"], type: App } },
# }
# newModel = Model.toPackageSelectState model
# newModel.state
# == PackageSelect { config: { fileName: "a", platform: "b", packages: ["c"], type: App } }
# && newModel.cursor.row
# == newModel.menuRow
# && newModel.selected
# == ["c"]
Loading