9dfa06ffee
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Signed-off-by: cls_宁波本机 <908705107@qq.com>
103 lines
3.1 KiB
Dart
103 lines
3.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:buzz/features/channels/date_formatters.dart';
|
|
|
|
/// Helper: build a unix-second timestamp from a local DateTime.
|
|
int _ts(DateTime local) => local.millisecondsSinceEpoch ~/ 1000;
|
|
|
|
void main() {
|
|
group('formatDayHeading', () {
|
|
// Fix "now" so tests are deterministic.
|
|
final now = DateTime(2026, 4, 23, 14, 30); // Apr 23 2026, 2:30 PM local
|
|
|
|
test('same day returns "Today"', () {
|
|
final morning = _ts(DateTime(2026, 4, 23, 8, 0));
|
|
expect(formatDayHeading(morning, now: now), 'Today');
|
|
});
|
|
|
|
test('yesterday returns "Yesterday"', () {
|
|
final yesterday = _ts(DateTime(2026, 4, 22, 18, 0));
|
|
expect(formatDayHeading(yesterday, now: now), 'Yesterday');
|
|
});
|
|
|
|
test('older date returns full formatted date', () {
|
|
final older = _ts(DateTime(2026, 3, 31, 12, 0));
|
|
expect(formatDayHeading(older, now: now), 'Tuesday, March 31, 2026');
|
|
});
|
|
|
|
test('midnight boundary: 11:59 PM today vs 12:01 AM tomorrow', () {
|
|
final lateTonight = _ts(DateTime(2026, 4, 23, 23, 59));
|
|
final earlyTomorrow = _ts(DateTime(2026, 4, 24, 0, 1));
|
|
|
|
expect(formatDayHeading(lateTonight, now: now), 'Today');
|
|
// Tomorrow relative to our fixed "now" is not today or yesterday.
|
|
expect(
|
|
formatDayHeading(earlyTomorrow, now: now),
|
|
'Friday, April 24, 2026',
|
|
);
|
|
});
|
|
|
|
test('cross-month boundary: April 1 → March 31 is yesterday', () {
|
|
final april1 = DateTime(2026, 4, 1, 10, 0);
|
|
final march31 = _ts(DateTime(2026, 3, 31, 20, 0));
|
|
expect(formatDayHeading(march31, now: april1), 'Yesterday');
|
|
});
|
|
});
|
|
|
|
group('isSameDay', () {
|
|
test('same calendar day returns true', () {
|
|
final a = _ts(DateTime(2026, 4, 23, 1, 0));
|
|
final b = _ts(DateTime(2026, 4, 23, 23, 59));
|
|
expect(isSameDay(a, b), isTrue);
|
|
});
|
|
|
|
test('different days returns false', () {
|
|
final a = _ts(DateTime(2026, 4, 23, 23, 59));
|
|
final b = _ts(DateTime(2026, 4, 24, 0, 1));
|
|
expect(isSameDay(a, b), isFalse);
|
|
});
|
|
});
|
|
|
|
group('formatThreadSummaryLastReplyTime', () {
|
|
const now = 2_000_000;
|
|
|
|
test('uses expanded relative units', () {
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(now - 30, nowSeconds: now),
|
|
'just now',
|
|
);
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(now - 60, nowSeconds: now),
|
|
'1 minute ago',
|
|
);
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(now - 3 * 3600, nowSeconds: now),
|
|
'3 hours ago',
|
|
);
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(now - 2 * 86400, nowSeconds: now),
|
|
'2 days ago',
|
|
);
|
|
});
|
|
|
|
test('uses a short month and ordinal for older replies', () {
|
|
final may19 = _ts(DateTime(2026, 5, 19, 12));
|
|
final may27 = _ts(DateTime(2026, 5, 27, 12));
|
|
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(
|
|
may19,
|
|
nowSeconds: _ts(DateTime(2026, 5, 27, 12)),
|
|
),
|
|
'on May 19th',
|
|
);
|
|
expect(
|
|
formatThreadSummaryLastReplyTime(
|
|
may27,
|
|
nowSeconds: _ts(DateTime(2026, 6, 4, 12)),
|
|
),
|
|
'on May 27th',
|
|
);
|
|
});
|
|
});
|
|
}
|