Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for WebAssets class #412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include-build/roborazzi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dependencies {
integrationTestDepImplementation libs.android.tools.build.gradle
integrationTestDepImplementation libs.kotlin.gradle.plugin
integrationTestDepImplementation libs.compose.gradle.plugin
testImplementation libs.kotlin.test
testImplementation libs.kotlin.test.junit
testImplementation libs.junit
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import org.webjars.WebJarVersionLocator
import java.io.File

class WebAssets private constructor(private val webJarVersionLocator: WebJarVersionLocator) {
private val materializeCss = "materializecss"
private val materialIcons = "material-design-icons"
private val webJarResource = "resources"

val assets = assetPathsMap.entries.flatMap {
assets -> assets.value.map { it.substringAfterLast("/") }
}

fun writeToRoborazziReportsDir(reportDir: File) {
writeLocalAssetsToRoborazziReportsDir(reportDir)
writeWebJarAssetsToRoborazziReportsDir(reportDir)
Expand All @@ -22,16 +24,7 @@ class WebAssets private constructor(private val webJarVersionLocator: WebJarVers
}

private fun writeWebJarAssetsToRoborazziReportsDir(reportDir: File) {
mapOf(
materializeCss to listOf(
"css/materialize.min.css",
"js/materialize.min.js",
),
materialIcons to listOf(
"material-icons.css",
"MaterialIcons-Regular.ttf",
)
).forEach { (key, value) ->
assetPathsMap.forEach { (key, value) ->
value.forEach { exactPath ->
webJarVersionLocator.locate(key, exactPath)?.let {
writeAssets(
Expand Down Expand Up @@ -71,6 +64,17 @@ class WebAssets private constructor(private val webJarVersionLocator: WebJarVers

companion object {

private val assetPathsMap = mapOf(
"materializecss" to listOf(
"css/materialize.min.css",
"js/materialize.min.js",
),
"material-design-icons" to listOf(
"material-icons.css",
"MaterialIcons-Regular.ttf",
)
)

fun create(
webJarVersionLocator: WebJarVersionLocator = WebJarVersionLocator()
): WebAssets = WebAssets(webJarVersionLocator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.takahirom.roborazzi

import junit.framework.TestCase.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import java.io.File
import kotlin.test.Test

class WebAssetsTest {

@get:Rule
val tmpDir: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build()

private lateinit var sut: WebAssets

@Before
fun setUp() {
sut = WebAssets.create()
}

@Test
fun testWritesWebAssetsSuccessfullyToReportsDirectory() {
val reportDir = tmpDir.newFolder("roborazzi-reports")
val assetFiles = sut.assets.map { File(reportDir, "assets/$it") }

sut.writeToRoborazziReportsDir(reportDir)

assetFiles.forEach { file->
assertTrue(file.exists())
}
}
}
Loading