-
Notifications
You must be signed in to change notification settings - Fork 1
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
ksnd
committed
May 11, 2023
1 parent
e2b4581
commit 05b0d6e
Showing
4 changed files
with
67 additions
and
1 deletion.
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
7 changes: 7 additions & 0 deletions
7
core/mock/src/main/java/kosenda/makecolor/core/mock/MockHsvColor.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,7 @@ | ||
package kosenda.makecolor.core.mock | ||
|
||
import com.godaddy.android.colorpicker.HsvColor | ||
|
||
class MockHsvColor { | ||
val item = HsvColor(hue = 180f, saturation = 0.9f, value = 0.9f, alpha = 1f) | ||
} |
1 change: 0 additions & 1 deletion
1
...ure/makecolor/src/test/java/kosenda/makecolor/feature/viewmodel/MergeViewModelImplTest.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
59 changes: 59 additions & 0 deletions
59
...re/makecolor/src/test/java/kosenda/makecolor/feature/viewmodel/PickerViewModelImplTest.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,59 @@ | ||
package kosenda.makecolor.feature.viewmodel | ||
|
||
import com.godaddy.android.colorpicker.harmony.ColorHarmonyMode | ||
import com.google.common.truth.Truth.assertThat | ||
import kosenda.makecolor.core.mock.MockHsvColor | ||
import kosenda.makecolor.core.model.data.ColorData | ||
import kosenda.makecolor.core.ui.data.PickerType | ||
import kosenda.makecolor.core.util.hsvColorToHsv | ||
import kosenda.makecolor.core.util.hsvToRGB | ||
import kosenda.makecolor.core.util.rgbToCmyk | ||
import kosenda.makecolor.core.util.rgbToHex | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class PickerViewModelImplTest { | ||
|
||
private val viewModel = PickerViewModelImpl() | ||
|
||
@Test | ||
fun updateColorData_hsvColor_updatedUiState() { | ||
// hsvColorを渡したときにColorDataが作成されUiStateに反映されることを確認する | ||
val hsv = hsvColorToHsv(hsvColor = MockHsvColor().item) | ||
val rgb = hsvToRGB(hsv = hsv) | ||
val cmyk = rgbToCmyk(rgb) | ||
val hex = rgbToHex(rgb) | ||
viewModel.updateColorData(MockHsvColor().item) | ||
assertThat(viewModel.uiState.value.colorData).isEqualTo(ColorData(rgb, cmyk, hsv, hex)) | ||
} | ||
|
||
@Test | ||
fun updateHsvColor_hsvColor_updatedUiState() { | ||
// hsvColorを渡したときにUiStateに反映されることを確認する | ||
val originColorData = viewModel.uiState.value.colorData | ||
val originHsvColorData = viewModel.uiState.value.hsvColorData | ||
viewModel.updateHsvColor(MockHsvColor().item) | ||
assertThat(viewModel.uiState.value.colorData).isNotEqualTo(originColorData) | ||
assertThat(viewModel.uiState.value.hsvColorData).isNotEqualTo(originHsvColorData) | ||
} | ||
|
||
@Test | ||
fun updatePickerType_pickerType_updatedUiState() { | ||
// pickerTypeを渡したときにUiStateに反映されることを確認する | ||
viewModel.updatePickerType(PickerType.CIRCLE) | ||
assertThat(viewModel.uiState.value.pickerType).isEqualTo(PickerType.CIRCLE) | ||
viewModel.updatePickerType(PickerType.SQUARE) | ||
assertThat(viewModel.uiState.value.pickerType).isEqualTo(PickerType.SQUARE) | ||
} | ||
|
||
@Test | ||
fun updateHarmonyMode_colorHarmonyMode_updatedUiState() { | ||
// colorHarmonyModeを渡したときにUiStateに反映されることを確認する | ||
viewModel.updateHarmonyMode(ColorHarmonyMode.COMPLEMENTARY) | ||
assertThat(viewModel.uiState.value.harmonyMode).isEqualTo(ColorHarmonyMode.COMPLEMENTARY) | ||
viewModel.updateHarmonyMode(ColorHarmonyMode.ANALOGOUS) | ||
assertThat(viewModel.uiState.value.harmonyMode).isEqualTo(ColorHarmonyMode.ANALOGOUS) | ||
} | ||
} |