Add test for banned user
This commit is contained in:
parent
8c16a776b6
commit
a6c0fe691c
5 changed files with 80 additions and 32 deletions
|
|
@ -119,7 +119,7 @@ when defined(js):
|
|||
),
|
||||
onClick=(e: Event, n: VNode) => (state.currentTab = Overview)
|
||||
):
|
||||
a(class="c-hand"):
|
||||
a(id="overview-tab", class="c-hand"):
|
||||
text "Overview"
|
||||
li(class=class(
|
||||
{"active": state.currentTab == Settings},
|
||||
|
|
@ -127,7 +127,7 @@ when defined(js):
|
|||
),
|
||||
onClick=(e: Event, n: VNode) => (state.currentTab = Settings)
|
||||
):
|
||||
a(class="c-hand"):
|
||||
a(id="settings-tab", class="c-hand"):
|
||||
italic(class="fas fa-cog")
|
||||
text " Settings"
|
||||
|
||||
|
|
@ -147,4 +147,4 @@ when defined(js):
|
|||
genPostLink(thread)
|
||||
of Settings:
|
||||
if state.settings.isSome():
|
||||
render(state.settings.get(), currentUser)
|
||||
render(state.settings.get(), currentUser)
|
||||
|
|
|
|||
|
|
@ -165,7 +165,8 @@ when defined(js):
|
|||
label(class="form-label"):
|
||||
text "Account"
|
||||
tdiv(class="col-9 col-sm-12"):
|
||||
button(class="btn btn-secondary", `type`="button",
|
||||
button(id="delete-account-btn",
|
||||
class="btn btn-secondary", `type`="button",
|
||||
onClick=(e: Event, n: VNode) =>
|
||||
(state.deleteModal.show(state.profile.user))):
|
||||
italic(class="fas fa-times")
|
||||
|
|
@ -176,13 +177,15 @@ when defined(js):
|
|||
span(class="text-error"):
|
||||
text state.error.get().message
|
||||
|
||||
button(class=class(
|
||||
button(id="cancel-btn",
|
||||
class=class(
|
||||
{"disabled": not needsSave(state)}, "btn btn-link"
|
||||
),
|
||||
onClick=(e: Event, n: VNode) => (resetSettings(state))):
|
||||
text "Cancel"
|
||||
|
||||
button(class=class(
|
||||
button(id="save-btn",
|
||||
class=class(
|
||||
{"disabled": not needsSave(state)}, "btn btn-primary"
|
||||
),
|
||||
onClick=(e: Event, n: VNode) => save(state),
|
||||
|
|
@ -199,4 +202,4 @@ when defined(js):
|
|||
rankField.setInputText($state.rank)
|
||||
let emailField = getVNodeById("email-field")
|
||||
if not emailField.isNil:
|
||||
emailField.setInputText($state.email)
|
||||
emailField.setInputText($state.email)
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ template sendKeys*(session: Session, element: string, keys: varargs[Key]) =
|
|||
for key in keys:
|
||||
session.press(key)
|
||||
|
||||
template ensureExists*(session: Session, element: string) =
|
||||
let el = session.findElement(element)
|
||||
template ensureExists*(session: Session, element: string, strategy=CssSelector) =
|
||||
let el = session.findElement(element, strategy)
|
||||
check el.isSome()
|
||||
|
||||
template check*(session: Session, element: string, function: untyped) =
|
||||
|
|
@ -69,8 +69,22 @@ proc waitForLoad*(session: Session, timeout=20000) =
|
|||
proc wait*(session: Session, msTimeout: int = 5000) =
|
||||
session.waitForLoad(msTimeout)
|
||||
|
||||
proc logout*(session: Session) =
|
||||
proc setUserRank*(session: Session, user, rank, baseUrl: string) =
|
||||
with session:
|
||||
navigate(baseUrl & "profile/" & user)
|
||||
wait()
|
||||
|
||||
click "#settings-tab"
|
||||
|
||||
click "#rank-field"
|
||||
click("#rank-field-" & rank.toLowerAscii)
|
||||
|
||||
click "#save-btn"
|
||||
wait()
|
||||
|
||||
proc logout*(session: Session, baseUrl: string) =
|
||||
with session:
|
||||
navigate baseUrl
|
||||
wait()
|
||||
click "#profile-btn"
|
||||
click "#profile-btn #logout-btn"
|
||||
|
|
@ -79,8 +93,10 @@ proc logout*(session: Session) =
|
|||
# Verify we have logged out by looking for the log in button.
|
||||
ensureExists "#login-btn"
|
||||
|
||||
proc login*(session: Session, user, password: string) =
|
||||
proc login*(session: Session, baseUrl, user, password: string) =
|
||||
with session:
|
||||
navigate baseUrl
|
||||
wait()
|
||||
click "#login-btn"
|
||||
|
||||
sendKeys "#login-form input[name='username']", user
|
||||
|
|
@ -138,3 +154,9 @@ proc changeRank*(session: Session, rank: string) =
|
|||
|
||||
# TODO: Getting an "element click intercepted" error here.
|
||||
click "#save-btn"
|
||||
|
||||
proc banUser*(session: Session, baseUrl: string) =
|
||||
with session:
|
||||
login baseUrl, "admin", "admin"
|
||||
setUserRank "user", "banned", baseUrl
|
||||
logout baseUrl
|
||||
|
|
|
|||
|
|
@ -31,6 +31,4 @@ proc test*(session: Session, baseUrl: string) =
|
|||
with session:
|
||||
register("test", "test")
|
||||
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
logout(session)
|
||||
session.logout(baseUrl)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,17 @@ import unittest, options, os, common
|
|||
|
||||
import webdriver
|
||||
|
||||
proc test*(session: Session, baseUrl: string) =
|
||||
let
|
||||
userTitleStr = "This is a user thread!"
|
||||
userContentStr = "A user has filled this out"
|
||||
let
|
||||
userTitleStr = "This is a user thread!"
|
||||
userContentStr = "A user has filled this out"
|
||||
|
||||
adminTitleStr = "This is a thread title!"
|
||||
adminContentStr = "This is content"
|
||||
adminTitleStr = "This is a thread title!"
|
||||
adminContentStr = "This is content"
|
||||
|
||||
|
||||
proc userTests(session: Session, baseUrl: string) =
|
||||
suite "user thread tests":
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
login(session, "user", "user")
|
||||
session.login(baseUrl, "user", "user")
|
||||
|
||||
setup:
|
||||
session.navigate(baseUrl)
|
||||
|
|
@ -33,19 +32,39 @@ proc test*(session: Session, baseUrl: string) =
|
|||
checkText "#thread-title", userTitleStr
|
||||
checkText ".original-post div.post-content", userContentStr
|
||||
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
logout(session)
|
||||
session.logout(baseUrl)
|
||||
|
||||
proc bannedTests(session: Session, baseUrl: string) =
|
||||
suite "banned user thread tests":
|
||||
session.login(baseUrl, "banned", "banned")
|
||||
|
||||
test "can't start thread":
|
||||
with session:
|
||||
click "#new-thread-btn"
|
||||
wait()
|
||||
|
||||
sendKeys "#thread-title", "test"
|
||||
sendKeys "#reply-textarea", "test"
|
||||
|
||||
click "#create-thread-btn"
|
||||
wait()
|
||||
|
||||
ensureExists "#new-thread p.text-error"
|
||||
|
||||
session.logout(baseUrl)
|
||||
|
||||
proc adminTests(session: Session, baseUrl: string) =
|
||||
suite "admin thread tests":
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
login(session, "admin", "admin")
|
||||
session.login(baseUrl, "admin", "admin")
|
||||
|
||||
setup:
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
|
||||
test "can view banned thread":
|
||||
with session:
|
||||
ensureExists userTitleStr, LinkTextSelector
|
||||
|
||||
test "can create thread":
|
||||
with session:
|
||||
click "#new-thread-btn"
|
||||
|
|
@ -116,6 +135,12 @@ proc test*(session: Session, baseUrl: string) =
|
|||
# Make sure the forum post is gone
|
||||
checkIsNone adminTitleStr, LinkTextSelector
|
||||
|
||||
session.navigate(baseUrl)
|
||||
session.wait()
|
||||
logout(session)
|
||||
session.logout(baseUrl)
|
||||
|
||||
proc test*(session: Session, baseUrl: string) =
|
||||
userTests(session, baseUrl)
|
||||
|
||||
banUser(session, baseUrl)
|
||||
|
||||
bannedTests(session, baseUrl)
|
||||
adminTests(session, baseUrl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue