Files
Client/test/widget/prosemirror/pm_image_width_test.dart
T

32 lines
1.0 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:marianum_mobile/widget/prosemirror/pm_image_view.dart';
void main() {
group('resolvePmImageWidth', () {
test('returns null without a width attribute', () {
expect(resolvePmImageWidth(null, 300), isNull);
});
test('returns null for unparseable widths', () {
expect(resolvePmImageWidth('auto', 300), isNull);
});
test('resolves px, %, em and rem', () {
expect(resolvePmImageWidth('120px', 300), 120);
expect(resolvePmImageWidth('50%', 300), 150);
expect(resolvePmImageWidth('2em', 300), 32);
expect(resolvePmImageWidth('2rem', 300), 32);
});
test('caps at the available width and floors at one pixel', () {
expect(resolvePmImageWidth('900px', 300), 300);
expect(resolvePmImageWidth('0px', 300), 1);
});
test('survives zero or sub-pixel available width', () {
expect(resolvePmImageWidth('50%', 0), isNull);
expect(resolvePmImageWidth('120px', 0.5), isNull);
});
});
}