Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(date input): create new component for date input (DSP-94) #298

Merged
merged 65 commits into from Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e4cdd08
feat(date input): create new component for date input (ongoing)
May 26, 2021
7a3f730
feat(date input): component for date input (ongoing)
May 27, 2021
3487698
feat(date input): component for date input (ongoing)
May 27, 2021
c89d43b
feat(date input): component for date input (ongoing)
May 27, 2021
bd36043
feat(date input): component for date input (ongoing)
May 27, 2021
d05d6bf
feat(date input): component for date input (ongoing)
May 27, 2021
79153d3
feat(date input): component for date input (ongoing)
May 28, 2021
5e185df
feat(date input): component for date input (ongoing)
May 28, 2021
f4a4e90
feat(date input): component for date input (ongoing))
May 31, 2021
af02e3e
feat(date input): component for date input (ongoing))
Jun 1, 2021
5892342
feat(date input): component for date input (ongoing))
Jun 1, 2021
d5de294
feat(date input): component for date input (ongoing))
Jun 1, 2021
da7b1f8
feat(date input): component for date input (ongoing))
Jun 1, 2021
9dd504b
feat(date input): component for date input (ongoing))
Jun 1, 2021
b661bf3
feat(date input): component for date input (ongoing))
Jun 1, 2021
198d499
feat(date input): component for date input (ongoing))
Jun 1, 2021
6114a44
feat(date input): component for date input (ongoing))
Jun 1, 2021
57a0488
feat(date input): component for date input (ongoing))
Jun 1, 2021
4924318
feat(date input): component for date input (ongoing))
Jun 1, 2021
6568cb6
feat(date input): component for date input (ongoing))
Jun 2, 2021
89c01bd
feat(date input): component for date input (ongoing))
Jun 2, 2021
14a6068
feat(date input): component for date input (ongoing))
Jun 2, 2021
dec5b13
feat(date input): component for date input (ongoing))
Jun 2, 2021
10031b2
feat(date input): component for date input (ongoing))
Jun 2, 2021
fbf1946
feat(date input): component for date input (ongoing))
Jun 2, 2021
6fba550
feat(date input): component for date input (ongoing))
Jun 2, 2021
aca2df9
feat(date input): component for date input (ongoing))
Jun 2, 2021
7cf0062
feat(date input): component for date input (ongoing))
Jun 3, 2021
e523a3c
feat(date input): component for date input (ongoing))
Jun 3, 2021
0f2c4fd
feat(date input): component for date input (ongoing))
Jun 3, 2021
0b2235b
feat(date input): component for date input (ongoing))
Jun 3, 2021
525e6da
feat(date input): move new date components to lib
Jun 3, 2021
08e4e93
fix(date edit): make calendar update async
Jun 3, 2021
4003d77
refactor(viewer): remove check if a date can be edited
Jun 3, 2021
8ab4e9c
feat(date input text): add Input for required validator
Jun 3, 2021
41beac5
feat(date edit): add Input for required validator
Jun 3, 2021
3d44f8b
feat(date edit): adjust day selection when changing month
Jun 3, 2021
d79046d
test(date edit): add spec
Jun 3, 2021
edb48ff
test(date edit): add spec
Jun 3, 2021
468e9f9
test(date edit): add spec
Jun 7, 2021
456c71c
test(date edit): add spec
Jun 7, 2021
bf9c547
test(date edit): add spec
Jun 7, 2021
b4e52bb
test(date edit): add spec
Jun 7, 2021
abf3f40
feat(date edit): reinit days after calendar change
Jun 7, 2021
5bdcaf8
test(date edit): add spec
Jun 7, 2021
c55e74e
feat(value service): move date calc logic to service
Jun 7, 2021
58ac4d7
test(date edit): add spec
Jun 7, 2021
5f09c34
test(date edit): add spec
Jun 7, 2021
5b9e458
test(date input text): add spec
Jun 7, 2021
69a244a
test(date input text): add spec
Jun 7, 2021
d4c3f8f
test(date input text): add spec
Jun 8, 2021
a22fa04
test(date input text): add spec
Jun 8, 2021
42bbc2d
test(date input text): add spec
Jun 8, 2021
e604f01
test(date input text): add spec
Jun 8, 2021
52a6c50
test(date input text): add spectest(date input text): add spec
Jun 8, 2021
922a070
test(date input text): add spec
Jun 8, 2021
86ebb93
test(date input text): add spec
Jun 8, 2021
55dcd07
test(date input text): fix CSS
Jun 8, 2021
28bd174
feat(value service): move date calc logic to service
Jun 8, 2021
848a523
feat(value service): move date calc logic to service
Jun 8, 2021
1e2cb4a
feat(viewer): handle Islamic date (no era)
Jun 8, 2021
9429679
refactor(date edit): centralize logic for setting era
Jun 8, 2021
5a14452
feat(date input / edit): unsubscribe from valueChanges on com. destru…
Jun 8, 2021
1f5f699
refactor(viewer): remove parameters
Jun 9, 2021
7a2d826
refactor(viewer): remove injected service
Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
202 changes: 109 additions & 93 deletions projects/dsp-ui/src/lib/viewer/services/value.service.spec.ts
Expand Up @@ -61,59 +61,6 @@ describe('ValueService', () => {

});

describe('isDateEditable', () => {

it('should determine if a given date or period is editable', () => {

expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13))).toBe(true);

expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'AD', 2018, 5, 13))).toBe(true);

// before common era
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'BCE', 2018, 5, 13))).toBe(false);

// before common era
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'BC', 2018, 5, 13))).toBe(false);

// month precision
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018, 5))).toBe(false);

// year precision
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018))).toBe(false);

expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(true);

// period starts with year precision
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(false);

// period ends with year precision
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019)
))).toBe(false);

// period starts with BCE date
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'BCE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(false);

// period ends with BCE date
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'BCE', 2019, 5, 13)
))).toBe(false);

});

});

describe('isReadOnly', () => {

it('should not mark a ReadIntValue as ReadOnly', () => {
Expand Down Expand Up @@ -186,26 +133,6 @@ describe('ValueService', () => {
expect(service.isReadOnly(valueClass, readStandoffLinkValue, resPropDef)).toBeTruthy();
});

it('should mark ReadDateValue with unsupported era as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
const date: ReadDateValue =
res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasDate', ReadDateValue)[0];

date.date = new KnoraDate('GREGORIAN', 'BCE', 2019, 5, 13);

const resPropDef = new ResourcePropertyDefinition();
resPropDef.isEditable = true;

const valueClass = service.getValueTypeOrClass(date);
expect(service.isReadOnly(valueClass, date, resPropDef)).toBeTruthy();

done();

});

});

it('should not mark ReadDateValue with supported era as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
Expand All @@ -226,26 +153,6 @@ describe('ValueService', () => {

});

it('should mark ReadDateValue with unsupported precision as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
const date: ReadDateValue =
res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasDate', ReadDateValue)[0];

date.date = new KnoraDate('GREGORIAN', 'CE', 2019, 5);

const resPropDef = new ResourcePropertyDefinition();
resPropDef.isEditable = true;

const valueClass = service.getValueTypeOrClass(date);
expect(service.isReadOnly(valueClass, date, resPropDef)).toBeTruthy();

done();

});

});

it('should not mark ReadDateValue with supported precision as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
Expand Down Expand Up @@ -313,4 +220,113 @@ describe('ValueService', () => {
});

});

describe('calculateDaysInMonth', () => {

it('should calculate the number of days in February in a leap year', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2020, 2)).toEqual(29);

});

it('should calculate the number of days in February in a non leap year', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2021, 2)).toEqual(28);

});

it('should calculate the number of days in March', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2021, 3)).toEqual(31);

});

});

describe('createJDNCalendarDateFromKnoraDate', () => {

it('should create a JDN calendar date from a Knora date with day precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021, 3, 15));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459289);
expect(period.periodEnd).toEqual(2459289);

});

it('should create a JDN calendar date from a Knora date BCE with day precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'BCE', 1, 1, 1));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(1721060);
expect(period.periodEnd).toEqual(1721060);

});

it('should create a JDN calendar date from a Knora date with day precision in the Julian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('JULIAN', 'CE', 2021, 3, 15));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459302);
expect(period.periodEnd).toEqual(2459302);

});

it('should create a JDN calendar date from a Knora date with month precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021, 3));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459275);
expect(period.periodEnd).toEqual(2459305);

});

it('should create a JDN calendar date from a Knora date with year precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459216);
expect(period.periodEnd).toEqual(2459580);

});

});

describe('convertHistoricalYearToAstronomicalYear', () => {

it('should convert the year 1 BCE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'BCE', 'JULIAN')).toEqual(0);

});

it('should convert the year 2 BCE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(2, 'BCE', 'JULIAN')).toEqual(-1);

});

it('should convert the year 1 CE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'CE', 'JULIAN')).toEqual(1);

});

it('should convert the year 1 in the Islamic to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'noEra', 'ISLAMIC')).toEqual(1);

});

});
});