From 5714ad0c6aafcd7b95a433d97f7b4069d5cc791b Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 20 Jul 2018 15:16:39 +0100 Subject: [PATCH] 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. --- src/frontend/profilesettings.nim | 5 +-- tests/browsertester.nim | 5 +-- tests/browsertests/common.nim | 54 +++++++++++++++++++++++++++++++- tests/browsertests/issue181.nim | 46 +++++++++++++++++++++++++++ tests/browsertests/scenario1.nim | 29 ++--------------- 5 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 tests/browsertests/issue181.nim diff --git a/src/frontend/profilesettings.nim b/src/frontend/profilesettings.nim index 07862b7..ca96361 100644 --- a/src/frontend/profilesettings.nim +++ b/src/frontend/profilesettings.nim @@ -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" diff --git a/tests/browsertester.nim b/tests/browsertester.nim index 646ab79..15a3f68 100644 --- a/tests/browsertester.nim +++ b/tests/browsertester.nim @@ -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: diff --git a/tests/browsertests/common.nim b/tests/browsertests/common.nim index a2fb09b..9a0c17a 100644 --- a/tests/browsertests/common.nim +++ b/tests/browsertests/common.nim @@ -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" diff --git a/tests/browsertests/issue181.nim b/tests/browsertests/issue181.nim new file mode 100644 index 0000000..3e28737 --- /dev/null +++ b/tests/browsertests/issue181.nim @@ -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) diff --git a/tests/browsertests/scenario1.nim b/tests/browsertests/scenario1.nim index 18d1bc7..5dbc8b6 100644 --- a/tests/browsertests/scenario1.nim +++ b/tests/browsertests/scenario1.nim @@ -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()