Skip to content

Feature/add more tests#145

Open
daniJimen wants to merge 16 commits intomainfrom
feature/add_more_tests
Open

Feature/add more tests#145
daniJimen wants to merge 16 commits intomainfrom
feature/add_more_tests

Conversation

@daniJimen
Copy link
Collaborator

@daniJimen daniJimen commented Jan 12, 2026

  • update coverage of testing into 91%
  • remove unnecesary code from extension GithubJsonModel.fromJson and classes like sesssiontypes and app_router

This commit adds several unit tests to `config_loader_test.dart` to cover edge cases and error scenarios when loading organization configurations, including handling null repository files and remote loading failures.

### Key Changes:

- **`test/core/config/config_loader_test.dart`**:
    - Updated `tearDown` to properly clear the mock message handler for `flutter/assets` and reset `GetIt`.
    - Added a test case to verify that an error is set (`setError(true)`) when the GitHub repository content returns a null file.
    - Added a test case to verify successful local fallback when `githubItem` is null or missing specific keys.
    - Added a test case to verify that an error is set when remote configuration fails to load and local configuration is empty.
    - Cleaned up redundant comments and added `rootBundle.clear()` to ensure test isolation.
This commit adds unit tests to `secure_info_test.dart` to verify that `SecureInfo` correctly handles and throws exceptions when storage operations for GitHub tokens fail.

### Key Changes:

- **`test/core/config/secure_info_test.dart`**:
    - Added a test case to verify that `saveGithubKey` throws an `Exception` when the underlying storage write operation fails.
    - Added a test case to verify that `removeGithubKey` throws an `Exception` when the underlying storage delete operation fails.
    - Mocked the `MethodChannel` behavior to simulate failures during storage access.
This commit updates a unit test in `config_loader_test.dart` to explicitly call `ConfigLoader.loadOrganization()`, ensuring the error state verification is correctly triggered during the test execution.

### Key Changes:

- **`test/core/config/config_loader_test.dart`**:
    - Added a call to `ConfigLoader.loadOrganization()` within a test case to properly exercise the logic that triggers `mockCheckOrg.setError(true)`.
… routing

This commit introduces a comprehensive test suite for the `Result` utility class to ensure type safety and correct pattern matching. It also simplifies the routing logic for the agenda form by removing a redundant null check.

### Key Changes:

- **`test/core/utils/result_test.dart`**:
    - Added unit tests for `Result.ok` and `Result.error` to verify value encapsulation and `toString` output.
    - Added tests for pattern matching using Dart 3 switch expressions.
    - Added type safety tests to ensure generic integrity between `Result<int>` and `Result<String>`.
    - Defined a `TestException` mock class to facilitate error state testing.

- **`lib/core/routing/app_router.dart`**:
    - Removed a redundant null check in the `agendaFormPath` builder, as `state.extra` is now expected to be cast directly to `AgendaFormData`.
This commit refactors the `GithubJsonModel.fromJson` factory to use more direct list casting and adds a template JSON file for GitHub items.

### Key Changes:

- **`lib/core/models/github_json_model.dart`**:
    - Simplified the parsing logic for `events`, `tracks`, `sessions`, `agendadays`, `sponsors`, and `speakers`.
    - Removed redundant null-aware operators (`?` and `?? []`) when casting lists, assuming the existence check `json['key'] != null` is sufficient for a direct `as List` cast.

- **`events/githubItem/githubItem.json`**:
    - Added a new JSON file providing a base structure with empty arrays for all major entities.
…es.updateData`

This commit enhances the test suite for `commons_api_services_test.dart` by adding several test cases to verify error handling during the GitHub data update process. It also includes minor cleanup in the `SessionType` model and updates generated mocks.

### Key Changes:

- **`test/data/remote_data/common/commons_api_services_test.dart`**:
    - Added tests to verify `GithubException` is thrown when the file `sha` is null during an update.
    - Added tests to simulate `GitHubError` (e.g., "Not Found") from the GitHub SDK, covering scenarios where file creation either succeeds or fails.
    - Added a test case to ensure an exception is thrown when the GitHub token is missing or null.
    - Added a test case to handle scenarios where the repository content response is null.
    - Refactored several existing tests to improve readability and ensure consistent mock setups.

- **`lib/core/models/session_type.dart`**:
    - Removed the unused `allLabels` static method.

- **`test/mocks.dart`**:
    - Added `ContentCreation` to the list of mocked classes.

- **`test/mocks.mocks.dart`**:
    - Regenerated mocks to include `MockContentCreation`.
# Conflicts:
#	events/githubItem/githubItem.json
@daniJimen daniJimen requested a review from vicajilau January 12, 2026 10:53
@daniJimen daniJimen self-assigned this Jan 12, 2026
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 98.46154% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.47%. Comparing base (b7cc934) to head (035bdfb).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...eens/event_collection/event_collection_screen.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
+ Coverage   89.36%   90.47%   +1.10%     
==========================================
  Files          78       78              
  Lines        6431     6464      +33     
==========================================
+ Hits         5747     5848     +101     
+ Misses        684      616      -68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…vices`

This commit introduces several unit tests to `commons_api_services_test.dart` to verify error handling and specific edge cases for `updateData`, `updateDataList`, and `updateSingleData`.

### Key Changes:

- **`test/data/remote_data/common/commons_api_services_test.dart`**:
    - Added a test for `updateData` to verify it throws a `NetworkException` when the HTTP status code is 400.
    - Added multiple test cases for `updateDataList` to handle scenarios including:
        - Throwing a `GithubException` when the file SHA is null.
        - Throwing a `GithubException` when `getContents` fails and the file cannot be created.
        - Successful execution when `getContents` fails but `createFile` succeeds.
        - Throwing a `GithubException` when the created file content is null.
        - Throwing a `NetworkException` when the update results in a 400 status code.
    - Updated the error handling test for `updateSingleData` to use an asynchronous expectation for better reliability.
…piServices`

This commit adds several unit tests to `commons_api_services_test.dart` to verify error handling for `updateDataList` and `removeDataList` methods, specifically targeting various GitHub API failure scenarios and HTTP error status codes.

### Key Changes:

- **`test/data/remote_data/common/commons_api_services_test.dart`**:
    - Added a test case for `updateDataList` to verify it throws a `NetworkException` when receiving a 409 Conflict status code.
    - Added comprehensive test cases for `removeDataList` covering:
        - Scenarios where the repository file SHA is null.
        - GitHub API "Not Found" errors during content retrieval, including cases where file creation subsequently fails or succeeds.
        - Handling of null content in API responses.
        - HTTP error responses (400 and 409 status codes) during the data removal process.
    - Refactored existing tests for consistent indentation and improved readability.
    - Fixed a typo in a test description from `updateData` to `updateDataList`.
…piServices`

This commit adds several unit tests to `commons_api_services_test.dart` to verify error handling and edge cases for the `updateAllData` method, ensuring robust behavior when interacting with the GitHub API.

### Key Changes:

- **`test/data/remote_data/common/commons_api_services_test.dart`**:
    - Added tests to verify that `GithubException` is thrown when the file `sha` is null during content retrieval.
    - Added a test case for handling `GitHubError` (e.g., "Not Found") from the repository service, covering both successful and failed attempts to create a missing file.
    - Added a test case to ensure a `GithubException` is thrown if the file creation response contains null content.
    - Added tests for HTTP error responses from the client, verifying that a `NetworkException` is thrown for status codes `400` and `409`.
    - Integrated `MockSecureInfo` and dependency injection overrides to simulate various GitHub configuration states during tests.
This commit introduces unit tests to verify the functionality of the room creation dialog and adds necessary keys to the UI components to facilitate testing.

### Key Changes:

- **`lib/presentation/ui/screens/agenda/form/agenda_form_screen.dart`**:
    - Added `Key` identifiers to the room name `TextFormField`, "Cancel" button, and "Save" button within the room dialog to enable widget testing.

- **`test/presentation/agenda/form/agenda_form_screen_test.dart`**:
    - Added a new test group 'room dialog' with three test cases:
        - Verifies that the room dialog opens when the "add room" button is pressed.
        - Verifies that the dialog closes correctly when the "cancel" button is tapped.
        - Verifies that the dialog saves the input and closes when the "save" button is tapped.
    - Cleaned up minor formatting and trailing whitespace in existing tests.
…een`

This commit removes the redundant `isTimeSelected` utility method from `AgendaFormScreen` as it is no longer used within the codebase.

### Key Changes:

- **`lib/presentation/ui/screens/agenda/form/agenda_form_screen.dart`**:
    - Deleted the `isTimeSelected` helper method.
…ve `EventCollectionScreen` test coverage

This commit enhances the test suite for event collection and login flows by adding specific widget keys for testing, introducing new test cases for admin interactions, and cleaning up redundant tests in `event_collection_screen_test.dart`.

### Key Changes:

- **`lib/presentation/ui/screens/event_collection/event_collection_screen.dart`**:
    - Added `title_key_event_collection` key to the `AppBar` title `GestureDetector` to facilitate targeted tap testing.

- **`lib/presentation/ui/screens/login/admin_login_screen.dart`**:
    - Added unique keys (`title_key_event_collection`, `token_key_github`, `login_button`) to UI components for more robust widget testing.
    - Refactored GitHub client initialization into a helper method `getGithubUser()`.

- **`test/presentation/event_collection/event_collection_screen_test.dart`**:
    - Refactored existing tests for better readability and consistent formatting.
    - Added a new test case to verify that tapping the screen title 5 times correctly triggers the `AdminLoginScreen` dialog when an organization error exists.
    - Removed several admin-related test cases (visibility toggle, edit/delete event, organization FAB) that were redundant or out of scope for this suite.

- **`test/mocks.dart` & `test/mocks.mocks.dart`**:
    - Generated new mocks for `CurrentUser` and `UsersService` to support authentication and user-related test scenarios.
This commit introduces several new localization keys to support option management (adding and deleting) and confirmation dialogs across all supported languages.

### Key Changes:

- **Localization Files (`.arb`, `.dart`)**:
    - Added `confirm`: Translation for generic confirmation actions.
    - Added `deleteOptionMessage`: Confirmation prompt for deleting an option.
    - Added `delete`: Translation for delete actions.
    - Added `addOption`: Translation for adding a new option.
    - Added `optionHint`: Placeholder text for option input fields.
    - Updated English, Basque, Catalan, Spanish, French, Galician, Italian, and Portuguese localizations.
    - Fixed a typo in `app_eu.arb` for `tokenHintLabel`.

- **Tests**:
    - Updated unit tests for various languages (English, French, Portuguese, Spanish, Catalan, Galician, Italian, Basque) to verify the presence and correctness of the new localized strings.
This commit updates the `tokenHintLabel` string in the Basque localization and its corresponding test to reflect a change in the translation text.

### Key Changes:

- **`lib/l10n/app_localizations_eu.dart`**:
    - Updated `tokenHintLabel` from "Sartu zure bezeroaren sekretua jarraitzeko" to "Sartu votre bezeroaren sekretua jarraitzeko".

- **`test/l10n/app_localizations_eu_test.dart`**:
    - Updated the test expectation for `tokenHintLabel` to match the new string value.
This commit replaces hardcoded Spanish and English strings with localized alternatives in the `AddRoom` widget to support internationalization.

### Key Changes:

- **`lib/presentation/ui/widgets/add_room.dart`**:
    - Imported `AppLocalizations`.
    - Updated the `_confirmRemoveOption` dialog to use localized strings for the title (`confirm`), content (`deleteOptionMessage`), and action buttons (`cancel`, `delete`).
    - Updated the "Add Option" button label in the `build` method to use the localized `addOption` string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant