Skip to content

Commit

Permalink
Merge pull request #31 from yihong1120/sweep/add-docstrings
Browse files Browse the repository at this point in the history
Add Docstrings to test/social_service_test.dart
  • Loading branch information
yihong1120 authored Dec 30, 2023
2 parents d59a969 + 09c5463 commit 1db2eb8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/social_service_test.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/// Tests for the 'launchUrl' function in the 'SocialService' class.
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:traffic_report_front_flutter/services/social_service.dart';
import 'package:url_launcher/url_launcher.dart';

class MockUrlLauncher extends Mock implements UrlLauncher {}

/// The 'main' function is the entry point for the tests and contains a group of tests for the 'launchUrl' function.
void main() {
group('launchUrl', () {
final mockUrlLauncher = MockUrlLauncher();
final socialService = SocialService();

/// Tests if the 'launchUrl' function can successfully launch a URL.
test('launches URL successfully', () async {
when(mockUrlLauncher.canLaunch(any)).thenAnswer((_) async => true);
when(mockUrlLauncher.launch(any)).thenAnswer((_) async => true);

expect(await socialService.launchUrl('http://valid.url'), completes);
});

/// Tests if the 'launchUrl' function throws an exception when the URL cannot be launched.
test('throws an exception when URL cannot be launched', () async {
when(mockUrlLauncher.canLaunch(any)).thenAnswer((_) async => false);

Expand Down

0 comments on commit 1db2eb8

Please sign in to comment.