@@ -40,53 +40,91 @@ void main() {
4040 'JsonCacheSafeLocalStorage' ,
4141 () {
4242 test (
43- 'refresh, value, clear, refresh ' ,
43+ '" refresh", " value", "remove" with one piece of data ' ,
4444 () async {
45+ // Insert a single piece of data into the cache
4546 await jsonCacheSafeLocalStorage.refresh (profKey, profData);
4647
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);
5055
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);
5359 },
5460 );
5561
5662 test (
57- 'contains ' ,
63+ '"refresh", "value", "remove" with multiple data ' ,
5864 () async {
59- // Adding content on cache. Each 'refresh' method overrides the last one.
65+ // Insert multiple data into the cache
6066 await jsonCacheSafeLocalStorage.refresh (profKey, profData);
6167 await jsonCacheSafeLocalStorage.refresh (prefKey, prefData);
6268
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);
6677
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.
6795 await jsonCacheSafeLocalStorage.refresh (profKey, profData);
68- // Returning true if the last content exists on cache based on 'profKey'.
96+
97+ // Check
6998 expect (await jsonCacheSafeLocalStorage.contains (profKey), true );
7099 expect (await jsonCacheSafeLocalStorage.contains (prefKey), false );
71100
72101 // Test for keys that doesn't exist
73102 expect (await jsonCacheSafeLocalStorage.contains ('generickey' ), false );
74103 expect (await jsonCacheSafeLocalStorage.contains ('PROFKEY' ), false );
75104 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 );
76112 },
77113 );
78114
79115 test (
80- 'remove ' ,
116+ 'clear ' ,
81117 () async {
118+ // Insert multiple data into the cache.
82119 await jsonCacheSafeLocalStorage.refresh (profKey, profData);
120+ await jsonCacheSafeLocalStorage.refresh (prefKey, prefData);
83121
84- final recoveredData = await jsonCacheSafeLocalStorage. value (profKey);
85- expect (recoveredData, profData );
122+ // Clear it.
123+ await jsonCacheSafeLocalStorage. clear ( );
86124
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);
90128 },
91129 );
92130 },
0 commit comments