// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

/// Tests selected date controller behavior.
library;

import 'package:flutter_test/flutter_test.dart';
import 'package:scheduler_core/scheduler_core.dart';

import 'package:focus_flow_flutter/controllers/selected_date_controller.dart';

/// Runs selected date controller tests.
void main() {
  test('selectDate is a no-op when the date is unchanged', () {
    final controller = SelectedDateController(
      initialDate: CivilDate(2026, 7, 2),
    );
    addTearDown(controller.dispose);

    var notifications = 0;
    controller.addListener(() {
      notifications += 1;
    });

    final changed = controller.selectDate(CivilDate(2026, 7, 2));

    expect(changed, isFalse);
    expect(controller.date, CivilDate(2026, 7, 2));
    expect(notifications, 0);
  });

  test('previous and next move exactly one civil day', () {
    final controller = SelectedDateController(
      initialDate: CivilDate(2026, 7, 2),
    );
    addTearDown(controller.dispose);

    expect(controller.selectPreviousDay(), isTrue);
    expect(controller.date, CivilDate(2026, 7, 1));

    expect(controller.selectNextDay(), isTrue);
    expect(controller.date, CivilDate(2026, 7, 2));
  });

  test('direct selection notifies listeners once for a changed date', () {
    final controller = SelectedDateController(
      initialDate: CivilDate(2026, 7, 2),
    );
    addTearDown(controller.dispose);

    var notifications = 0;
    controller.addListener(() {
      notifications += 1;
    });

    final changed = controller.selectDate(CivilDate(2026, 8, 14));

    expect(changed, isTrue);
    expect(controller.date, CivilDate(2026, 8, 14));
    expect(notifications, 1);
  });
}
