-
Notifications
You must be signed in to change notification settings - Fork 0
test: setup unit test for flutter_skin main class and CI check on PRs #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| class FskinConstants { | ||
| static const String baseUrl = 'fskinbackend-production.up.railway.app'; | ||
| static const String keyRegex = r'^fsk_[a-f0-9]{64}$'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_skin/flutter_skin.dart'; | ||
| import 'package:flutter_skin/models/project_config.dart'; | ||
| import 'package:flutter_skin/remote/fskin_remote_config.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mockito/mockito.dart'; | ||
|
|
||
| import '../mocks/skin_model_mocks.dart'; | ||
|
|
||
| class MockFskinRemoteConfig extends Mock implements FskinRemoteConfig {} | ||
|
|
||
| class MockProjectConfig extends Mock implements ProjectConfig {} | ||
|
|
||
| void main() async { | ||
| group('FlutterSkin Initialization Tests', () { | ||
| final apiKey = | ||
| 'fsk_1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'; | ||
|
|
||
| setUp(() async { | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
| await FlutterSkin.init(apiKey: apiKey); | ||
| }); | ||
|
|
||
| test('fetches and applies skin on successful response', () async { | ||
| // Testing with fake api key will result in null theme. | ||
| await FlutterSkin.init(apiKey: apiKey); | ||
|
|
||
| final skin = FlutterSkin.theme; | ||
| final instance = FlutterSkin.singleton; | ||
|
|
||
| expect(instance.apiKey, apiKey); | ||
| expect(skin, null); | ||
| }); | ||
|
|
||
| test('applies skin from remote config', () async { | ||
| final instance = FlutterSkin.singleton; | ||
|
|
||
| instance.setRemoteConfig(MockFskinRemoteConfig()); | ||
| when( | ||
| FlutterSkin.remoteConfig.projectConfig, | ||
| ).thenReturn(ProjectConfig(skin: skinModelMock)); | ||
|
|
||
| final skin = FlutterSkin.theme; | ||
| expect(instance.apiKey, apiKey); | ||
| expect(skin, isA<ThemeData>()); | ||
| expect(skin?.colorScheme.primary, skinModelMock.colors?.primary); | ||
| }); | ||
|
|
||
| test('project config returns a nullable skin', () async { | ||
| final instance = FlutterSkin.singleton; | ||
|
|
||
| instance.setRemoteConfig(MockFskinRemoteConfig()); | ||
| when( | ||
| FlutterSkin.remoteConfig.projectConfig, | ||
| ).thenReturn(MockProjectConfig()); | ||
|
|
||
| var skin = FlutterSkin.theme; | ||
| expect(instance.apiKey, apiKey); | ||
| expect(skin, isA<Null>()); | ||
|
|
||
| skin = FlutterSkin.toThemeData( | ||
| fallbackTheme: ThemeData(primaryColor: Colors.red), | ||
| ); | ||
| expect(skin, isA<ThemeData>()); | ||
| expect(skin?.brightness, Brightness.light); | ||
| }); | ||
|
koukibadr marked this conversation as resolved.
|
||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import 'package:flutter_skin/flutter_skin.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| group('Initialization test across different scenarios', () { | ||
| test( | ||
| 'should throw an exception if init is called with an empty apiKey', | ||
| () async { | ||
| expect( | ||
| () => FlutterSkin.init(apiKey: ''), | ||
| throwsA(isA<ArgumentError>()), | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| test( | ||
| 'should throw an exception if init is called with an invalid apiKey', | ||
| () async { | ||
| expect( | ||
| () => FlutterSkin.init(apiKey: 'my_api_key'), | ||
| throwsA(isA<ArgumentError>()), | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| test('should throw an exception if singleton is accessed before init', () { | ||
| expect(() => FlutterSkin.singleton, throwsA(isA<Exception>())); | ||
| }); | ||
|
|
||
| test('should throw an exception if theme is accessed before init', () { | ||
| expect(() => FlutterSkin.theme, throwsA(isA<Exception>())); | ||
| }); | ||
| }); | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // ignore_for_file: deprecated_member_use | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_skin/models/skin_model.dart'; | ||
|
|
||
| var skinModelMock = SkinModel( | ||
| colors: const ColorScheme.light( | ||
| primary: Color(0xFF6200EE), | ||
| secondary: Color(0xFF03DAC6), | ||
| background: Color(0xFFFFFFFF), | ||
| surface: Color(0xFFFFFFFF), | ||
| onPrimary: Color(0xFFFFFFFF), | ||
| onSecondary: Color(0xFF000000), | ||
| onBackground: Color(0xFF000000), | ||
| onSurface: Color(0xFF000000), | ||
| ), | ||
| id: 'mock_id', | ||
| projectId: 'mock_project_id', | ||
| isActive: true, | ||
| version: 1, | ||
| createdAt: DateTime.now(), | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.