From 6e2514fd88d678f7cd0ca32f713218548292601a Mon Sep 17 00:00:00 2001 From: Shagen Ogandzhanian Date: Wed, 7 Jul 2021 17:11:22 +0200 Subject: [PATCH] Move backgroundColor to a separate file and introduce dedicated test --- .../androidx/compose/web/css/CSSProperties.kt | 8 ----- .../compose/web/css/properties/background.kt | 18 +++++++++++ .../jsTest/kotlin/css/CSSBackgroundTests.kt | 32 +++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt create mode 100644 web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt index 8f4c4746a2..56926b2753 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt @@ -33,14 +33,6 @@ fun StyleBuilder.color(value: CSSColorValue) { property("color", value) } -fun StyleBuilder.backgroundColor(value: CSSColorValue) { - property("background-color", value) -} - -fun StyleBuilder.backgroundColor(value: String) { - property("background-color", value) -} - @Suppress("EqualsOrHashCode") class CSSBorder : CSSStyleValue { var width: CSSNumeric? = null diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt new file mode 100644 index 0000000000..eb2e501e46 --- /dev/null +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt @@ -0,0 +1,18 @@ +/* + * 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 + +fun StyleBuilder.backgroundColor(value: String) { + property("background-color", value) +} + +fun StyleBuilder.backgroundColor(value: CSSColorValue) { + property("background-color", value) +} + +fun StyleBuilder.backgroundColor(value: String) { + property("background-color", value) +} \ No newline at end of file diff --git a/web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt b/web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt new file mode 100644 index 0000000000..2bd397ddf5 --- /dev/null +++ b/web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt @@ -0,0 +1,32 @@ +/* + * 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 kotlinx.browser.window +import org.jetbrains.compose.web.core.tests.runTest +import org.jetbrains.compose.web.css.backgroundColor +import org.jetbrains.compose.web.dom.Div +import org.w3c.dom.HTMLElement +import org.w3c.dom.get +import kotlin.test.Test +import kotlin.test.assertEquals + +class CSSBackgroundTests { + @Test + fun backgroundColor() = runTest { + composition { + Div({style { + backgroundColor("rgb(0, 128, 0)") + }}) + Div({style { + backgroundColor("rgba(0, 129, 0, 0.2)") + }}) + } + + assertEquals("rgb(0, 128, 0)", window.getComputedStyle(root.children[0] as HTMLElement).backgroundColor) + assertEquals("rgba(0, 129, 0, 0.2)", window.getComputedStyle(root.children[1] as HTMLElement).backgroundColor) + } +} \ No newline at end of file