Skip to content

Commit ae9d227

Browse files
author
Sterling Long
committed
Added test for update sort
1 parent 23965cb commit ae9d227

4 files changed

Lines changed: 67 additions & 9 deletions

File tree

lib/services/explorer/explorer_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ExplorerService implements IExplorerService {
154154
);
155155
}
156156

157-
await updateSort();
157+
updateSort();
158158

159159
initialized.value = true;
160160
}
@@ -179,7 +179,7 @@ class ExplorerService implements IExplorerService {
179179
}
180180

181181
@override
182-
Future<void> updateSort() async {
182+
void updateSort() async {
183183
final List<GridListItemModel<WalletData>> newList = [];
184184

185185
final String? recentWallet =

lib/services/walletconnect_modal/walletconnect_modal_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class WalletConnectModalService extends ChangeNotifier
373373
walletData.listing.id,
374374
);
375375
// Update explorer service with new recent
376-
await explorerService.instance!.updateSort();
376+
explorerService.instance!.updateSort();
377377

378378
try {
379379
await rebuildConnectionUri();

lib/widgets/grid_list/grid_list_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ abstract class GridListProvider<T> {
99
String? query,
1010
});
1111

12-
Future<void> updateSort();
12+
void updateSort();
1313
}

test/explorer/explorer_test.dart

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ void main() {
9999
);
100100
verify(
101101
mockStorageService.getString(StringConstants.recentWallet),
102-
).called(1);
102+
).called(2); // Once in init, once in updateSort
103103
});
104104

105105
group('After init', () {
106106
setUp(() async {
107107
await explorerService.init();
108108
});
109109

110-
test('Test Filter Functionality', () async {
110+
test('filterList', () async {
111111
explorerService.filterList(query: 'Test2');
112112

113113
// add assertions based on your expected outcomes
@@ -123,7 +123,65 @@ void main() {
123123
explorerService.filterList();
124124
});
125125

126-
test('Test Redirect Fetching', () {
126+
test('updateSort', () async {
127+
when(
128+
mockStorageService.getString(StringConstants.recentWallet),
129+
).thenReturn('1');
130+
explorerService.updateSort();
131+
132+
expect(
133+
explorerService.itemList.value[0].title,
134+
'Test1',
135+
);
136+
expect(
137+
explorerService.itemList.value[0].description,
138+
'Recent',
139+
);
140+
expect(
141+
explorerService.itemList.value[0].data.recent,
142+
true,
143+
);
144+
expect(explorerService.previousRecentWallet, '1');
145+
146+
when(
147+
mockStorageService.getString(StringConstants.recentWallet),
148+
).thenReturn('2');
149+
explorerService.updateSort();
150+
151+
expect(
152+
explorerService.itemList.value[0].title,
153+
'Test2',
154+
);
155+
expect(
156+
explorerService.itemList.value[0].description,
157+
'Recent',
158+
);
159+
expect(
160+
explorerService.itemList.value[0].data.recent,
161+
true,
162+
);
163+
expect(
164+
explorerService.itemList.value[1].title,
165+
'Test1',
166+
);
167+
expect(
168+
explorerService.itemList.value[1].description,
169+
'Installed',
170+
);
171+
expect(
172+
explorerService.itemList.value[1].data.recent,
173+
false,
174+
);
175+
expect(explorerService.previousRecentWallet, '2');
176+
177+
when(
178+
mockStorageService.getString(StringConstants.recentWallet),
179+
).thenReturn(null);
180+
181+
explorerService.updateSort();
182+
});
183+
184+
test('getRedirect', () {
127185
Redirect? redirect = explorerService.getRedirect(name: 'blank');
128186
expect(redirect, null);
129187

@@ -137,7 +195,7 @@ void main() {
137195
});
138196
});
139197

140-
test('Test Image URL Generation', () {
198+
test('getWalletImageUrl and getAssetImageUrl', () {
141199
String imageId = 'test_id';
142200
expect(
143201
explorerService.getWalletImageUrl(imageId: imageId),
@@ -153,7 +211,7 @@ void main() {
153211
);
154212
});
155213

156-
test('Test Fetching of Wallet Listings', () async {
214+
test('fetchListings', () async {
157215
final List<Listing> listings = await explorerService.fetchListings(
158216
endpoint: '/w3m/v1/getDesktopListings',
159217
referer: 'test_referer',

0 commit comments

Comments
 (0)