This repository has been archived by the owner on Oct 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from MITLibraries/128_roles
Publisher and Static Pages Specs
- Loading branch information
Showing
6 changed files
with
236 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import org.specs2.mutable._ | ||
import org.specs2.runner._ | ||
|
||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
import org.fest.assertions.Assertions.assertThat | ||
import play.api.Application | ||
import play.api.Play | ||
import play.api.Play.current | ||
import models.{ Publisher, User, Subscriber } | ||
|
||
/** | ||
* An integration test will fire up a whole play application in a real (or headless) browser | ||
*/ | ||
class PublisherPagesSpec extends Specification { | ||
|
||
def create_user(role: String) = User.make("bob", "bob@example.com", role, "identity") | ||
def make_subscriber(userid: Int) = Subscriber.make(userid, "Sub Name", "cat", "contact", Some("link"), Some("logo")) | ||
|
||
"Publisher pages" should { | ||
"index" should { | ||
"display information about publishers" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/publishers") | ||
assertThat(browser.title()).isEqualTo("Publishers - TopicHub") | ||
browser.pageSource must contain("Contribute your content to TopicHub") | ||
} | ||
|
||
"display sign up link" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/publishers") | ||
browser.pageSource must contain("/publishers/create") | ||
} | ||
|
||
"display links to browse exisiting publisher categories" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some("")) | ||
|
||
browser.goTo("http://localhost:" + port + "/publishers") | ||
browser.pageSource must contain("/publishers/browse?filter=category&value=pubcat") | ||
} | ||
} | ||
|
||
"browse categories" should { | ||
"display links to publishers" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some("")) | ||
|
||
browser.goTo("http://localhost:" + port + "/publishers") | ||
browser.$("a[href*='pubcat']").click(); | ||
assertThat(browser.title()).isEqualTo("Publisher Browse - TopicHub") | ||
} | ||
} | ||
|
||
"view publisher" should { | ||
"display publishers page" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some("http://www.example.com"), Some("")) | ||
browser.goTo("http://localhost:" + port + "/publisher/" + pub.id) | ||
assertThat(browser.title()).isEqualTo("Publisher - TopicHub") | ||
browser.pageSource must contain("No articles deposited") | ||
browser.$("a[href*='http://www.example.com']").getText() must equalTo("Site »") | ||
} | ||
|
||
"with no publisher link displays no link" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", None, Some("")) | ||
browser.goTo("http://localhost:" + port + "/publisher/" + pub.id) | ||
browser.pageSource must not contain("Site »") | ||
} | ||
|
||
"display links to publisher collections" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
skipped | ||
} | ||
|
||
"edit link" should { | ||
"displays to user associated with publisher" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val sub = make_subscriber(user.id) | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some("http://www.example.com"), Some("")) | ||
browser.goTo("http://localhost:" + port + "/publisher/" + pub.id) | ||
browser.pageSource must contain("/publisher/1/edit") | ||
} | ||
|
||
"not display to non logged in user" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
skipped(": need to be able to create a publisher without signing in user during test") | ||
} | ||
|
||
"not display to logged in user not associated with publisher" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub_user = User.make("pub", "pub@example.com", "some roles", "another_identity") | ||
val pub = Publisher.make(pub_user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some("http://www.example.com"), Some("")) | ||
browser.goTo("http://localhost:" + port + "/publisher/" + pub.id) | ||
browser.pageSource must not contain("/publisher/1/edit") | ||
} | ||
} | ||
} | ||
|
||
"create publisher" should { | ||
"redirect to login if not signed in" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/publishers") | ||
browser.$("a[href*='/publishers/create']").click() | ||
browser.pageSource must contain("Log in with your MIT ID") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"display create publisher form if signed in" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
browser.goTo("http://localhost:" + port + "/publishers") | ||
browser.$("a[href*='/publishers/create']").click() | ||
assertThat(browser.title()).isEqualTo("Create Publisher - TopicHub") | ||
} | ||
|
||
"creates publisher on submit" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
browser.goTo("http://localhost:" + port + "/publishers/create") | ||
browser.$("#tag").text("New Publisher Tag") | ||
browser.$("#name").text("New Publisher Name") | ||
browser.$("#description").text("New Publisher Description") | ||
browser.$("#submit").click | ||
assertThat(browser.title()).isEqualTo("Edit Publisher - TopicHub") | ||
} | ||
} | ||
|
||
"edit publisher" should { | ||
"redirects to login if not signed in" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
skipped(": need to be able to create a publisher without signing in user during test") | ||
} | ||
|
||
"redirects to trouble if user does not own publisher" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub_user = User.make("pub", "pub@example.com", "some roles", "another_identity") | ||
val pub = Publisher.make(pub_user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some("http://www.example.com"), Some("")) | ||
|
||
browser.goTo("http://localhost:" + port + "/publisher/1/edit") | ||
browser.pageSource must contain("Reason: You are not authorized") | ||
} | ||
|
||
"displays edit page if user owns publisher" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val user = create_user("norole") | ||
val pub = Publisher.make(user.id, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some("http://www.example.com"), Some("")) | ||
|
||
browser.goTo("http://localhost:" + port + "/publisher/1/edit") | ||
assertThat(browser.title()).isEqualTo("Edit Publisher - TopicHub") | ||
browser.pageSource must contain("/publisher/" + pub.id + "/create") | ||
browser.pageSource must contain("/publisher/" + pub.id + "/createH") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import org.specs2.mutable._ | ||
import org.specs2.runner._ | ||
|
||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
import org.fest.assertions.Assertions.assertThat | ||
import play.api.Application | ||
import play.api.Play | ||
import play.api.Play.current | ||
|
||
/** | ||
* An integration test will fire up a whole play application in a real (or headless) browser | ||
*/ | ||
class StaticPagesSpec extends Specification { | ||
|
||
"home" should { | ||
"displays welcome message" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port) | ||
browser.pageSource must contain("Welcome to SCOAP") | ||
assertThat(browser.title()).isEqualTo("SCOAP3 - TopicHub") | ||
} | ||
|
||
"displays Schemes with counts" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
// load pubmodel and cmodel | ||
// counts should all be zero | ||
// add some items with topic schmes, counts should new values | ||
skipped | ||
} | ||
} | ||
|
||
"about" should { | ||
"display about message" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/about") | ||
browser.pageSource must contain("About TopicHub") | ||
assertThat(browser.title()).isEqualTo("About - TopicHub") | ||
} | ||
|
||
"link to github" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/about") | ||
browser.pageSource must contain("https://github.com/MITLibraries/scoap3hub") | ||
} | ||
} | ||
|
||
"feedback" should { | ||
"displays form" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/feedback") | ||
browser.pageSource must contain("Feedback") | ||
assertThat(browser.title()).isEqualTo("Feedback - TopicHub") | ||
} | ||
|
||
"submitting without required fields retains filled out fields" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/feedback") | ||
browser.$("#email").text("popcorn@example.com") | ||
browser.$("#reply").click | ||
browser.$("#sendbutton").click | ||
assertThat(browser.title()).isEqualTo("Feedback - TopicHub") | ||
browser.pageSource must contain("popcorn@example.com") | ||
browser.pageSource must contain("This field is required") | ||
} | ||
|
||
"submitted form generates an email" in new WithBrowser(app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
skipped | ||
} | ||
} | ||
} |