Adds attempt to test issue #181. Moves procs to common too.

Sadly the attempt wasn't a success. I decided to commit what I've
got so far and come back to it later. Out of time for this now.
This commit is contained in:
Dominik Picheta 2018-07-20 15:16:39 +01:00
commit 5714ad0c6a
5 changed files with 108 additions and 31 deletions

View file

@ -88,7 +88,7 @@ when defined(js):
class="form-select", value = $state.rank,
onchange=(e: Event, n: VNode) => onRankChange(e, n, state)):
for r in Rank:
option(text $r)
option(text $r, id="rank-" & toLowerAscii($r))
p(class="form-input-hint text-warning"):
text "You can modify anyone's rank. Remember: with " &
"great power comes great responsibility."
@ -185,7 +185,8 @@ when defined(js):
button(class=class(
{"disabled": not needsSave(state)}, "btn btn-primary"
),
onClick=(e: Event, n: VNode) => save(state)):
onClick=(e: Event, n: VNode) => save(state),
id="save-btn"):
italic(class="fas fa-save")
text " Save"

View file

@ -43,8 +43,7 @@ template withBackend(body: untyped): untyped =
body
import browsertests/scenario1
import browsertests/threads
import browsertests/[scenario1, threads, issue181]
when isMainModule:
spawn runProcess("geckodriver -p 4444 --log config")
@ -65,6 +64,8 @@ when isMainModule:
withBackend:
scenario1.test(session, baseUrl)
threads.test(session, baseUrl)
# TODO: Fix the issue181 test.
# issue181.test(session, baseUrl)
session.close()
except:

View file

@ -1,4 +1,4 @@
import os, options, unittest
import os, options, unittest, strutils
import webdriver
import macros
@ -76,6 +76,9 @@ proc logout*(session: Session) =
click "#profile-btn #logout-btn"
wait()
# Verify we have logged out by looking for the log in button.
ensureExists "#login-btn"
proc login*(session: Session, user, password: string) =
with session:
click "#login-btn"
@ -86,3 +89,52 @@ proc login*(session: Session, user, password: string) =
sendKeys "#login-form input[name='password']", Key.Enter
wait()
# Verify that the user menu has been initialised properly.
click "#profile-btn"
checkText "#profile-btn #profile-name", user
click "#profile-btn"
proc register*(session: Session, user, password: string) =
with session:
click "#signup-btn"
sendKeys "#signup-form input[name='email']", user & "@" & user & ".com"
sendKeys "#signup-form input[name='username']", user
sendKeys "#signup-form input[name='password']", password
click "#signup-modal .create-account-btn"
wait()
# Verify that the user menu has been initialised properly.
click "#profile-btn"
checkText "#profile-btn #profile-name", user
# close menu
click "#profile-btn"
proc createThread*(session: Session, title, content: string) =
with session:
click "#new-thread-btn"
wait()
sendKeys "#thread-title", title
sendKeys "#reply-textarea", content
click "#create-thread-btn"
wait()
checkText "#thread-title", title
checkText ".original-post div.post-content", content
proc changeRank*(session: Session, rank: string) =
with session:
# Make sure the "Settings" tab is selected.
click ".profile-tabs li:nth-child(2)"
click "#rank-field"
click "#rank-field option#rank-" & rank.toLowerAscii()
wait()
# TODO: Getting an "element click intercepted" error here.
click "#save-btn"

View file

@ -0,0 +1,46 @@
import unittest, options, os, common
import webdriver
proc test*(session: Session, baseUrl: string) =
session.navigate(baseUrl)
waitForLoad(session)
test "can see banned posts":
with session:
register("issue181", "issue181")
logout()
# Change rank to `user` so they can post.
login("admin", "admin")
navigate(baseUrl & "profile/user")
wait()
changeRank("user")
logout()
login("issue181", "issue181")
const title = "Testing issue 181."
createThread(title, "Test for issue #181")
logout()
wait()
login("admin", "admin")
# Ban our user.
navigate(baseUrl & "profile/issue181")
changeRank("banned")
# Make sure the banned user's thread is still visible.
navigate(baseUrl)
ensureExists("tr.banned")
checkText("tr.banned .thread-title > a", title)
logout()
checkText("tr.banned .thread-title > a", title)
session.navigate(baseUrl)
session.wait()
logout(session)

View file

@ -20,39 +20,16 @@ proc test*(session: Session, baseUrl: string) =
# Logging in
test "can login/logout":
with session:
click "#login-btn"
sendKeys "#login-form input[name='username']", "admin"
sendKeys "#login-form input[name='password']", "admin"
sendKeys "#login-form input[name='password']", Key.Enter
wait()
# Verify that the user menu has been initialised properly.
click "#profile-btn"
checkText "#profile-btn #profile-name", "admin"
login("admin", "admin")
# Check whether we can log out.
click "#logout-btn"
logout()
# Verify we have logged out by looking for the log in button.
ensureExists "#login-btn"
test "can register":
with session:
click "#signup-btn"
sendKeys "#signup-form input[name='email']", "test@test.com"
sendKeys "#signup-form input[name='username']", "test"
sendKeys "#signup-form input[name='password']", "test"
click "#signup-modal .create-account-btn"
wait()
# Verify that the user menu has been initialised properly.
click "#profile-btn"
checkText "#profile-btn #profile-name", "test"
# close menu
click "#profile-btn"
register("test", "test")
session.navigate(baseUrl)
session.wait()