diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..e302029 --- /dev/null +++ b/build.sbt @@ -0,0 +1,20 @@ +enablePlugins(ScalaJSPlugin) + +name := "Scala.js Tutorial" +scalaVersion := "2.13.1" + +// This is an application with a main method +scalaJSUseMainModuleInitializer := true + +libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.0.0" +libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "1.0.0" + +skip in packageJSDependencies := false +jsDependencies += + "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.js" + +jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv() + +// uTest settings +libraryDependencies += "com.lihaoyi" %%% "utest" % "0.7.4" % "test" +testFrameworks += new TestFramework("utest.runner.Framework") diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..a82bb05 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.3.7 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..e93be7d --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32") diff --git a/scalajs-tutorial-fastopt.html b/scalajs-tutorial-fastopt.html new file mode 100644 index 0000000..582c082 --- /dev/null +++ b/scalajs-tutorial-fastopt.html @@ -0,0 +1,13 @@ + + +
+ +Hello World
") + } + + def addClickedMessage(): Unit = { + jQuery("body").append("You clicked the button!
") + } +} diff --git a/src/test/scala/tutorial/webapp/TutorialTest.scala b/src/test/scala/tutorial/webapp/TutorialTest.scala new file mode 100644 index 0000000..9d598a6 --- /dev/null +++ b/src/test/scala/tutorial/webapp/TutorialTest.scala @@ -0,0 +1,31 @@ +package tutorial.webapp + +import utest._ + +import org.scalajs.jquery._ + +object TutorialTest extends TestSuite { + + // Initialize App + TutorialApp.setupUI() + + def tests = Tests { + test("HelloWorld") { + assert(jQuery("p:contains('Hello World')").length == 1) + } + + test("ButtonClick") { + def messageCount = + jQuery("p:contains('You clicked the button!')").length + + val button = jQuery("button:contains('Click me!')") + assert(button.length == 1) + assert(messageCount == 0) + + for (c <- 1 to 5) { + button.click() + assert(messageCount == c) + } + } + } +}