Skip to content

Commit

Permalink
Merge pull request #1657 from arkadius/liftJavaScriptSpecFix2
Browse files Browse the repository at this point in the history
Tweaked the merge a bit to keep only the relevant commit.

Generated Lift JS is localized based on the current environment. However,
LiftJavaScriptSpec checks for English messages, so running it under a
non-English environment causes it to fail due to the mismatch in expected
message.  Now settings are tested with english locale, internationalization is
tested separately.
  • Loading branch information
Shadowfiend committed Jan 10, 2015
2 parents 1bc951e + 3ea320b commit 65fc960
Showing 1 changed file with 33 additions and 7 deletions.
Expand Up @@ -18,7 +18,10 @@ package net.liftweb
package http
package js

import org.specs2.mutable.Specification
import java.util.Locale

import org.specs2.execute.{Result, AsResult}
import org.specs2.mutable.{Around, Specification}

import common._
import http.js._
Expand All @@ -37,34 +40,41 @@ object LiftJavaScriptSpec extends Specification {
private def session = new LiftSession("", randomString(20), Empty)

"LiftJavaScript" should {
"create default settings" in {
"create default settings" in withEnglishLocale {
S.initIfUninitted(session) {
val settings = LiftJavaScript.settings
settings.toJsCmd must_== """{"liftPath": "/lift", "ajaxRetryCount": 3, "ajaxPostTimeout": 5000, "gcPollingInterval": 75000, "gcFailureRetryTimeout": 15000, "cometGetTimeout": 140000, "cometFailureRetryTimeout": 10000, "cometServer": null, "logError": function(msg) {}, "ajaxOnFailure": function() {alert("The server cannot be contacted at this time");}, "ajaxOnStart": function() {}, "ajaxOnEnd": function() {}}"""
}
}
"create custom static settings" in {
"create internationalized default settings" in withPolishLocale {
S.initIfUninitted(session) {
val settings = LiftJavaScript.settings
val internationalizedMessage = "Nie mo\\u017cna skontaktowa\\u0107 si\\u0119 z serwerem"
settings.toJsCmd must_== s"""{"liftPath": "/lift", "ajaxRetryCount": 3, "ajaxPostTimeout": 5000, "gcPollingInterval": 75000, "gcFailureRetryTimeout": 15000, "cometGetTimeout": 140000, "cometFailureRetryTimeout": 10000, "cometServer": null, "logError": function(msg) {}, "ajaxOnFailure": function() {alert("$internationalizedMessage");}, "ajaxOnStart": function() {}, "ajaxOnEnd": function() {}}"""
}
}
"create custom static settings" in withEnglishLocale {
S.initIfUninitted(session) {
LiftRules.ajaxRetryCount = Full(4)
val settings = LiftJavaScript.settings
settings.toJsCmd must_== """{"liftPath": "/lift", "ajaxRetryCount": 4, "ajaxPostTimeout": 5000, "gcPollingInterval": 75000, "gcFailureRetryTimeout": 15000, "cometGetTimeout": 140000, "cometFailureRetryTimeout": 10000, "cometServer": null, "logError": function(msg) {}, "ajaxOnFailure": function() {alert("The server cannot be contacted at this time");}, "ajaxOnStart": function() {}, "ajaxOnEnd": function() {}}"""
}
}
"create custom dynamic settings" in {
"create custom dynamic settings" in withEnglishLocale {
S.initIfUninitted(session) {
LiftRules.cometServer = () => Some("srvr1")
val settings = LiftJavaScript.settings
settings.toJsCmd must_== """{"liftPath": "/lift", "ajaxRetryCount": 4, "ajaxPostTimeout": 5000, "gcPollingInterval": 75000, "gcFailureRetryTimeout": 15000, "cometGetTimeout": 140000, "cometFailureRetryTimeout": 10000, "cometServer": "srvr1", "logError": function(msg) {}, "ajaxOnFailure": function() {alert("The server cannot be contacted at this time");}, "ajaxOnStart": function() {}, "ajaxOnEnd": function() {}}"""
}
}
"create custom function settings" in {
"create custom function settings" in withEnglishLocale {
S.initIfUninitted(session) {
LiftRules.jsLogFunc = Full(v => JE.Call("lift.logError", v))
val settings = LiftJavaScript.settings
settings.toJsCmd must_== """{"liftPath": "/lift", "ajaxRetryCount": 4, "ajaxPostTimeout": 5000, "gcPollingInterval": 75000, "gcFailureRetryTimeout": 15000, "cometGetTimeout": 140000, "cometFailureRetryTimeout": 10000, "cometServer": "srvr1", "logError": function(msg) {lift.logError(msg);}, "ajaxOnFailure": function() {alert("The server cannot be contacted at this time");}, "ajaxOnStart": function() {}, "ajaxOnEnd": function() {}}"""
}
}
"create init command" in {
"create init command" in withEnglishLocale {
S.initIfUninitted(session) {
val init = LiftRules.javaScriptSettings.vend().map(_.apply(session)).map(LiftJavaScript.initCmd(_).toJsCmd)
init must_==
Expand All @@ -73,7 +83,7 @@ object LiftJavaScriptSpec extends Specification {
|window.lift.init(lift_settings);""".stripMargin)
}
}
"create init command with custom setting" in {
"create init command with custom setting" in withEnglishLocale {
S.initIfUninitted(session) {
val settings = LiftJavaScript.settings.extend(JsObj("liftPath" -> "liftyStuff", "mysetting" -> 99))
val init = LiftJavaScript.initCmd(settings)
Expand All @@ -85,4 +95,20 @@ object LiftJavaScriptSpec extends Specification {
}
}
}

object withEnglishLocale extends WithLocale(Locale.ENGLISH)

object withPolishLocale extends WithLocale(Locale.forLanguageTag("pl-PL"))

class WithLocale(locale: Locale) extends Around {
override def around[T: AsResult](test: => T): Result = {
val savedDefaultLocale = Locale.getDefault
Locale.setDefault(locale)
try {
AsResult(test)
} finally {
Locale.setDefault(savedDefaultLocale)
}
}
}
}

0 comments on commit 65fc960

Please sign in to comment.