frindlymap/test/history_test.dart

55 lines
2.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:friendly_map/modules/history/history.dart';
void main() {
test('이직하면 이전 회사는 끝난 해로 닫히고 새 회사가 지금 다니는 곳이 된다', () {
final c = Career()
..begin('한빛전자', year: 2019)
..begin('누리소프트', year: 2024);
expect(c.newestFirst.map((s) => s.company), ['누리소프트', '한빛전자']);
expect(c.newestFirst.last.period, '2019 ~ 2024');
expect(c.now!.period, '2024 ~ 현재');
expect(c.now!.years(2026), 2);
});
test('같은 회사를 다시 알려도 그대로, 빈 회사 이름은 무시, 그만두면 닫힘', () {
final c = Career()..begin('한빛', year: 2020);
c.begin('한빛', year: 2025);
c.begin(' ');
expect(c.stints.length, 1);
expect(c.stints.single.from, 2020);
c.leave(year: 2026);
expect(c.now, isNull);
expect(c.stints.single.period, '2020 ~ 2026');
});
test('연도를 모르면 "기간 모름" · "~ 현재", 사용자가 기간을 고칠 수 있다', () {
final c = Career()..begin('한빛');
expect(c.now!.period, '~ 현재');
expect(Career().stints, isEmpty);
expect(const Stint('x').period, '기간 모름');
expect(c.setYears(0, from: 2018, current: true), isTrue);
expect(c.now!.period, '2018 ~ 현재');
expect(c.setYears(5, from: 1), isFalse);
});
test('같은 회사에서 기간이 겹치는지 (연도를 모르면 겹침으로)', () {
const a = Stint('한빛', from: 2015, to: 2020);
expect(a.overlaps(const Stint('한빛', from: 2019, to: 2023), 2026), isTrue);
expect(a.overlaps(const Stint('한빛', from: 2021, to: 2023), 2026), isFalse);
expect(a.overlaps(const Stint('한빛', from: 2021, current: true), 2026), isFalse);
expect(a.overlaps(const Stint('한빛'), 2026), isTrue);
expect(a.overlaps(const Stint('누리', from: 2015, to: 2020), 2026), isFalse);
});
test('글자로 저장했다 되살리기, 깨진 글자는 빈 이력', () {
final c = Career()
..begin('한빛', year: 2019)
..begin('누리', year: 2024);
final d = Career.fromJson(c.toJson());
expect(d.newestFirst.map((s) => s.period), ['2024 ~ 현재', '2019 ~ 2024']);
expect(Career.fromJson('{').stints, isEmpty);
expect(Career.fromJson('[{"x":1}]').stints, isEmpty);
});
}