96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
|
/* Component test for HistoryFallback atom.
|
||
|
* Copyright (C) 2024 André Jaenisch
|
||
|
* SPDX-FileCopyrightText: 2024 André Jaenisch
|
||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
import '@testing-library/jest-dom';
|
||
|
import { render, screen } from '@testing-library/svelte';
|
||
|
import { init, locale, register } from 'svelte-i18n';
|
||
|
|
||
|
import HistoryFallback from '../../../src/lib/components/atoms/HistoryFallback.svelte';
|
||
|
import enMessages from '../../../src/lib/i18n/locales/en.json';
|
||
|
|
||
|
describe('HistoryFallback.svelte', () => {
|
||
|
beforeEach(() => {
|
||
|
register('en', () => import('../../../src/lib/i18n/locales/en.json'));
|
||
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
||
|
locale.set('en');
|
||
|
});
|
||
|
|
||
|
it('should mount', () => {
|
||
|
// Arrange
|
||
|
// TODO: Figure out why beforeEach is not executed
|
||
|
register('en', () => import('../../../src/lib/i18n/locales/en.json'));
|
||
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
||
|
locale.set('en');
|
||
|
const created_with = 'Anvil';
|
||
|
const instance = 'example.com';
|
||
|
const username = 'John_Doe';
|
||
|
|
||
|
// Act
|
||
|
const { container } = render(HistoryFallback, {
|
||
|
created_with,
|
||
|
instance,
|
||
|
username
|
||
|
});
|
||
|
|
||
|
// Assert
|
||
|
expect(container).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
it('should show a date', () => {
|
||
|
// Arrange
|
||
|
// TODO: Figure out why beforeEach is not executed
|
||
|
register('en', () => import('../../../src/lib/i18n/locales/en.json'));
|
||
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
||
|
locale.set('en');
|
||
|
const created_with = 'Anvil';
|
||
|
const instance = 'example.com';
|
||
|
const username = 'John_Doe';
|
||
|
|
||
|
// Act
|
||
|
render(HistoryFallback, {
|
||
|
created_with,
|
||
|
instance,
|
||
|
username
|
||
|
});
|
||
|
const date = screen.getByText(new RegExp('4/23/23'));
|
||
|
|
||
|
// Assert
|
||
|
expect(date).toBeInTheDocument();
|
||
|
});
|
||
|
|
||
|
it('should show a description', () => {
|
||
|
// Arrange
|
||
|
// TODO: Figure out why beforeEach is not executed
|
||
|
register('en', () => import('../../../src/lib/i18n/locales/en.json'));
|
||
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
||
|
locale.set('en');
|
||
|
const created_with = 'Anvil';
|
||
|
const instance = 'example.com';
|
||
|
const username = 'John_Doe';
|
||
|
|
||
|
// Act
|
||
|
render(HistoryFallback, {
|
||
|
created_with,
|
||
|
instance,
|
||
|
username
|
||
|
});
|
||
|
const created_with_content = screen.getByText(new RegExp(created_with));
|
||
|
const instance_content = screen.getByText(new RegExp(instance));
|
||
|
const username_content = screen.getByText(new RegExp(username));
|
||
|
|
||
|
// Assert
|
||
|
expect(created_with_content).toBeInTheDocument();
|
||
|
expect(instance_content).toBeInTheDocument();
|
||
|
expect(username_content).toBeInTheDocument();
|
||
|
});
|
||
|
});
|