Merge pull request #179 from jyapayne/add_threads_test

Add threads tests
This commit is contained in:
Dominik Picheta 2018-07-13 11:50:42 +01:00 committed by GitHub
commit 82ff2fb212
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 28 deletions

View file

@ -49,7 +49,7 @@ when defined(js):
tdiv(class="title"):
p(): text "New Thread"
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",
oninput=(e: Event, n: VNode) => onSubjectChange(e, n, state))
if state.error.isSome():
@ -58,10 +58,11 @@ when defined(js):
renderContent(state.replyBox, none[Thread](), none[Post]())
tdiv(class="footer"):
button(class=class(
{"loading": state.loading},
"btn btn-primary"
button(id="create-thread-btn",
class=class(
{"loading": state.loading},
"btn btn-primary"
),
onClick=(ev: Event, n: VNode) =>
(onCreateClick(ev, n, state))):
text "Create thread"
text "Create thread"

View file

@ -220,8 +220,11 @@ when defined(js):
): VNode =
let postCopy = post # TODO: Another workaround here, closure capture :(
let originalPost = thread.author == post.author
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"):
render(post.author, "post-avatar")
tdiv(class="post-main"):
@ -326,7 +329,7 @@ when defined(js):
let list = state.list.get()
result = buildHtml():
section(class="container grid-xl"):
tdiv(class="title"):
tdiv(id="thread-title", class="title"):
p(): text list.thread.topic
if list.thread.isLocked:
italic(class="fas fa-lock fa-xs",
@ -368,4 +371,4 @@ when defined(js):
render(state.replyBox, list.thread, state.replyingTo, false)
render(state.deleteModal)
render(state.deleteModal)

View file

@ -114,7 +114,8 @@ when defined(js):
elif state.rendering.isSome():
verbatim(state.rendering.get())
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, n, state),
value=state.text)
@ -162,4 +163,4 @@ when defined(js):
button(class="btn"):
italic(class="fas fa-arrow-up")
tdiv(class="information-content"):
renderContent(state, some(thread), post)
renderContent(state, some(thread), post)

View file

@ -78,7 +78,7 @@ when defined(js):
button(class="btn btn-link"): text "Categories"
section(class="navbar-section"):
if currentUser.isSome():
a(href=makeUri("/newthread"), onClick=anchorCB):
a(id="new-thread-btn", href=makeUri("/newthread"), onClick=anchorCB):
button(class="btn btn-secondary"):
italic(class="fas fa-plus")
text " New Thread"
@ -243,4 +243,4 @@ when defined(js):
proc renderThreadList*(currentUser: Option[User]): VNode =
result = buildHtml(tdiv):
genTopButtons(currentUser)
genThreadList(currentUser)
genThreadList(currentUser)

View file

@ -44,6 +44,7 @@ template withBackend(body: untyped): untyped =
body
import browsertests/scenario1
import browsertests/threads
when isMainModule:
spawn runProcess("geckodriver -p 4444 --log config")
@ -63,8 +64,9 @@ when isMainModule:
withBackend:
scenario1.test(session, baseUrl)
threads.test(session, baseUrl)
session.close()
except:
sleep(10000) # See if we can grab any more output.
raise
raise

View 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)

View file

@ -1,20 +1,7 @@
import unittest, options, os
import unittest, options, os, common
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) =
session.navigate(baseUrl)
@ -112,4 +99,6 @@ proc test*(session: Session, baseUrl: string) =
"#main-navbar .menu-right div.tile-content"
).get()
check profileName.getText() == "test"
check profileName.getText() == "test"
logout(session)

View 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."