2024-03-10 12:22:01 +00:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2024-05-06 05:08:03 +00:00
|
|
|
import { HttpResponse, http } from 'msw';
|
2024-03-10 12:22:01 +00:00
|
|
|
|
2024-05-06 05:08:03 +00:00
|
|
|
import { EnvVarType } from '@/react/portainer/templates/app-templates/view-model';
|
2024-02-15 07:01:01 +00:00
|
|
|
import {
|
2024-05-06 05:08:03 +00:00
|
|
|
AppTemplate,
|
|
|
|
TemplateType,
|
|
|
|
} from '@/react/portainer/templates/app-templates/types';
|
|
|
|
import { server } from '@/setup-tests/server';
|
|
|
|
import { withTestQueryProvider } from '@/react/test-utils/withTestQuery';
|
2024-02-15 07:01:01 +00:00
|
|
|
|
|
|
|
import { AppTemplateFieldset } from './AppTemplateFieldset';
|
|
|
|
|
2024-05-06 05:08:03 +00:00
|
|
|
test('renders AppTemplateFieldset component', async () => {
|
2024-02-15 07:01:01 +00:00
|
|
|
const testedEnv = {
|
|
|
|
name: 'VAR2',
|
|
|
|
label: 'Variable 2',
|
|
|
|
default: 'value2',
|
|
|
|
value: 'value2',
|
|
|
|
type: EnvVarType.Text,
|
|
|
|
};
|
|
|
|
|
|
|
|
const env = [
|
|
|
|
{
|
|
|
|
name: 'VAR1',
|
|
|
|
label: 'Variable 1',
|
|
|
|
default: 'value1',
|
|
|
|
value: 'value1',
|
|
|
|
type: EnvVarType.Text,
|
|
|
|
},
|
|
|
|
testedEnv,
|
|
|
|
];
|
|
|
|
const template = {
|
2024-05-06 05:08:03 +00:00
|
|
|
id: 1,
|
|
|
|
note: 'This is a template note',
|
|
|
|
env,
|
|
|
|
type: TemplateType.ComposeStack,
|
|
|
|
categories: ['edge'],
|
|
|
|
title: 'Template title',
|
|
|
|
description: 'Template description',
|
|
|
|
administrator_only: false,
|
|
|
|
image: 'template-image',
|
|
|
|
repository: {
|
|
|
|
url: '',
|
|
|
|
stackfile: '',
|
|
|
|
},
|
|
|
|
} satisfies AppTemplate;
|
2024-02-15 07:01:01 +00:00
|
|
|
|
|
|
|
const values: Record<string, string> = {
|
|
|
|
VAR1: 'value1',
|
|
|
|
VAR2: 'value2',
|
|
|
|
};
|
|
|
|
|
2024-05-06 05:08:03 +00:00
|
|
|
server.use(
|
|
|
|
http.get('/api/templates', () =>
|
|
|
|
HttpResponse.json({ version: '3', templates: [template] })
|
|
|
|
),
|
|
|
|
http.get('/api/registries', () => HttpResponse.json([]))
|
|
|
|
);
|
2024-02-15 07:01:01 +00:00
|
|
|
|
2024-05-06 05:08:03 +00:00
|
|
|
const onChange = vi.fn();
|
|
|
|
const Wrapped = withTestQueryProvider(AppTemplateFieldset);
|
2024-02-15 07:01:01 +00:00
|
|
|
render(
|
2024-05-06 05:08:03 +00:00
|
|
|
<Wrapped templateId={template.id} values={values} onChange={onChange} />
|
2024-02-15 07:01:01 +00:00
|
|
|
);
|
|
|
|
|
2024-05-06 05:08:03 +00:00
|
|
|
screen.debug();
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
screen.findByText('This is a template note')
|
|
|
|
).resolves.toBeInTheDocument();
|
2024-02-15 07:01:01 +00:00
|
|
|
|
|
|
|
const envVarsFieldsetElement = screen.getByLabelText(testedEnv.label, {
|
|
|
|
exact: false,
|
|
|
|
});
|
|
|
|
expect(envVarsFieldsetElement).toBeInTheDocument();
|
|
|
|
});
|