@@ -5,8 +5,8 @@ import androidx.datastore.core.DataStoreFactory
5
5
import androidx.datastore.dataStoreFile
6
6
import androidx.test.core.app.ApplicationProvider
7
7
import com.google.common.truth.Truth.assertThat
8
+ import dev.shorthouse.coinwatch.data.datastore.CoinSort
8
9
import dev.shorthouse.coinwatch.data.datastore.Currency
9
- import dev.shorthouse.coinwatch.data.datastore.UserPreferences
10
10
import dev.shorthouse.coinwatch.data.datastore.UserPreferencesRepository
11
11
import dev.shorthouse.coinwatch.data.datastore.UserPreferencesSerializer
12
12
import kotlinx.coroutines.Dispatchers
@@ -53,54 +53,112 @@ class UserPreferencesRepositoryTest {
53
53
@Test
54
54
fun when_setCurrencyToUSD_should_updateUserPreferencesCurrencyToUSD () =
55
55
testCoroutineScope.runTest {
56
- val expectedUserPreferences = UserPreferences (
57
- currency = Currency .USD
58
- )
56
+ val currency = Currency .USD
59
57
60
58
userPreferencesRepository.updateCurrency(
61
- currency = Currency . USD
59
+ currency = currency
62
60
)
63
61
64
62
val userPreferences = userPreferencesRepository
65
63
.userPreferencesFlow
66
64
.first()
67
65
68
- assertThat(userPreferences).isEqualTo(expectedUserPreferences )
66
+ assertThat(userPreferences.currency ).isEqualTo(currency )
69
67
}
70
68
71
69
@Test
72
70
fun when_setCurrencyToGBP_should_updateUserPreferencesCurrencyToGBP () =
73
71
testCoroutineScope.runTest {
74
- val expectedUserPreferences = UserPreferences (
75
- currency = Currency .GBP
76
- )
72
+ val currency = Currency .GBP
77
73
78
74
userPreferencesRepository.updateCurrency(
79
- currency = Currency . GBP
75
+ currency = currency
80
76
)
81
77
82
78
val userPreferences = userPreferencesRepository
83
79
.userPreferencesFlow
84
80
.first()
85
81
86
- assertThat(userPreferences).isEqualTo(expectedUserPreferences )
82
+ assertThat(userPreferences.currency ).isEqualTo(currency )
87
83
}
88
84
89
85
@Test
90
86
fun when_setCurrencyToEUR_should_updateUserPreferencesCurrencyToEUR () =
91
87
testCoroutineScope.runTest {
92
- val expectedUserPreferences = UserPreferences (
93
- currency = Currency .EUR
94
- )
88
+ val currency = Currency .EUR
95
89
96
90
userPreferencesRepository.updateCurrency(
97
- currency = Currency .EUR
91
+ currency = currency
92
+ )
93
+
94
+ val userPreferences = userPreferencesRepository
95
+ .userPreferencesFlow
96
+ .first()
97
+
98
+ assertThat(userPreferences.currency).isEqualTo(currency)
99
+ }
100
+
101
+ @Test
102
+ fun when_setCoinSortToMarketCap_should_updateUserPreferencesCoinSortToMarketCap () =
103
+ testCoroutineScope.runTest {
104
+ val coinSort = CoinSort .MarketCap
105
+
106
+ userPreferencesRepository.updateCoinSort(
107
+ coinSort = coinSort
108
+ )
109
+
110
+ val userPreferences = userPreferencesRepository
111
+ .userPreferencesFlow
112
+ .first()
113
+
114
+ assertThat(userPreferences.coinSort).isEqualTo(coinSort)
115
+ }
116
+
117
+ @Test
118
+ fun when_setCoinSortToPrice_should_updateUserPreferencesCoinSortToPrice () =
119
+ testCoroutineScope.runTest {
120
+ val coinSort = CoinSort .Price
121
+
122
+ userPreferencesRepository.updateCoinSort(
123
+ coinSort = coinSort
124
+ )
125
+
126
+ val userPreferences = userPreferencesRepository
127
+ .userPreferencesFlow
128
+ .first()
129
+
130
+ assertThat(userPreferences.coinSort).isEqualTo(coinSort)
131
+ }
132
+
133
+ @Test
134
+ fun when_setCoinSortToPriceChange_should_updateUserPreferencesCoinSortToPriceChange () =
135
+ testCoroutineScope.runTest {
136
+ val coinSort = CoinSort .PriceChange24h
137
+
138
+ userPreferencesRepository.updateCoinSort(
139
+ coinSort = coinSort
140
+ )
141
+
142
+ val userPreferences = userPreferencesRepository
143
+ .userPreferencesFlow
144
+ .first()
145
+
146
+ assertThat(userPreferences.coinSort).isEqualTo(coinSort)
147
+ }
148
+
149
+ @Test
150
+ fun when_setCoinSortToVolume_should_updateUserPreferencesCoinSortToVolume () =
151
+ testCoroutineScope.runTest {
152
+ val coinSort = CoinSort .Volume24h
153
+
154
+ userPreferencesRepository.updateCoinSort(
155
+ coinSort = coinSort
98
156
)
99
157
100
158
val userPreferences = userPreferencesRepository
101
159
.userPreferencesFlow
102
160
.first()
103
161
104
- assertThat(userPreferences).isEqualTo(expectedUserPreferences )
162
+ assertThat(userPreferences.coinSort ).isEqualTo(coinSort )
105
163
}
106
164
}
0 commit comments