-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5da943
commit 9e4a00b
Showing
6 changed files
with
191 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...g/impl/src/test/kotlin/com/blacksquircle/ui/feature/changelog/ChangelogRepositoryTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2023 Squircle CE contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blacksquircle.ui.feature.changelog | ||
|
||
import android.content.Context | ||
import android.content.res.Resources | ||
import com.blacksquircle.ui.core.tests.TestDispatcherProvider | ||
import com.blacksquircle.ui.feature.changelog.data.repository.ChangelogRepositoryImpl | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
import java.io.InputStream | ||
|
||
class ChangelogRepositoryTests { | ||
|
||
@Test | ||
fun `When loading changelog Then read data from resource file`() = runTest { | ||
// Given | ||
val resources = mockk<Resources>() | ||
val context = mockk<Context>() | ||
every { context.resources } returns resources | ||
every { resources.openRawResource(any()) } returns InputStream.nullInputStream() | ||
|
||
val repository = ChangelogRepositoryImpl( | ||
dispatcherProvider = TestDispatcherProvider(), | ||
context = context | ||
) | ||
|
||
// When | ||
repository.loadChangelog() | ||
|
||
// Then | ||
verify(exactly = 1) { resources.openRawResource(R.raw.changelog) } | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...gelog/impl/src/test/kotlin/com/blacksquircle/ui/feature/changelog/ReleaseConverterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2023 Squircle CE contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blacksquircle.ui.feature.changelog | ||
|
||
import com.blacksquircle.ui.feature.changelog.data.converter.ReleaseConverter | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Test | ||
|
||
class ReleaseConverterTest { | ||
|
||
@Test | ||
fun `When converting changelog Then check list size`() { | ||
// Given | ||
val testData = """ | ||
<b>v2018.1.2, 11 Feb. 2018</b><br> | ||
• <b>Added:</b> Line №1<br> | ||
• <b>Fixed:</b> Line №2<br> | ||
• <b>Fixed:</b> Line №3<br> | ||
• Line №4<br> | ||
<br> | ||
<b>v2018.1.1, 28 Jan. 2018</b><br> | ||
• <b>Added:</b> Line №1<br> | ||
• <b>Added:</b> Line №2<br> | ||
• Line №3<br> | ||
<br> | ||
<b>v2018.1.0, 23 Jan. 2018</b><br> | ||
• Line №1<br> | ||
<br> | ||
""".trimIndent() | ||
|
||
// When | ||
val releaseList = ReleaseConverter.toReleaseModels(testData) | ||
|
||
// Then | ||
assertEquals(3, releaseList.size) | ||
} | ||
|
||
@Test | ||
fun `When converting changelog Then verify release info`() { | ||
// Given | ||
val testData = """ | ||
<b>v2018.1.2, 11 Feb. 2018</b><br> | ||
• <b>Added:</b> Line №1<br> | ||
• <b>Fixed:</b> Line №2<br> | ||
• <b>Fixed:</b> Line №3<br> | ||
• Line №4<br> | ||
<br> | ||
""".trimIndent() | ||
|
||
// When | ||
val releaseModel = ReleaseConverter.toReleaseModels(testData).first() | ||
|
||
// Then | ||
assertEquals("v2018.1.2", releaseModel.versionName) | ||
assertEquals("11 Feb. 2018", releaseModel.releaseDate) | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
...re-settings/impl/src/test/kotlin/com/blacksquircle/ui/feature/settings/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
...ngs/impl/src/test/kotlin/com/blacksquircle/ui/feature/settings/SettingsRepositoryTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2023 Squircle CE contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blacksquircle.ui.feature.settings | ||
|
||
import android.content.Context | ||
import com.blacksquircle.ui.core.storage.keyvalue.SettingsManager | ||
import com.blacksquircle.ui.feature.settings.data.repository.SettingsRepositoryImpl | ||
import com.blacksquircle.ui.feature.settings.domain.model.KeyModel | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Test | ||
|
||
class SettingsRepositoryTests { | ||
|
||
@Test | ||
fun `When loading keyboard preset Then return keys list containing a tab`() { | ||
// Given | ||
val repository = SettingsRepositoryImpl( | ||
settingsManager = mockk<SettingsManager>().apply { | ||
every { keyboardPreset } returns "ABC" | ||
}, | ||
context = mockk<Context>().apply { | ||
every { getString(any()) } returns "Tab" | ||
}, | ||
) | ||
|
||
// When | ||
val actual = repository.keyboardPreset() | ||
|
||
// Then | ||
val expected = listOf( | ||
KeyModel(display = "Tab", value = '\t'), | ||
KeyModel(display = "A", value = 'A'), | ||
KeyModel(display = "B", value = 'B'), | ||
KeyModel(display = "C", value = 'C'), | ||
) | ||
assertEquals(expected, actual) | ||
} | ||
} |