@@ -40,53 +40,91 @@ void main() {
40
40
'JsonCacheSafeLocalStorage' ,
41
41
() {
42
42
test (
43
- 'refresh, value, clear, refresh ' ,
43
+ '" refresh", " value", "remove" with one piece of data ' ,
44
44
() async {
45
+ // Insert a single piece of data into the cache
45
46
await jsonCacheSafeLocalStorage.refresh (profKey, profData);
46
47
47
- final data = await jsonCacheSafeLocalStorage.value (profKey);
48
- expect (data, profData);
49
- await jsonCacheSafeLocalStorage.clear ();
48
+ // Check if the data has been inserted into the cache.
49
+ final profileRetrieved =
50
+ await jsonCacheSafeLocalStorage.value (profKey);
51
+ expect (profileRetrieved, equals (profData));
52
+
53
+ // Remove the single piece of data stored.
54
+ await jsonCacheSafeLocalStorage.remove (profKey);
50
55
51
- final cleanCache = await jsonCacheSafeLocalStorage.value (profKey);
52
- expect (cleanCache, isNull);
56
+ // No data should remain in the cache.
57
+ final cachedValue = await jsonCacheSafeLocalStorage.value (profKey);
58
+ expect (cachedValue, isNull);
53
59
},
54
60
);
55
61
56
62
test (
57
- 'contains ' ,
63
+ '"refresh", "value", "remove" with multiple data ' ,
58
64
() async {
59
- // Adding content on cache. Each 'refresh' method overrides the last one.
65
+ // Insert multiple data into the cache
60
66
await jsonCacheSafeLocalStorage.refresh (profKey, profData);
61
67
await jsonCacheSafeLocalStorage.refresh (prefKey, prefData);
62
68
63
- // Returning true if the last content exists on cache based on 'prefKey'.
64
- expect (await jsonCacheSafeLocalStorage.contains (prefKey), true );
65
- expect (await jsonCacheSafeLocalStorage.contains (profKey), false );
69
+ // Check if multiple data has been inserted into the cache.
70
+ final profileRetrieved =
71
+ await jsonCacheSafeLocalStorage.value (profKey);
72
+ expect (profileRetrieved, equals (profData));
73
+
74
+ final preferencesRetrived =
75
+ await jsonCacheSafeLocalStorage.value (prefKey);
76
+ expect (preferencesRetrived, prefData);
66
77
78
+ // Remove data from the cache.
79
+ await jsonCacheSafeLocalStorage.remove (profKey);
80
+ await jsonCacheSafeLocalStorage.remove (prefKey);
81
+
82
+ final removedProfValue =
83
+ await jsonCacheSafeLocalStorage.value (profKey);
84
+ expect (removedProfValue, isNull);
85
+ final removedPrefValue =
86
+ await jsonCacheSafeLocalStorage.value (prefKey);
87
+ expect (removedPrefValue, isNull);
88
+ },
89
+ );
90
+
91
+ test (
92
+ 'contains' ,
93
+ () async {
94
+ // Insert a single piece of data into the cache.
67
95
await jsonCacheSafeLocalStorage.refresh (profKey, profData);
68
- // Returning true if the last content exists on cache based on 'profKey'.
96
+
97
+ // Check
69
98
expect (await jsonCacheSafeLocalStorage.contains (profKey), true );
70
99
expect (await jsonCacheSafeLocalStorage.contains (prefKey), false );
71
100
72
101
// Test for keys that doesn't exist
73
102
expect (await jsonCacheSafeLocalStorage.contains ('generickey' ), false );
74
103
expect (await jsonCacheSafeLocalStorage.contains ('PROFKEY' ), false );
75
104
expect (await jsonCacheSafeLocalStorage.contains ('PREFKEY' ), false );
105
+
106
+ // Insert a new piece of data into the cache to test more than one key stored.
107
+ await jsonCacheSafeLocalStorage.refresh (prefKey, prefData);
108
+
109
+ // Check for multiple data.
110
+ expect (await jsonCacheSafeLocalStorage.contains (profKey), true );
111
+ expect (await jsonCacheSafeLocalStorage.contains (prefKey), true );
76
112
},
77
113
);
78
114
79
115
test (
80
- 'remove ' ,
116
+ 'clear ' ,
81
117
() async {
118
+ // Insert multiple data into the cache.
82
119
await jsonCacheSafeLocalStorage.refresh (profKey, profData);
120
+ await jsonCacheSafeLocalStorage.refresh (prefKey, prefData);
83
121
84
- final recoveredData = await jsonCacheSafeLocalStorage. value (profKey);
85
- expect (recoveredData, profData );
122
+ // Clear it.
123
+ await jsonCacheSafeLocalStorage. clear ( );
86
124
87
- await jsonCacheSafeLocalStorage. remove (profKey);
88
- final cleanCache = await jsonCacheSafeLocalStorage.value (profKey);
89
- expect (cleanCache , isNull);
125
+ // No data should remain in the cache.
126
+ final cachedValue = await jsonCacheSafeLocalStorage.value (profKey);
127
+ expect (cachedValue , isNull);
90
128
},
91
129
);
92
130
},
0 commit comments