Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 23, 2021
1 parent 2e604f2 commit 493b886
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 30 deletions.
17 changes: 17 additions & 0 deletions test/random_service_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:odin/services/random_service.dart';

void main() {
group("Random -", () {
test("Result should be String", () {
final RandomService _randomService = RandomService();
final String randomText = _randomService.getRandomString(10);
expect(randomText, isA<String>());
});
test("Result should be 10 char long", () {
final RandomService _randomService = RandomService();
final String randomText = _randomService.getRandomString(10);
expect(randomText, hasLength(10));
});
});
}
13 changes: 13 additions & 0 deletions test/shortner_service_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:odin/services/shortener_service.dart';

void main() {
group("Shortener -", () {
test("Url should contain shrtco.de", () async {
final ShortenerService _shortnerService = ShortenerService();
const String url = "https://www.google.com";
final String? shortUrl = await _shortnerService.getShortUrl(url: url);
expect(shortUrl, stringContainsInOrder(["https://", "shrtco.de"]));
});
});
}
30 changes: 0 additions & 30 deletions test/widget_test.dart

This file was deleted.

41 changes: 41 additions & 0 deletions test/zip_service_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:odin/services/locator.dart';
import 'package:odin/services/zip_service.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

void main() {
setUpAll(() => setupLocator());
group("Zip -", () {
test("Result should be a File", () async {
final ZipService _zipService = ZipService();
final directory = await getTemporaryDirectory();
final file = File('${directory.path}\\hello.txt');
file.writeAsStringSync('Hello World!');
final File zippedFile = await _zipService.zipFile(fileToZips: [file]);
expect(zippedFile, isA<File>());
});
test("Result should be of zip extension", () async {
final ZipService _zipService = ZipService();
final directory = await getTemporaryDirectory();
final file = File('${directory.path}\\hello2.txt');
file.writeAsStringSync('Hello World!');
final File zippedFile = await _zipService.zipFile(fileToZips: [file]);
expect(basename(zippedFile.path), stringContainsInOrder([".zip"]));
});
test("Result should contain first file name", () async {
final ZipService _zipService = ZipService();
final directory = await getTemporaryDirectory();
final file = File('${directory.path}\\hello3.txt');
file.writeAsStringSync('Hello World!');
final file2 = File('${directory.path}\\hello4.txt');
file2.writeAsStringSync('Hello World!');
final File zippedFile =
await _zipService.zipFile(fileToZips: [file, file2]);
expect(basename(zippedFile.path),
stringContainsInOrder(["hello3", "txt", ".zip"]));
});
});
}

0 comments on commit 493b886

Please sign in to comment.