Skip to content

Moved subtitle selector into it's own file and unit test#324

Open
TheyCallMeSpy wants to merge 3 commits into
Moonfin-Client:mainfrom
TheyCallMeSpy:feature/subtitle-refactor
Open

Moved subtitle selector into it's own file and unit test#324
TheyCallMeSpy wants to merge 3 commits into
Moonfin-Client:mainfrom
TheyCallMeSpy:feature/subtitle-refactor

Conversation

@TheyCallMeSpy

Copy link
Copy Markdown
Contributor

Pull Request

Summary

Extracts subtitle track selection logic from item_detail_screen.dart into a standalone subtitle_track_logic.dart utility, making it pure and unit-testable. Adds fixture-based unit tests and a fixture loader helper.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • UI/UX update
  • Documentation update
  • Build/CI change
  • Other (describe):

Changes Made

List the key changes included in this PR.

  • Extracted isExternalSubtitleStream, isSdhSubtitleStream, computeEffectiveSubtitleIndex, sortedSubtitleStreams, computeSubtitleDialogSelectedIndex, mapSubtitleResultToStreamIndex into lib/util/subtitle_track_logic.dart
  • _effectiveSubtitleStreamIndex in item_detail_screen.dart is now a thin wrapper delegating to the pure function
  • Added test/util/subtitle_track_logic_test.dart with fixture-based unit tests
  • Added test/util/fixture_loader.dart helper
  • Added test/fixtures/subtitle_streams.json with real Jellyfin stream data

Platform

  • Android
  • iOS
  • macOS
  • Windows
  • Linux
  • All / Shared code

Testing

Describe how this change was tested.

  • Tested on emulator / simulator
  • Tested on physical device
  • Manual testing completed
  • Not tested (explain why):

Test Steps

  1. Nothing, just check of subtitle logic is same as before

Checklist

  • Code builds successfully
  • Code follows project style and conventions
  • No unnecessary commented-out code
  • No new warnings introduced

@RadicalMuffinMan

Copy link
Copy Markdown
Contributor

one small cleanup request: mapSubtitleResultToStreamIndex() should guard the lower bound too. Right now a negative result other than 0 would satisfy result - 1 < displayStreams.length and then index the list with a negative offset. Something like:

final streamPosition = result - 1;
if (streamPosition >= 0 && streamPosition < displayStreams.length) {
  return displayStreams[streamPosition]['Index'] as int?;
}

Also, the cs does not match ces test doesn't really prove that behavior because the filtered list only contains the Czech stream, so both fallback and a real match return the same index. I’d either rename it as a fallback test or add another stream before the Czech stream so the expected values differ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants