|
| 1 | +import 'package:cli_completion/cli_completion.dart'; |
| 2 | +import 'package:cli_completion/installer.dart'; |
| 3 | +import 'package:mason_logger/mason_logger.dart'; |
| 4 | +import 'package:mocktail/mocktail.dart'; |
| 5 | +import 'package:test/test.dart'; |
| 6 | + |
| 7 | +class _MockLogger extends Mock implements Logger {} |
| 8 | + |
| 9 | +class _MockCompletionInstallation extends Mock |
| 10 | + implements CompletionInstallation {} |
| 11 | + |
| 12 | +class _TestCompletionCommandRunner extends CompletionCommandRunner<int> { |
| 13 | + _TestCompletionCommandRunner() : super('test', 'Test command runner'); |
| 14 | + |
| 15 | + @override |
| 16 | + // ignore: overridden_fields |
| 17 | + final Logger completionInstallationLogger = _MockLogger(); |
| 18 | + |
| 19 | + @override |
| 20 | + final CompletionInstallation completionInstallation = |
| 21 | + _MockCompletionInstallation(); |
| 22 | +} |
| 23 | + |
| 24 | +void main() { |
| 25 | + group('$UnistallCompletionFilesCommand', () { |
| 26 | + late _TestCompletionCommandRunner commandRunner; |
| 27 | + |
| 28 | + setUp(() { |
| 29 | + commandRunner = _TestCompletionCommandRunner(); |
| 30 | + }); |
| 31 | + |
| 32 | + test('can be instantiated', () { |
| 33 | + expect(UnistallCompletionFilesCommand<int>(), isNotNull); |
| 34 | + }); |
| 35 | + |
| 36 | + test('is hidden', () { |
| 37 | + expect(UnistallCompletionFilesCommand<int>().hidden, isTrue); |
| 38 | + }); |
| 39 | + |
| 40 | + test('description', () { |
| 41 | + expect( |
| 42 | + UnistallCompletionFilesCommand<int>().description, |
| 43 | + 'Manually uninstalls completion files for the current shell.', |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + group('uninstalls completion files', () { |
| 48 | + test('when normal', () async { |
| 49 | + await commandRunner.run(['uninstall-completion-files']); |
| 50 | + |
| 51 | + verify( |
| 52 | + () => commandRunner.completionInstallationLogger.level = Level.info, |
| 53 | + ).called(1); |
| 54 | + verify( |
| 55 | + () => commandRunner.completionInstallation |
| 56 | + .uninstall(commandRunner.executableName), |
| 57 | + ).called(1); |
| 58 | + }); |
| 59 | + |
| 60 | + test('when verbose', () async { |
| 61 | + await commandRunner.run(['uninstall-completion-files', '--verbose']); |
| 62 | + |
| 63 | + verify( |
| 64 | + () { |
| 65 | + return commandRunner.completionInstallationLogger.level = |
| 66 | + Level.verbose; |
| 67 | + }, |
| 68 | + ).called(1); |
| 69 | + verify( |
| 70 | + () => commandRunner.completionInstallation |
| 71 | + .uninstall(commandRunner.executableName), |
| 72 | + ).called(1); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }); |
| 76 | +} |
0 commit comments