Skip to content

Commit

Permalink
covered all test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam Jha committed Dec 22, 2024
1 parent 9764b40 commit 68ba2bc
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,46 @@ void main() {
});

test('successfully listens to connectivity changes', () async {
final expectedResults = [ConnectivityResult.wifi];
final expectedResults = [
ConnectivityResult.mobile,
ConnectivityResult.wifi,
];

service.connectionStatusController.stream.listen(
expectAsync1(
(List<ConnectivityResult> results) {
expect(results, equals(expectedResults));
},
count: 1,
),
(List<ConnectivityResult> results) {
expect(results, equals(expectedResults));
},
);

// Trigger the event
service.connectionStatusController.add(expectedResults);
});

test('check has connection', () async {
test('check has connection - no connection', () async {
connectivityStatus = [ConnectivityResult.none];
expect(await service.hasConnection(), false);
});

test('check has connection - with connection', () async {
connectivityStatus = [ConnectivityResult.mobile];
expect(await service.hasConnection(), true);
});

// empty list
test('check has connection - empty list', () async {
connectivityStatus = [];
expect(await service.hasConnection(), false);
});

test('check has connection - mixed results', () async {
connectivityStatus = [ConnectivityResult.none, ConnectivityResult.wifi];
expect(await service.hasConnection(), true);
});

test('check has connection - all none', () async {
connectivityStatus = [ConnectivityResult.none, ConnectivityResult.none];
expect(await service.hasConnection(), false);
});

test('isReachable', () async {
final reached = await service.isReachable(
client: mockClient,
Expand Down

0 comments on commit 68ba2bc

Please sign in to comment.