Skip to content

Commit

Permalink
Extend test
Browse files Browse the repository at this point in the history
  • Loading branch information
rekire committed Mar 16, 2024
1 parent 0e4f2cd commit 28a2bde
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions autologin_linux/test/autologin_linux_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:autologin_linux/autologin_linux.dart';
import 'package:autologin_platform_interface/autologin_platform_interface.dart';
import 'package:flutter/services.dart';
Expand All @@ -7,9 +9,10 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('AutologinLinux', () {
const kPlatformName = 'Linux';
late AutologinLinux autologin;
late List<MethodCall> log;
const expectedCompatibilities = Compatibilities(isPlatformSupported: true);
const expectedCredentials = Credential(username: 'foo', password: 'bar');

setUp(() async {
autologin = AutologinLinux();
Expand All @@ -19,8 +22,12 @@ void main() {
.setMockMethodCallHandler(autologin.methodChannel, (methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
case 'getPlatformName':
return kPlatformName;
case 'performCompatibilityChecks':
return jsonEncode(expectedCompatibilities.toJson());
case 'requestCredentials':
return jsonEncode(expectedCredentials.toJson());
case 'saveCredentials':
return 'true';
default:
return null;
}
Expand All @@ -32,13 +39,49 @@ void main() {
expect(AutologinPlatform.instance, isA<AutologinLinux>());
});

test('getPlatformName returns correct name', () async {
final name = await autologin.getPlatformName();
test('performCompatibilityChecks returns expected value', () async {
final report = await autologin.performCompatibilityChecks();
expect(
log,
<Matcher>[isMethodCall('performCompatibilityChecks', arguments: null)],
);
expect(report, equals(expectedCompatibilities));
});

test('requestCredentials returns expected value', () async {
final credentials = await autologin.requestCredentials();
expect(
log,
<Matcher>[isMethodCall('requestCredentials', arguments: null)],
);
expect(credentials, equals(expectedCredentials));
});

test('saveCredentials returns expected value', () async {
final report = await autologin.saveCredentials(expectedCredentials);
expect(
log,
<Matcher>[isMethodCall('saveCredentials', arguments: expectedCredentials.toJson())],
);
expect(report, equals(true));
});

test('requestLoginToken returns nothing', () async {
final token = await autologin.requestLoginToken();
expect(
log,
<Matcher>[isMethodCall('requestLoginToken', arguments: null)],
);
expect(token, equals(null));
});

test('saveLoginToken returns expected value', () async {
final report = await autologin.saveLoginToken(expectedToken);
expect(
log,
<Matcher>[isMethodCall('getPlatformName', arguments: null)],
<Matcher>[isMethodCall('saveLoginToken', arguments: expectedToken)],
);
expect(name, equals(kPlatformName));
expect(report, equals(false));
});
});
}

0 comments on commit 28a2bde

Please sign in to comment.