130 lines
4.9 KiB
Dart
130 lines
4.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/artifacts/domain/artifact_kind.dart';
|
|
|
|
void main() {
|
|
test('classifies images and videos from their recorded content type', () {
|
|
expect(artifactKind('image/png', 'shot.png'), ArtifactKind.image);
|
|
expect(
|
|
artifactKind('image/svg+xml; charset=utf-8', 'plot'),
|
|
ArtifactKind.image,
|
|
);
|
|
expect(artifactKind('video/mp4', 'clip.mp4'), ArtifactKind.video);
|
|
});
|
|
|
|
test('matches the web client file-kind vocabulary by MIME and name', () {
|
|
const cases = <(String, String, ArtifactKind)>[
|
|
('audio/mpeg', 'sound.mp3', ArtifactKind.audio),
|
|
('application/pdf', 'report', ArtifactKind.pdf),
|
|
('application/octet-stream', 'data.pdf', ArtifactKind.pdf),
|
|
('application/json', 'payload', ArtifactKind.json),
|
|
('text/plain', 'config.json', ArtifactKind.json),
|
|
('application/zip', 'bundle', ArtifactKind.archive),
|
|
('text/plain', 'backup.tar.gz', ArtifactKind.archive),
|
|
('text/csv', 'rows', ArtifactKind.spreadsheet),
|
|
('application/octet-stream', 'sheet.xlsx', ArtifactKind.spreadsheet),
|
|
('text/plain', 'run.log', ArtifactKind.log),
|
|
('application/xml', 'layout', ArtifactKind.code),
|
|
('text/plain', 'main.go', ArtifactKind.code),
|
|
('text/html; charset=utf-8', 'session.html', ArtifactKind.document),
|
|
('text/plain', 'notes.txt', ArtifactKind.document),
|
|
('application/octet-stream', 'blob.bin', ArtifactKind.other),
|
|
('', '', ArtifactKind.other),
|
|
('application/x-unknown-thing', 'report.unknownext', ArtifactKind.other),
|
|
];
|
|
for (final (contentType, name, kind) in cases) {
|
|
expect(
|
|
artifactKind(contentType, name),
|
|
kind,
|
|
reason: '$contentType $name',
|
|
);
|
|
}
|
|
});
|
|
|
|
test('names every kind in prose, with File as the unknown fallback', () {
|
|
expect(artifactKindLabel(ArtifactKind.image), 'Image');
|
|
expect(artifactKindLabel(ArtifactKind.video), 'Video');
|
|
expect(artifactKindLabel(ArtifactKind.audio), 'Audio');
|
|
expect(artifactKindLabel(ArtifactKind.pdf), 'PDF');
|
|
expect(artifactKindLabel(ArtifactKind.json), 'JSON');
|
|
expect(artifactKindLabel(ArtifactKind.archive), 'Archive');
|
|
expect(artifactKindLabel(ArtifactKind.spreadsheet), 'Spreadsheet');
|
|
expect(artifactKindLabel(ArtifactKind.log), 'Log');
|
|
expect(artifactKindLabel(ArtifactKind.code), 'Code');
|
|
expect(artifactKindLabel(ArtifactKind.document), 'Document');
|
|
expect(artifactKindLabel(ArtifactKind.other), 'File');
|
|
});
|
|
|
|
test('formats recorded bytes like the web client', () {
|
|
expect(humanBytes(0), '0 B');
|
|
expect(humanBytes(999), '999 B');
|
|
expect(humanBytes(1024), '1.0 KiB');
|
|
expect(humanBytes(1536), '1.5 KiB');
|
|
expect(humanBytes(2 * 1024 * 1024), '2.0 MiB');
|
|
expect(humanBytes(3 * 1024 * 1024 * 1024), '3.0 GiB');
|
|
});
|
|
|
|
test('markdown and viewer artifacts use the shared classification', () {
|
|
const markdown = <(String, String)>[
|
|
('text/markdown', 'plan'),
|
|
('text/markdown; charset=utf-8', 'plan'),
|
|
('text/plain', 'notes'),
|
|
('application/octet-stream', 'input.md'),
|
|
('', 'memory.markdown'),
|
|
('', 'output.txt'),
|
|
];
|
|
for (final (contentType, name) in markdown) {
|
|
expect(isMarkdownArtifact(contentType, name), isTrue, reason: name);
|
|
}
|
|
for (final (contentType, name) in <(String, String)>[
|
|
('text/html', 'session.html'),
|
|
('text/csv', 'rows.csv'),
|
|
('application/json', 'payload.json'),
|
|
('text/x-python', 'main.py'),
|
|
('application/xml', 'shot.png.xml'),
|
|
('', ''),
|
|
]) {
|
|
expect(isMarkdownArtifact(contentType, name), isFalse, reason: name);
|
|
}
|
|
|
|
for (final (contentType, name) in <(String, String)>[
|
|
('image/png', 'shot.png'),
|
|
('video/mp4', 'clip.mp4'),
|
|
('text/markdown', 'input.md'),
|
|
('text/plain', 'memory.txt'),
|
|
('text/plain', 'run.log'),
|
|
('', 'output.md'),
|
|
// The text family previews as selectable text, not an external file.
|
|
('application/json', 'payload.json'),
|
|
('text/x-python', 'main.py'),
|
|
('application/octet-stream', 'config.yaml'),
|
|
('', 'build.log'),
|
|
]) {
|
|
expect(isViewerArtifact(contentType, name), isTrue, reason: name);
|
|
}
|
|
expect(
|
|
artifactPreviewFormat('application/json', 'payload.json'),
|
|
ArtifactPreviewFormat.text,
|
|
);
|
|
expect(
|
|
artifactPreviewFormat('text/markdown', 'plan'),
|
|
ArtifactPreviewFormat.markdown,
|
|
);
|
|
expect(
|
|
artifactPreviewFormat('text/html', 'report.html'),
|
|
ArtifactPreviewFormat.html,
|
|
);
|
|
expect(
|
|
artifactPreviewFormat('', 'session-repair-3-ab12.html'),
|
|
ArtifactPreviewFormat.none,
|
|
);
|
|
for (final (contentType, name) in <(String, String)>[
|
|
('text/html', 'session.html'),
|
|
('application/zip', 'bundle.zip'),
|
|
('application/octet-stream', 'blob.bin'),
|
|
('', ''),
|
|
]) {
|
|
expect(isViewerArtifact(contentType, name), isFalse, reason: name);
|
|
}
|
|
});
|
|
}
|