2024-03-06 16:03:12 +01:00
|
|
|
/* Component test for ImportProject template.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2024-02-16 15:46:32 +01:00
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
import { render, screen } from '@testing-library/svelte';
|
|
|
|
import { init, locale, register } from 'svelte-i18n';
|
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
import ImportProject from '../../../src/lib/components/templates/ImportProject.svelte';
|
2024-02-16 15:46:32 +01:00
|
|
|
import enMessages from '../../../src/lib/i18n/locales/en.json';
|
|
|
|
|
|
|
|
describe('ImportProject.svelte', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
register('en', () => import('../../../src/lib/i18n/locales/en.json'));
|
|
|
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
|
|
|
locale.set('en');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mount', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
const { container } = render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(container).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a form', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(screen.getByRole('form')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a h2', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
const h2 = screen.getByRole('heading', { level: 2 });
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(h2).toBeInTheDocument();
|
|
|
|
expect(h2).toHaveTextContent(enMessages.page.import_project.heading);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have an intro text', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(screen.getByText(enMessages.page.import_project.intro)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('name', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the asterisk
|
|
|
|
const name = screen.getByLabelText(
|
|
|
|
new RegExp(enMessages.page.import_project.form.fields.name.label)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(name).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a text input', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
const name = screen.getByPlaceholderText(
|
|
|
|
enMessages.page.import_project.form.fields.name.placeholder
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(name).toBeInTheDocument();
|
|
|
|
expect(name).toHaveAttribute('type', 'text');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when empty', () => {
|
|
|
|
it('should display an error', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(
|
|
|
|
screen.getByText(enMessages.page.import_project.form.fields.name.error)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// FIXME: Enable once the dev server is running
|
|
|
|
describe.skip('when filled', () => {
|
|
|
|
it('should hide the error', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(
|
|
|
|
screen.getByText(enMessages.page.import_project.form.fields.name.error)
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show a live updating hint', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
const value = 'Vervis';
|
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data, value });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(screen.getByText(`domain.example/projects/${value}`)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('description', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
const description = screen.getByLabelText(
|
|
|
|
enMessages.page.import_project.form.fields.description.label
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(description).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a textarea', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
const description = screen.getByPlaceholderText(
|
|
|
|
enMessages.page.import_project.form.fields.description.placeholder
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(description).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('avatar', () => {
|
|
|
|
it('should have a heading', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
const components = screen.getByRole('heading', {
|
2024-02-16 15:46:32 +01:00
|
|
|
level: 3,
|
2024-02-19 11:33:41 +01:00
|
|
|
name: enMessages.page.import_project.form.components
|
2024-02-16 15:46:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
2024-02-19 11:33:41 +01:00
|
|
|
expect(components).toBeInTheDocument();
|
2024-02-16 15:46:32 +01:00
|
|
|
});
|
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
describe('repository', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
// Act
|
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
const avatar = screen.getByRole('heading', {
|
|
|
|
level: 3,
|
|
|
|
name: enMessages.page.import_project.form.avatar
|
|
|
|
});
|
2024-02-16 15:46:32 +01:00
|
|
|
|
2024-02-19 11:33:41 +01:00
|
|
|
// Assert
|
|
|
|
expect(avatar).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have an upload button', () => {
|
|
|
|
// Arrange
|
|
|
|
const data = {};
|
|
|
|
|
|
|
|
// Act
|
|
|
|
render(ImportProject, { data });
|
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const avatar = screen.getByLabelText(
|
|
|
|
new RegExp(enMessages.page.import_project.form.fields.avatar.label)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(avatar).toBeInTheDocument();
|
|
|
|
});
|
2024-02-16 15:46:32 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('components', () => {
|
|
|
|
it('should have a heading', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
const components = screen.getByRole('heading', {
|
|
|
|
level: 3,
|
|
|
|
name: enMessages.page.import_project.form.components
|
|
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(components).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('repository', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const repository = screen.getByLabelText(
|
|
|
|
enMessages.page.import_project.form.fields.repository.label
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(repository).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have an URL input', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const repository = screen.getByPlaceholderText(
|
|
|
|
enMessages.page.import_project.form.fields.repository.placeholder
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(repository).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a hint', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const repository = screen.getByText(
|
|
|
|
enMessages.page.import_project.form.fields.repository.hint
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(repository).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issues', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const issues = screen.getByLabelText(
|
|
|
|
enMessages.page.import_project.form.fields.issues.label
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(issues).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('pull requests', () => {
|
|
|
|
it('should have a label', () => {
|
|
|
|
// Arrange
|
2024-02-19 11:33:41 +01:00
|
|
|
const data = {};
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Act
|
2024-02-19 11:33:41 +01:00
|
|
|
render(ImportProject, { data });
|
2024-02-16 15:46:32 +01:00
|
|
|
|
|
|
|
// Turn into regular expression to account for the icon
|
|
|
|
const issues = screen.getByLabelText(enMessages.page.import_project.form.fields.pr.label);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(issues).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|