Browse Source

Introduce separate test for stylesheet inheritance

pull/1597/head
Shagen Ogandzhanian 3 years ago
parent
commit
211fe2e63f
  1. 14
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt
  2. 6
      web/core/src/jsTest/kotlin/css/AnimationTests.kt
  3. 45
      web/core/src/jsTest/kotlin/css/StyleSheetTests.kt

14
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt

@ -0,0 +1,14 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.css.utils
import org.jetbrains.compose.web.css.StyleSheet
import org.jetbrains.compose.web.dom.stringPresentation
fun StyleSheet.serializeRules(): List<String> {
return cssRules.map { it.stringPresentation(indent = " ", delimiter = "") }
}

6
web/core/src/jsTest/kotlin/css/AnimationTests.kt

@ -5,9 +5,9 @@
package org.jetbrains.compose.web.core.tests.css
import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.jetbrains.compose.web.testutils.*
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.dom.stringPresentation
import org.jetbrains.compose.web.css.utils.serializeRules
import org.jetbrains.compose.web.testutils.runTest
import org.w3c.dom.HTMLStyleElement
import org.w3c.dom.css.CSSStyleSheet
import org.w3c.dom.get
@ -39,7 +39,7 @@ object AnimationsStyleSheet : StyleSheet() {
class AnimationTests {
@Test
fun animationClassGenerated() = runTest {
val generatedRules = AnimationsStyleSheet.cssRules.map { it.stringPresentation(indent = " ", delimiter = "") }
val generatedRules = AnimationsStyleSheet.serializeRules()
assertContentEquals(

45
web/core/src/jsTest/kotlin/css/StyleSheetTests.kt

@ -0,0 +1,45 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.core.tests.css
import org.jetbrains.compose.web.css.Color
import org.jetbrains.compose.web.css.StyleSheet
import org.jetbrains.compose.web.css.color
import org.jetbrains.compose.web.css.utils.serializeRules
import kotlin.test.Test
import kotlin.test.assertContentEquals
class StyleSheetTests {
@Test
fun extendExistingStyleSheet() {
val styleSheet = object : StyleSheet(usePrefix = false) {
val someClassName by style {
color(Color.red)
}
}
val childStyleSheet = object : StyleSheet(styleSheet, usePrefix = false) {
val someClassName by style {
color(Color.green)
}
}
assertContentEquals(
listOf(".someClassName { color: red;}", ".someClassName { color: green;}"),
styleSheet.serializeRules(),
"styleSheet rules"
)
assertContentEquals(
listOf(".someClassName { color: red;}", ".someClassName { color: green;}"),
childStyleSheet.serializeRules(),
"childStyleSheet rules"
)
}
}
Loading…
Cancel
Save