Skip to content

Commit 911ce2e

Browse files
committed
fix: added more unit tests for format date pipe
TRACEFOSS-865
1 parent eed8f33 commit 911ce2e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,37 @@
1919
* SPDX-License-Identifier: Apache-2.0
2020
********************************************************************************/
2121

22+
import { CalendarDateModel } from '@core/model/calendar-date.model';
2223
import { screen } from '@testing-library/angular';
2324
import { renderComponent } from '@tests/test-render.utils';
2425
import { SharedModule } from '..';
2526

2627
describe('FormatDatePipe', () => {
2728
it('should format date having the 1970 value for the year', async () => {
28-
await renderComponent(`{{ 'unitTest.test01' | formatDate }}`, {
29+
const date = new CalendarDateModel(null);
30+
await renderComponent(`{{ date | formatDate }}`, {
2931
imports: [SharedModule],
32+
componentProperties: { date },
3033
});
3134

32-
expect(screen.getByText('This is for unit tests purposes.')).toBeInTheDocument();
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();
3354
});
3455
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ 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();

0 commit comments

Comments
 (0)