Skip to content
Snippets Groups Projects
Commit 89654857 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-1819 fix date parse error

parent 186f08aa
No related branches found
No related tags found
No related merge requests found
...@@ -71,3 +71,7 @@ export function createFutureDate(todayPlusDays: number): Date { ...@@ -71,3 +71,7 @@ export function createFutureDate(todayPlusDays: number): Date {
return date; return date;
} }
export function isParsableToDate(date: string): boolean {
return !isNaN(Date.parse(date));
}
\ No newline at end of file
import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatRipple } from '@angular/material/core'; import { MatRipple } from '@angular/material/core';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatList, MatListItem } from '@angular/material/list';
import { MatIcon } from '@angular/material/icon'; import { MatIcon } from '@angular/material/icon';
import { registerLocaleData } from '@angular/common'; import { MatList, MatListItem } from '@angular/material/list';
import localeDe from '@angular/common/locales/de'; import { MatTooltipModule } from '@angular/material/tooltip';
import { VorgangDetailAntragstellerComponent } from './vorgang-detail-antragsteller.component';
import { createAntragsteller } from 'libs/vorgang-shared/test/vorgang';
import { getElementFromFixture } from 'libs/test-utils/src/lib/helper';
import { Antragsteller } from '@goofy-client/vorgang-shared'; import { Antragsteller } from '@goofy-client/vorgang-shared';
import { getElementFromFixture } from 'libs/test-utils/src/lib/helper';
import { createAntragsteller } from 'libs/vorgang-shared/test/vorgang';
import { VorgangDetailAntragstellerComponent } from './vorgang-detail-antragsteller.component';
registerLocaleData(localeDe, 'de'); registerLocaleData(localeDe, 'de');
describe('VorgangDetailAntragstellerComponent', () => { describe('VorgangDetailAntragstellerComponent', () => {
let component: VorgangDetailAntragstellerComponent; let component: VorgangDetailAntragstellerComponent;
let fixture: ComponentFixture<VorgangDetailAntragstellerComponent>; let fixture: ComponentFixture<VorgangDetailAntragstellerComponent>;
const antragsteller: Antragsteller = createAntragsteller();
const antragstellerName: string = '[data-test-id="antragsteller-name"]'; const antragstellerName: string = '[data-test-id="antragsteller-name"]';
const antragstellerEmail: string = '[data-test-id="antragsteller-email"]'; const antragstellerEmail: string = '[data-test-id="antragsteller-email"]';
...@@ -24,6 +23,8 @@ describe('VorgangDetailAntragstellerComponent', () => { ...@@ -24,6 +23,8 @@ describe('VorgangDetailAntragstellerComponent', () => {
const antragstellerPlzOrt: string = '[data-test-id="antragsteller-plz-ort"]'; const antragstellerPlzOrt: string = '[data-test-id="antragsteller-plz-ort"]';
const antragstellerGeburt: string = '[data-test-id="antragsteller-geburt"]'; const antragstellerGeburt: string = '[data-test-id="antragsteller-geburt"]';
const antragsteller: Antragsteller = createAntragsteller();
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ declarations: [
...@@ -51,30 +52,47 @@ describe('VorgangDetailAntragstellerComponent', () => { ...@@ -51,30 +52,47 @@ describe('VorgangDetailAntragstellerComponent', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}) })
it('should have full name of Antragstellerin', () => { it('should have full name', () => {
const element = getElementFromFixture(fixture, antragstellerName); const element = getElementFromFixture(fixture, antragstellerName);
expect(element).toHaveTextContent(component.name); expect(element).toHaveTextContent(component.name);
}); });
it('should have email of Antragstellerin', () => { it('should have email', () => {
const element = getElementFromFixture(fixture, antragstellerEmail); const element = getElementFromFixture(fixture, antragstellerEmail);
expect(element).toHaveTextContent(antragsteller.email); expect(element).toHaveTextContent(antragsteller.email);
}); });
it('should have telefon number of Antragstellerin', () => { it('should have telefon number', () => {
const element = getElementFromFixture(fixture, antragstellerTelefon); const element = getElementFromFixture(fixture, antragstellerTelefon);
expect(element).toHaveTextContent(antragsteller.telefon); expect(element).toHaveTextContent(antragsteller.telefon);
}); });
it('should have geburt of Antragstellerin', () => { describe('geburtsdata', () => {
it('should show formatted geburtsdatum and geburtsort', () => {
const geburtsdatum: string = '2022-01-01';
component.antragsteller = { ...antragsteller, geburtsdatum };
fixture.detectChanges();
const element = getElementFromFixture(fixture, antragstellerGeburt); const element = getElementFromFixture(fixture, antragstellerGeburt);
expect(element).toHaveTextContent(component.geburt); expect(element).toHaveTextContent(`01.01.2022 in ${antragsteller.geburtsort}`);
}); });
it('should show not formatted geburtsdatum on unparsable string and geburtsort', () => {
const geburtsdatum: string = 'quatsch';
component.antragsteller = { ...antragsteller, geburtsdatum };
fixture.detectChanges();
const element = getElementFromFixture(fixture, antragstellerGeburt);
expect(element).toHaveTextContent(`${geburtsdatum} in ${antragsteller.geburtsort}`);
})
})
it('should have strasse + hausnummer of Antragstellerin', () => { it('should have strasse + hausnummer of Antragstellerin', () => {
const element = getElementFromFixture(fixture, antragstellerStrasseHausnummer); const element = getElementFromFixture(fixture, antragstellerStrasseHausnummer);
......
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { formatFullDate } from '@goofy-client/tech-shared'; import { formatFullDate, isParsableToDate } from '@goofy-client/tech-shared';
import { Antragsteller } from '@goofy-client/vorgang-shared'; import { Antragsteller } from '@goofy-client/vorgang-shared';
@Component({ @Component({
selector: 'goofy-client-vorgang-detail-antragsteller', selector: 'goofy-client-vorgang-detail-antragsteller',
templateUrl: './vorgang-detail-antragsteller.component.html', templateUrl: './vorgang-detail-antragsteller.component.html',
styleUrls: ['./vorgang-detail-antragsteller.component.scss'] styleUrls: ['./vorgang-detail-antragsteller.component.scss']
}) })
export class VorgangDetailAntragstellerComponent { export class VorgangDetailAntragstellerComponent {
@Input() antragsteller: Antragsteller; @Input() antragsteller: Antragsteller;
get name(): string {
return `${this.antragsteller.anrede} ${this.antragsteller.vorname} ${this.antragsteller.nachname}`.trim();
}
get adresseTooltip(): string {
return `${this.antragstellerStrasseHausnummer}, ${this.antragstellerPlzOrt}`.trim();
}
get antragstellerStrasseHausnummer(): string { get antragstellerStrasseHausnummer(): string {
return `${this.antragsteller.strasse} ${this.antragsteller.hausnummer}`.trim(); return `${this.antragsteller.strasse} ${this.antragsteller.hausnummer}`.trim();
} }
...@@ -17,17 +27,14 @@ export class VorgangDetailAntragstellerComponent { ...@@ -17,17 +27,14 @@ export class VorgangDetailAntragstellerComponent {
return `${this.antragsteller.plz} ${this.antragsteller.ort}`.trim(); return `${this.antragsteller.plz} ${this.antragsteller.ort}`.trim();
} }
get name(): string { get geburt(): string {
return `${this.antragsteller.anrede} ${this.antragsteller.vorname} ${this.antragsteller.nachname}`.trim(); return `${this.getGeburtsdatum()} in ${this.antragsteller.geburtsort}`;
} }
get adresseTooltip(): string { private getGeburtsdatum(): string {
return `${this.antragstellerStrasseHausnummer}, ${this.antragstellerPlzOrt}`.trim(); if (isParsableToDate(this.antragsteller.geburtsdatum)) {
return formatFullDate(new Date(this.antragsteller.geburtsdatum));
} }
return this.antragsteller.geburtsdatum;
get geburt(): string {
const geburtsdatum: Date = new Date(this.antragsteller.geburtsdatum);
const datum: string = formatFullDate(geburtsdatum);
return `${datum} in ${this.antragsteller.geburtsort}`;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment