Skip to content

Commit

Permalink
Switched to Scala.js v1.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Jan 26, 2022
1 parent c62cc04 commit d1e6eb7
Show file tree
Hide file tree
Showing 19 changed files with 1,704 additions and 1,871 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

[![Build Status](https://travis-ci.com/scommons/scommons-client.svg?branch=master)](https://travis-ci.com/scommons/scommons-client)
[![Coverage Status](https://coveralls.io/repos/github/scommons/scommons-client/badge.svg?branch=master)](https://coveralls.io/github/scommons/scommons-client?branch=master)
[![scala-index](https://index.scala-lang.org/scommons/scommons-client/scommons-client-ui/latest-by-scala-version.svg?targetType=Js)](https://index.scala-lang.org/scommons/scommons-client/scommons-client-ui)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
[![scala-index](https://index.scala-lang.org/scommons/scommons-client/scommons-client-ui/latest.svg)](https://index.scala-lang.org/scommons/scommons-client/scommons-client-ui)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.1.0.svg)](https://www.scala-js.org)

## Scala Commons Client
Common Scala.js, React.js web-client utilities and components.
Expand Down
18 changes: 9 additions & 9 deletions docs/showcase/assets/scommons-client-showcase-opt-library.js

Large diffs are not rendered by default.

2,871 changes: 1,399 additions & 1,472 deletions docs/showcase/assets/scommons-client-showcase-opt.js

Large diffs are not rendered by default.

210 changes: 105 additions & 105 deletions docs/showcase/assets/styles/scommons-client-showcase-opt.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

//addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin-sjs06" % "0.7.0-SNAPSHOT").changing())
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin-sjs06" % "0.7.0")
addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.8.0-SNAPSHOT").changing())
//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.8.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.3")

Expand Down
4 changes: 2 additions & 2 deletions project/src/main/scala/common/Libs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import scommons.sbtplugin.project.CommonLibs
object Libs extends CommonLibs {

val scommonsNodejsVersion = "0.7.0"
val scommonsReactVersion = "0.7.0"
val scommonsReactVersion = "1.0.0-SNAPSHOT"
private val scommonsApiVersion = "0.7.0"
private val sjsReactJsVer = "0.17.0"
private val sjsReactJsVer = "0.17.1"

lazy val scommonsApiXhr = Def.setting("org.scommons.api" %%% "scommons-api-xhr" % scommonsApiVersion)

Expand Down
25 changes: 24 additions & 1 deletion project/src/main/scala/definitions/ScalaJsModule.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package definitions

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._
import scommons.sbtplugin.ScommonsPlugin.autoImport._
import scommons.sbtplugin.project.CommonClientModule
import scoverage.ScoverageKeys.{coverageEnabled, coverageScalacPluginVersion}

trait ScalaJsModule extends ClientModule {

Expand All @@ -16,7 +18,28 @@ trait ScalaJsModule extends ClientModule {
.settings(CommonClientModule.settings: _*)
.settings(
scommonsRequireWebpackInTest := true,
webpackConfigFile in Test := Some(baseDirectory.value / "test.webpack.config.js")
webpackConfigFile in Test := Some(baseDirectory.value / "test.webpack.config.js"),

//TODO: remove these temporal fixes for Scala.js 1.1+ and scoverage
coverageScalacPluginVersion := {
val current = coverageScalacPluginVersion.value
if (scalaJSVersion.startsWith("0.6")) current
else "1.4.2" //the only version that supports Scala.js 1.1+
},
libraryDependencies ~= { modules =>
if (scalaJSVersion.startsWith("0.6")) modules
else modules.filter(_.organization != "org.scoverage")
},
libraryDependencies ++= {
if (coverageEnabled.value) {
if (scalaJSVersion.startsWith("0.6")) Nil
else Seq(
"org.scoverage" %% "scalac-scoverage-runtime_sjs1" % coverageScalacPluginVersion.value,
"org.scoverage" %% "scalac-scoverage-plugin" % coverageScalacPluginVersion.value % "scoveragePlugin"
)
}
else Nil
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package scommons.client.ui.select

import org.scalajs.dom.window
import scommons.react._

import scala.concurrent.Future
import scala.concurrent.duration._
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global
import scala.util.{Failure, Success}

case class SearchSelectProps(selected: Option[SelectData],
Expand All @@ -17,7 +17,6 @@ case class SearchSelectProps(selected: Option[SelectData],

object SearchSelect extends ClassComponent[SearchSelectProps] {

private[select] var global: js.Dynamic = window.asInstanceOf[js.Dynamic]
private[select] var singleSelectComp: UiComponent[SingleSelectProps] = SingleSelect

private case class SearchSelectState(isLoading: Boolean = false,
Expand Down
50 changes: 14 additions & 36 deletions ui/src/test/scala/scommons/client/controller/RouteParamsSpec.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package scommons.client.controller

import io.github.shogowada.scalajs.history.History
import io.github.shogowada.scalajs.reactjs.router.Location
import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.router.RouterProps.RouterProps
import scommons.client.controller.RouteParamsSpec._
import scommons.react.test.TestSpec

import scala.scalajs.js.annotation.JSExportAll
import scala.scalajs.js.Dynamic.literal

class RouteParamsSpec extends TestSpec {

it should "return PathParams from pathname when pathParams" in {
//given
val routerProps = mock[RouterProps]
val location = mock[LocationMock]
val pathname = "/app/1/2//3/"
val location = literal("pathname" -> pathname)
val nativeProps = literal("location" -> location)
val routerProps = new RouterProps(Props[Unit](nativeProps))
val routeParams = new RouteParams(routerProps)

(routerProps.location _).expects().returning(location.asInstanceOf[Location])
(location.pathname _).expects().returning(pathname)

//when
val result = routeParams.pathParams
Expand All @@ -29,15 +25,12 @@ class RouteParamsSpec extends TestSpec {

it should "return PathParams from pathname and search when allParams" in {
//given
val routerProps = mock[RouterProps]
val location = mock[LocationMock]
val pathname = "/app/1/2//3/"
val search = "?testId=123"
val location = literal("pathname" -> pathname, "search" -> search)
val nativeProps = literal("location" -> location)
val routerProps = new RouterProps(Props[Unit](nativeProps))
val routeParams = new RouteParams(routerProps)

(routerProps.location _).expects().returning(location.asInstanceOf[Location])
(location.pathname _).expects().returning(pathname)
(location.search _).expects().returning(search)

//when
val result = routeParams.allParams
Expand All @@ -48,32 +41,17 @@ class RouteParamsSpec extends TestSpec {

it should "push url to the browser history" in {
//given
val routerProps = mock[RouterProps]
val history = mock[HistoryMock]
val url = "/app/1/2//3/"
val pushMock = mockFunction[String, Unit]
val history = literal("push" -> pushMock)
val nativeProps = literal("history" -> history)
val routerProps = new RouterProps(Props[Unit](nativeProps))
val routeParams = new RouteParams(routerProps)
val url = "/app/1/2//3/"

//then
(routerProps.history _).expects().returning(history.asInstanceOf[History])
(history.push _).expects(url)
pushMock.expects(url)

//when
routeParams.push(url)
}
}

object RouteParamsSpec {

@JSExportAll
trait LocationMock {

def pathname: String
def search: String
}

@JSExportAll
trait HistoryMock {

def push(url: String): Unit
}
}
33 changes: 13 additions & 20 deletions ui/src/test/scala/scommons/client/ui/ImageButtonSpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package scommons.client.ui

import scommons.client.ui.ButtonImagesCss._
import scommons.client.ui.ImageButtonSpec._
import scommons.react.test._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportAll
import scala.scalajs.js.Dynamic.literal

class ImageButtonSpec extends TestSpec with TestRendererUtils {

Expand Down Expand Up @@ -109,14 +108,15 @@ class ImageButtonSpec extends TestSpec with TestRendererUtils {
//given
val data = ImageButtonData("accept", accept, acceptDisabled, "test button")
val props = ImageButtonProps(data, () => (), requestFocus = true)
val buttonMock = mock[ButtonMock]
val focusMock = mockFunction[Unit]
val buttonMock = literal("focus" -> focusMock)

//then
(buttonMock.focus _).expects()
focusMock.expects()

//when
testRender(<(ImageButton())(^.wrapped := props)(), { el =>
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock.asInstanceOf[js.Any]
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock
else null
})
}
Expand All @@ -125,16 +125,17 @@ class ImageButtonSpec extends TestSpec with TestRendererUtils {
//given
val data = ImageButtonData("accept", accept, acceptDisabled, "test button")
val prevProps = ImageButtonProps(data, () => ())
val buttonMock = mock[ButtonMock]
val focusMock = mockFunction[Unit]
val buttonMock = literal("focus" -> focusMock)
val renderer = createTestRenderer(<(ImageButton())(^.wrapped := prevProps)(), { el =>
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock.asInstanceOf[js.Any]
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock
else null
})
val props = ImageButtonProps(data, () => (), requestFocus = true)
props should not be prevProps

//then
(buttonMock.focus _).expects()
focusMock.expects()

//when
TestRenderer.act { () =>
Expand All @@ -146,29 +147,21 @@ class ImageButtonSpec extends TestSpec with TestRendererUtils {
//given
val data = ImageButtonData("accept", accept, acceptDisabled, "test button")
val prevProps = ImageButtonProps(data, () => ())
val buttonMock = mock[ButtonMock]
val focusMock = mockFunction[Unit]
val buttonMock = literal("focus" -> focusMock)
val renderer = createTestRenderer(<(ImageButton())(^.wrapped := prevProps)(), { el =>
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock.asInstanceOf[js.Any]
if (el.`type` == "button".asInstanceOf[js.Any]) buttonMock
else null
})
val props = ImageButtonProps(data, () => (), showTextAsTitle = true)
props should not be prevProps

//then
(buttonMock.focus _).expects().never()
focusMock.expects().never()

//when
TestRenderer.act { () =>
renderer.update(<(ImageButton())(^.wrapped := props)())
}
}
}

object ImageButtonSpec {

@JSExportAll
trait ButtonMock {

def focus(): Unit
}
}
Loading

0 comments on commit d1e6eb7

Please sign in to comment.