diff --git a/goofy-client/libs/tech-shared/src/lib/date.util.ts b/goofy-client/libs/tech-shared/src/lib/date.util.ts index 243da7d68598a2d013e1ea0d776f3499edfe4329..3473f7380dd6c40a9a82cb5faf29969bc713adf1 100644 --- a/goofy-client/libs/tech-shared/src/lib/date.util.ts +++ b/goofy-client/libs/tech-shared/src/lib/date.util.ts @@ -70,4 +70,8 @@ export function createFutureDate(todayPlusDays: number): Date { date.setDate(date.getDate() + todayPlusDays); return date; +} + +export function isParsableToDate(date: string): boolean { + return !isNaN(Date.parse(date)); } \ No newline at end of file diff --git a/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.spec.ts b/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.spec.ts index 91fc3a7443e0126d5bec22a63486384f8316fa9e..d180052aa18acfd4ee4ceeec6fefe4b53edbeb06 100644 --- a/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.spec.ts +++ b/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.spec.ts @@ -1,90 +1,108 @@ +import { registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; 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 { registerLocaleData } from '@angular/common'; -import localeDe from '@angular/common/locales/de'; -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 { MatList, MatListItem } from '@angular/material/list'; +import { MatTooltipModule } from '@angular/material/tooltip'; 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'); describe('VorgangDetailAntragstellerComponent', () => { let component: VorgangDetailAntragstellerComponent; let fixture: ComponentFixture<VorgangDetailAntragstellerComponent>; - const antragsteller: Antragsteller = createAntragsteller(); - const antragstellerName: string = '[data-test-id="antragsteller-name"]'; - const antragstellerEmail: string = '[data-test-id="antragsteller-email"]'; - const antragstellerTelefon: string = '[data-test-id="antragsteller-telefon"]'; - const antragstellerStrasseHausnummer: string = '[data-test-id="antragsteller-strasse-hausnummer"]'; - const antragstellerPlzOrt: string = '[data-test-id="antragsteller-plz-ort"]'; - const antragstellerGeburt: string = '[data-test-id="antragsteller-geburt"]'; + const antragstellerName: string = '[data-test-id="antragsteller-name"]'; + const antragstellerEmail: string = '[data-test-id="antragsteller-email"]'; + const antragstellerTelefon: string = '[data-test-id="antragsteller-telefon"]'; + const antragstellerStrasseHausnummer: string = '[data-test-id="antragsteller-strasse-hausnummer"]'; + const antragstellerPlzOrt: string = '[data-test-id="antragsteller-plz-ort"]'; + const antragstellerGeburt: string = '[data-test-id="antragsteller-geburt"]'; + + const antragsteller: Antragsteller = createAntragsteller(); beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ VorgangDetailAntragstellerComponent, - MatIcon, - MatList, - MatListItem, - MatRipple, + MatIcon, + MatList, + MatListItem, + MatRipple, + ], + imports: [ + MatTooltipModule, ], - imports: [ - MatTooltipModule, - ], }) .compileComponents(); }); - beforeEach(() => { + beforeEach(() => { fixture = TestBed.createComponent(VorgangDetailAntragstellerComponent); component = fixture.componentInstance; - component.antragsteller = antragsteller; + component.antragsteller = antragsteller; fixture.detectChanges(); - }); + }); - it('should create', () => { + it('should create', () => { expect(component).toBeTruthy(); }) - it('should have full name of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerName); + it('should have full name', () => { + const element = getElementFromFixture(fixture, antragstellerName); - expect(element).toHaveTextContent(component.name); - }); + expect(element).toHaveTextContent(component.name); + }); - it('should have email of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerEmail); + it('should have email', () => { + const element = getElementFromFixture(fixture, antragstellerEmail); - expect(element).toHaveTextContent(antragsteller.email); - }); + expect(element).toHaveTextContent(antragsteller.email); + }); - it('should have telefon number of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerTelefon); + it('should have telefon number', () => { + const element = getElementFromFixture(fixture, antragstellerTelefon); - expect(element).toHaveTextContent(antragsteller.telefon); - }); + expect(element).toHaveTextContent(antragsteller.telefon); + }); - it('should have geburt of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerGeburt); + describe('geburtsdata', () => { - expect(element).toHaveTextContent(component.geburt); - }); + it('should show formatted geburtsdatum and geburtsort', () => { + const geburtsdatum: string = '2022-01-01'; + component.antragsteller = { ...antragsteller, geburtsdatum }; + fixture.detectChanges(); - it('should have strasse + hausnummer of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerStrasseHausnummer); + const element = getElementFromFixture(fixture, antragstellerGeburt); - expect(element).toHaveTextContent(component.antragstellerStrasseHausnummer); - }); + expect(element).toHaveTextContent(`01.01.2022 in ${antragsteller.geburtsort}`); + }); - it('should have plz + ort of Antragstellerin', () => { - const element = getElementFromFixture(fixture, antragstellerPlzOrt); + it('should show not formatted geburtsdatum on unparsable string and geburtsort', () => { + const geburtsdatum: string = 'quatsch'; + component.antragsteller = { ...antragsteller, geburtsdatum }; + fixture.detectChanges(); - expect(element).toHaveTextContent(component.antragstellerPlzOrt); - }); + const element = getElementFromFixture(fixture, antragstellerGeburt); + + expect(element).toHaveTextContent(`${geburtsdatum} in ${antragsteller.geburtsort}`); + }) + }) + + it('should have strasse + hausnummer of Antragstellerin', () => { + const element = getElementFromFixture(fixture, antragstellerStrasseHausnummer); + + expect(element).toHaveTextContent(component.antragstellerStrasseHausnummer); + }); + + it('should have plz + ort of Antragstellerin', () => { + const element = getElementFromFixture(fixture, antragstellerPlzOrt); + + expect(element).toHaveTextContent(component.antragstellerPlzOrt); + }); }); diff --git a/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.ts b/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.ts index 76ef0f5b2fdc1c57b6ebd94103918defffdbf0b4..354cf7467e7f0e89b082846f2ea6338805805dd0 100644 --- a/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.ts +++ b/goofy-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-area/vorgang-detail-antragsteller/vorgang-detail-antragsteller.component.ts @@ -1,33 +1,40 @@ 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'; + @Component({ - selector: 'goofy-client-vorgang-detail-antragsteller', - templateUrl: './vorgang-detail-antragsteller.component.html', - styleUrls: ['./vorgang-detail-antragsteller.component.scss'] + selector: 'goofy-client-vorgang-detail-antragsteller', + templateUrl: './vorgang-detail-antragsteller.component.html', + styleUrls: ['./vorgang-detail-antragsteller.component.scss'] }) export class VorgangDetailAntragstellerComponent { - @Input() antragsteller: Antragsteller; - - get antragstellerStrasseHausnummer(): string { - return `${this.antragsteller.strasse} ${this.antragsteller.hausnummer}`.trim(); - } - - get antragstellerPlzOrt(): string { - return `${this.antragsteller.plz} ${this.antragsteller.ort}`.trim(); - } - - get name(): string { - return `${this.antragsteller.anrede} ${this.antragsteller.vorname} ${this.antragsteller.nachname}`.trim(); - } - - get adresseTooltip(): string { - return `${this.antragstellerStrasseHausnummer}, ${this.antragstellerPlzOrt}`.trim(); - } - - get geburt(): string { - const geburtsdatum: Date = new Date(this.antragsteller.geburtsdatum); - const datum: string = formatFullDate(geburtsdatum); - return `${datum} in ${this.antragsteller.geburtsort}`; - } -} + + @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 { + return `${this.antragsteller.strasse} ${this.antragsteller.hausnummer}`.trim(); + } + + get antragstellerPlzOrt(): string { + return `${this.antragsteller.plz} ${this.antragsteller.ort}`.trim(); + } + + get geburt(): string { + return `${this.getGeburtsdatum()} in ${this.antragsteller.geburtsort}`; + } + + private getGeburtsdatum(): string { + if (isParsableToDate(this.antragsteller.geburtsdatum)) { + return formatFullDate(new Date(this.antragsteller.geburtsdatum)); + } + return this.antragsteller.geburtsdatum; + } +} \ No newline at end of file diff --git a/goofy-client/package.json b/goofy-client/package.json index f265c6e1b32cbc87804d25209de65949a3e0286b..05d6dac54664a96b8ed2b6427bd4e3a8f34ad384 100644 --- a/goofy-client/package.json +++ b/goofy-client/package.json @@ -36,7 +36,7 @@ "cypress:run": "npx cypress run --project apps/goofy-e2e", "cypress:version": "npx cypress version", "cypress:open": "export CYPRESS_BASE_URL=http://localhost:4300 ; npx cypress open --project apps/goofy-e2e", - "cypress:ci-run": "export CYPRESS_BASE_URL=https://e2e.dev.ozg-sh.de ; npm run cypress:delete-old-reports ; npm run cypress:run -- --config-file ./cypress-ci.json ; test=$(echo \"$?\") ; npm run cypress:pre-merge ; npm run cypress:generate-report ; exit $test", + "cypress:ci-run": "export CYPRESS_BASE_URL=https://e2e.dev.ozg-sh.de ; npm run cypress:delete-old-reports ; npm run cypress:run -- --config-file ./cypress-ci.json ; test=$(echo \"$?\") ; npm run cypress:pre-merge ; npm run cypress:generate-report ; exit $test", "cypress:delete-old-reports": "node apps/goofy-e2e/src/support/delete-old-reports.ts", "cypress:pre-merge": "node apps/goofy-e2e/src/support/pre-merge.ts", "cypress:generate-report": "npm run cypress:merge-report ; npm run cypress:generate-html",