Files
logic-puzzle/test/ambience_test.dart
Hadrian Burkhardt 68871ec573 Expand narrated story, preserve solved patterns, and add ambience
Connect the island story with new character memories and narrative transitions.
Blend each solved symbol into its artwork and retain a replayable pattern stamp.
Allow completed grids to be inspected after navigation and app restarts.
Reduce campaign difficulty spikes and keep explained story hints free.

Append 24 narrated continuations while preserving original PCM takes. Add
four offline environmental loops with saved mute/volume controls, scene
fades, narration ducking and lifecycle handling.

Validation: 31 unit/widget tests, Flutter analysis, narration and soundscape
asset checks, tablet discovery layouts and extended-audio integration,
including simultaneous active voice and ambience mixer tracks.
2026-11-02 05:04:57 +01:00

130 lines
3.6 KiB
Dart

import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:lumen/services/ambience.dart';
class _Output implements AmbienceOutput {
Soundscape? scene;
double gain = 0;
bool playing = false, disposed = false, fail = false;
Completer<void>? loading;
@override
Future<void> load(Soundscape value) async {
if (fail) throw StateError('No decoder');
await loading?.future;
scene = value;
}
@override
Future<void> volume(double value) async => gain = value;
@override
Future<void> play() async => playing = true;
@override
Future<void> stop() async => playing = false;
@override
Future<void> dispose() async => disposed = true;
}
void main() {
test('bridge, harbour and tower have their own atmosphere', () {
expect(soundscapeFor(6), Soundscape.bridge);
for (final i in [4, 5, 7]) {
expect(soundscapeFor(i), Soundscape.harbour);
}
for (final i in [8, 9, 10]) {
expect(soundscapeFor(i), Soundscape.tower);
}
expect(soundscapeFor(0), Soundscape.cottage);
expect(soundscapeFor(11), Soundscape.cottage);
});
test(
'voice ducks atmosphere, pause restores it, mute and background stop it',
() async {
final output = _Output();
final ambience = Ambience(output: output);
void update({
bool voice = false,
bool enabled = true,
bool foreground = true,
}) => ambience.update(
scene: Soundscape.bridge,
enabled: enabled,
foreground: foreground,
narrating: voice,
volume: .7,
);
update();
await ambience.settled;
expect(output.playing, true);
expect(output.gain, closeTo(.28, .0001));
update(voice: true);
await ambience.settled;
expect(output.gain, closeTo(.07, .0001));
update();
await ambience.settled;
expect(output.gain, closeTo(.28, .0001));
update(enabled: false);
await ambience.settled;
expect(output.playing, false);
update();
await ambience.settled;
update(foreground: false);
await ambience.settled;
expect(output.playing, false);
ambience.dispose();
await Future<void>.delayed(Duration.zero);
expect(output.disposed, true);
},
);
test('a mute while loading cannot start a stale sound', () async {
final output = _Output()..loading = Completer<void>();
final ambience = Ambience(output: output);
ambience.update(
scene: Soundscape.bridge,
enabled: true,
foreground: true,
narrating: false,
volume: 1,
);
await Future<void>.delayed(Duration.zero);
ambience.update(
scene: Soundscape.bridge,
enabled: false,
foreground: true,
narrating: false,
volume: 1,
);
output.loading!.complete();
await ambience.settled;
expect(output.playing, false);
expect(output.gain, 0);
ambience.dispose();
});
test(
'failed atmosphere stays isolated and can recover after toggling',
() async {
final output = _Output()..fail = true;
final ambience = Ambience(output: output);
void update(bool enabled) => ambience.update(
scene: Soundscape.bridge,
enabled: enabled,
foreground: true,
narrating: false,
volume: .5,
);
update(true);
await ambience.settled;
expect(ambience.error, isNotEmpty);
expect(output.playing, false);
update(false);
await ambience.settled;
output.fail = false;
update(true);
await ambience.settled;
expect(ambience.error, isEmpty);
expect(output.playing, true);
ambience.dispose();
},
);
}