Skip to content

Commit 1ee6a15

Browse files
authored
Merge pull request #188 from catenax-ng/TRACEFOSS-865_Date_interpreted_instead_of_NULL
fix: interpreting the date as -- when it is NULL in backend
2 parents e4f21aa + 911ce2e commit 1ee6a15

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/********************************************************************************
2+
* Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2022, 2023 ZF Friedrichshafen AG
4+
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
5+
*
6+
* See the NOTICE file(s) distributed with this work for additional
7+
* information regarding copyright ownership.
8+
*
9+
* This program and the accompanying materials are made available under the
10+
* terms of the Apache License, Version 2.0 which is available at
11+
* https://www.apache.org/licenses/LICENSE-2.0.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
* SPDX-License-Identifier: Apache-2.0
20+
********************************************************************************/
21+
22+
import { CalendarDateModel } from '@core/model/calendar-date.model';
23+
import { screen } from '@testing-library/angular';
24+
import { renderComponent } from '@tests/test-render.utils';
25+
import { SharedModule } from '..';
26+
27+
describe('FormatDatePipe', () => {
28+
it('should format date having the 1970 value for the year', async () => {
29+
const date = new CalendarDateModel(null);
30+
await renderComponent(`{{ date | formatDate }}`, {
31+
imports: [SharedModule],
32+
componentProperties: { date },
33+
});
34+
35+
expect(screen.getByText('--')).toBeInTheDocument();
36+
});
37+
38+
it('should format date without issues', async () => {
39+
const date = new CalendarDateModel('2022-02-04T13:48:54Z');
40+
await renderComponent(`{{ date | formatDate }}`, {
41+
imports: [SharedModule],
42+
componentProperties: { date },
43+
});
44+
45+
expect(screen.getByText('2/4/2022')).toBeInTheDocument();
46+
});
47+
48+
it('should return -- if string is empty', async () => {
49+
await renderComponent(`{{ '' | formatDate }}`, {
50+
imports: [SharedModule],
51+
});
52+
53+
expect(screen.getByText('--')).toBeInTheDocument();
54+
});
55+
});

src/app/modules/shared/pipes/format-date.pipe.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ export class FormatDatePipe implements PipeTransform, OnDestroy {
4848

4949
public transform(input: string | CalendarDateModel): string {
5050
if (!input) {
51-
return '';
51+
return '--';
5252
}
5353

5454
const date = typeof input === 'string' ? this.transformStringToDate(input) : input.valueOf();
55+
if (date.getFullYear() == 1970) {
56+
return '--';
57+
}
5558
return this.dateFormat.format(date, this.formatOptions);
5659
}
5760

0 commit comments

Comments
 (0)