Files
pipelines/app/test/features/attention/notify/notification_models_test.dart
T

159 lines
4.9 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
import 'package:pipelines_app/features/attention/notify/notification_models.dart';
NotificationEnvironment _env({
bool supported = true,
bool secure = true,
String permission = 'default',
}) => NotificationEnvironment(
supported: supported,
secureContext: secure,
permission: permission,
);
void main() {
group('permission state is the platform\'s own answer', () {
test('an unsupported API and an insecure page win over the word', () {
expect(
notificationStateOf(_env(supported: false, permission: 'granted')),
NotificationPermissionState.unsupported,
);
expect(
notificationStateOf(_env(secure: false, permission: 'granted')),
NotificationPermissionState.needsSecureContext,
);
});
test('granted is never assumed from an unrecognised word', () {
expect(
notificationStateOf(_env(permission: 'prompt')),
NotificationPermissionState.notRequested,
);
expect(
notificationStateOf(_env(permission: '')),
NotificationPermissionState.notRequested,
);
expect(
notificationStateOf(_env(permission: 'granted')),
NotificationPermissionState.granted,
);
expect(
notificationStateOf(_env(permission: 'denied')),
NotificationPermissionState.denied,
);
});
test('each state carries the browser model\'s own wire word', () {
expect(NotificationPermissionState.unsupported.wireName, 'unsupported');
expect(
NotificationPermissionState.needsSecureContext.wireName,
'insecure',
);
expect(NotificationPermissionState.notRequested.wireName, 'default');
expect(NotificationPermissionState.granted.wireName, 'granted');
expect(NotificationPermissionState.denied.wireName, 'denied');
});
});
group('the permission view', () {
test('only a still-undecided page can request', () {
final view = notificationPermissionView(
NotificationPermissionState.notRequested,
);
expect(view.canRequest, isTrue);
expect(view.actionLabel, notificationRequestLabel);
expect(view.body, notificationDefaultCopy);
for (final state in [
NotificationPermissionState.unsupported,
NotificationPermissionState.needsSecureContext,
NotificationPermissionState.granted,
NotificationPermissionState.denied,
]) {
final other = notificationPermissionView(state);
expect(other.canRequest, isFalse, reason: '$state');
expect(other.actionLabel, isNull, reason: '$state');
}
});
test('asked only changes the undecided wording', () {
expect(
notificationPermissionView(
NotificationPermissionState.notRequested,
asked: true,
).body,
notificationDefaultAskedCopy,
);
expect(
notificationPermissionView(
NotificationPermissionState.denied,
asked: true,
).body,
notificationDeniedCopy,
);
});
test('every unavailable state names the in-app channel', () {
for (final state in [
NotificationPermissionState.unsupported,
NotificationPermissionState.needsSecureContext,
NotificationPermissionState.denied,
]) {
expect(
notificationPermissionView(state).body,
contains('in-app Needs you surface'),
reason: '$state',
);
}
});
});
group('notification content is the entry\'s own words', () {
test('the headline is the kind, nothing invented', () {
expect(
notificationAlertTitle(AttentionKind.decision),
'A run needs your decision',
);
expect(notificationAlertTitle(AttentionKind.failed), 'A run failed');
});
test('the body is the run label then its pipeline', () {
final entry = attentionEntryFor({
'id': 7,
'name': 'nightly-audit',
'title': 'Nightly audit',
'status': 'failed',
'diagnostic': 'Stage 3 stopped',
'created_at': '2026-10-22T09:00:00Z',
'finished_at': '2026-10-22T09:10:00Z',
})!;
expect(
notificationAlertBody(entry),
'Nightly audit \u00b7 nightly-audit',
);
});
test('a blank or equal pipeline is never repeated', () {
final untitled = attentionEntryFor({
'id': 7,
'name': 'release',
'status': 'failed',
'created_at': '2026-10-22T09:00:00Z',
'finished_at': '2026-10-22T09:10:00Z',
})!;
expect(notificationAlertBody(untitled), 'release');
final nameless = attentionEntryFor({
'id': 8,
'name': '',
'title': 'A title',
'status': 'failed',
'created_at': '2026-10-22T09:00:00Z',
'finished_at': '2026-10-22T09:10:00Z',
})!;
expect(notificationAlertBody(nameless), 'A title');
});
});
}