|
| 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 | +}); |
0 commit comments