Merge pull request #179 from jyapayne/add_threads_test
Add threads tests
This commit is contained in:
commit
82ff2fb212
8 changed files with 112 additions and 28 deletions
|
|
@ -49,7 +49,7 @@ when defined(js):
|
||||||
tdiv(class="title"):
|
tdiv(class="title"):
|
||||||
p(): text "New Thread"
|
p(): text "New Thread"
|
||||||
tdiv(class="content"):
|
tdiv(class="content"):
|
||||||
input(class="form-input", `type`="text", name="subject",
|
input(id="thread-title", class="form-input", `type`="text", name="subject",
|
||||||
placeholder="Type the title here",
|
placeholder="Type the title here",
|
||||||
oninput=(e: Event, n: VNode) => onSubjectChange(e, n, state))
|
oninput=(e: Event, n: VNode) => onSubjectChange(e, n, state))
|
||||||
if state.error.isSome():
|
if state.error.isSome():
|
||||||
|
|
@ -58,7 +58,8 @@ when defined(js):
|
||||||
renderContent(state.replyBox, none[Thread](), none[Post]())
|
renderContent(state.replyBox, none[Thread](), none[Post]())
|
||||||
tdiv(class="footer"):
|
tdiv(class="footer"):
|
||||||
|
|
||||||
button(class=class(
|
button(id="create-thread-btn",
|
||||||
|
class=class(
|
||||||
{"loading": state.loading},
|
{"loading": state.loading},
|
||||||
"btn btn-primary"
|
"btn btn-primary"
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -220,8 +220,11 @@ when defined(js):
|
||||||
): VNode =
|
): VNode =
|
||||||
let postCopy = post # TODO: Another workaround here, closure capture :(
|
let postCopy = post # TODO: Another workaround here, closure capture :(
|
||||||
|
|
||||||
|
let originalPost = thread.author == post.author
|
||||||
|
|
||||||
result = buildHtml():
|
result = buildHtml():
|
||||||
tdiv(class=class({"highlight": highlight}, "post"), id = $post.id):
|
tdiv(class=class({"highlight": highlight, "original-post": originalPost}, "post"),
|
||||||
|
id = $post.id):
|
||||||
tdiv(class="post-icon"):
|
tdiv(class="post-icon"):
|
||||||
render(post.author, "post-avatar")
|
render(post.author, "post-avatar")
|
||||||
tdiv(class="post-main"):
|
tdiv(class="post-main"):
|
||||||
|
|
@ -326,7 +329,7 @@ when defined(js):
|
||||||
let list = state.list.get()
|
let list = state.list.get()
|
||||||
result = buildHtml():
|
result = buildHtml():
|
||||||
section(class="container grid-xl"):
|
section(class="container grid-xl"):
|
||||||
tdiv(class="title"):
|
tdiv(id="thread-title", class="title"):
|
||||||
p(): text list.thread.topic
|
p(): text list.thread.topic
|
||||||
if list.thread.isLocked:
|
if list.thread.isLocked:
|
||||||
italic(class="fas fa-lock fa-xs",
|
italic(class="fas fa-lock fa-xs",
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,8 @@ when defined(js):
|
||||||
elif state.rendering.isSome():
|
elif state.rendering.isSome():
|
||||||
verbatim(state.rendering.get())
|
verbatim(state.rendering.get())
|
||||||
else:
|
else:
|
||||||
textarea(class="form-input post-text-area", rows="5",
|
textarea(id="reply-textarea",
|
||||||
|
class="form-input post-text-area", rows="5",
|
||||||
onChange=(e: Event, n: VNode) =>
|
onChange=(e: Event, n: VNode) =>
|
||||||
onChange(e, n, state),
|
onChange(e, n, state),
|
||||||
value=state.text)
|
value=state.text)
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ when defined(js):
|
||||||
button(class="btn btn-link"): text "Categories"
|
button(class="btn btn-link"): text "Categories"
|
||||||
section(class="navbar-section"):
|
section(class="navbar-section"):
|
||||||
if currentUser.isSome():
|
if currentUser.isSome():
|
||||||
a(href=makeUri("/newthread"), onClick=anchorCB):
|
a(id="new-thread-btn", href=makeUri("/newthread"), onClick=anchorCB):
|
||||||
button(class="btn btn-secondary"):
|
button(class="btn btn-secondary"):
|
||||||
italic(class="fas fa-plus")
|
italic(class="fas fa-plus")
|
||||||
text " New Thread"
|
text " New Thread"
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ template withBackend(body: untyped): untyped =
|
||||||
body
|
body
|
||||||
|
|
||||||
import browsertests/scenario1
|
import browsertests/scenario1
|
||||||
|
import browsertests/threads
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
spawn runProcess("geckodriver -p 4444 --log config")
|
spawn runProcess("geckodriver -p 4444 --log config")
|
||||||
|
|
@ -63,6 +64,7 @@ when isMainModule:
|
||||||
|
|
||||||
withBackend:
|
withBackend:
|
||||||
scenario1.test(session, baseUrl)
|
scenario1.test(session, baseUrl)
|
||||||
|
threads.test(session, baseUrl)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
42
tests/browsertests/common.nim
Normal file
42
tests/browsertests/common.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import os, options
|
||||||
|
import webdriver
|
||||||
|
|
||||||
|
proc waitForLoad*(session: Session, timeout=20000) =
|
||||||
|
var waitTime = 0
|
||||||
|
sleep(2000)
|
||||||
|
|
||||||
|
while true:
|
||||||
|
let loading = session.findElement(".loading")
|
||||||
|
if loading.isNone: return
|
||||||
|
sleep(1000)
|
||||||
|
waitTime += 1000
|
||||||
|
|
||||||
|
if waitTime > timeout:
|
||||||
|
doAssert false, "Wait for load time exceeded"
|
||||||
|
|
||||||
|
proc logout*(session: Session) =
|
||||||
|
# Check whether we can log out.
|
||||||
|
let logoutLink = session.findElement(
|
||||||
|
"Logout",
|
||||||
|
LinkTextSelector
|
||||||
|
).get()
|
||||||
|
logoutLink.click()
|
||||||
|
|
||||||
|
proc login*(session: Session, user, password: string) =
|
||||||
|
let logIn = session.findElement("#login-btn").get()
|
||||||
|
logIn.click()
|
||||||
|
|
||||||
|
let usernameField = session.findElement(
|
||||||
|
"#login-form input[name='username']"
|
||||||
|
)
|
||||||
|
|
||||||
|
let passwordField = session.findElement(
|
||||||
|
"#login-form input[name='password']"
|
||||||
|
)
|
||||||
|
|
||||||
|
usernameField.get().sendKeys("admin")
|
||||||
|
passwordField.get().sendKeys("admin")
|
||||||
|
passwordField.get().click() # Focus field.
|
||||||
|
session.press(Key.Enter)
|
||||||
|
|
||||||
|
waitForLoad(session, 5000)
|
||||||
|
|
@ -1,20 +1,7 @@
|
||||||
import unittest, options, os
|
import unittest, options, os, common
|
||||||
|
|
||||||
import webdriver
|
import webdriver
|
||||||
|
|
||||||
proc waitForLoad(session: Session, timeout=20000) =
|
|
||||||
var waitTime = 0
|
|
||||||
sleep(2000)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let loading = session.findElement(".loading")
|
|
||||||
if loading.isNone: return
|
|
||||||
sleep(1000)
|
|
||||||
waitTime += 1000
|
|
||||||
|
|
||||||
if waitTime > timeout:
|
|
||||||
doAssert false, "Wait for load time exceeded"
|
|
||||||
|
|
||||||
proc test*(session: Session, baseUrl: string) =
|
proc test*(session: Session, baseUrl: string) =
|
||||||
session.navigate(baseUrl)
|
session.navigate(baseUrl)
|
||||||
|
|
||||||
|
|
@ -113,3 +100,5 @@ proc test*(session: Session, baseUrl: string) =
|
||||||
).get()
|
).get()
|
||||||
|
|
||||||
check profileName.getText() == "test"
|
check profileName.getText() == "test"
|
||||||
|
|
||||||
|
logout(session)
|
||||||
46
tests/browsertests/threads.nim
Normal file
46
tests/browsertests/threads.nim
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import unittest, options, os, common
|
||||||
|
|
||||||
|
import webdriver
|
||||||
|
|
||||||
|
proc test*(session: Session, baseUrl: string) =
|
||||||
|
session.navigate(baseUrl)
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
login(session, "admin", "admin")
|
||||||
|
|
||||||
|
test "can create thread":
|
||||||
|
let newThreadBtn = session.findElement("#new-thread-btn").get()
|
||||||
|
newThreadBtn.click()
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
let newThread = session.findElement("#new-thread")
|
||||||
|
check newThread.isSome()
|
||||||
|
|
||||||
|
let createThreadBtn = session.findElement("#create-thread-btn")
|
||||||
|
check createThreadBtn.isSome()
|
||||||
|
|
||||||
|
|
||||||
|
let threadTitle = session.findElement("#thread-title")
|
||||||
|
check threadTitle.isSome()
|
||||||
|
|
||||||
|
let replyBox = session.findElement("#reply-textarea")
|
||||||
|
check replyBox.isSome()
|
||||||
|
|
||||||
|
threadTitle.get().sendKeys("This is a thread title!")
|
||||||
|
replyBox.get().sendKeys("This is content.")
|
||||||
|
|
||||||
|
createThreadBtn.get().click()
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
let newThreadTitle = session.findElement("#thread-title")
|
||||||
|
check newThreadTitle.isSome()
|
||||||
|
|
||||||
|
check newThreadTitle.get().getText() == "This is a thread title!"
|
||||||
|
|
||||||
|
let content = session.findElement(".original-post div.post-content")
|
||||||
|
check content.isSome()
|
||||||
|
|
||||||
|
check content.get().getText() == "This is content."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue