2130cd74e9
Бэк: хелпер CompetitorElements нормализует элементы и выводит легаси site_url/directory_urls из ВСЕХ карточек. Ручки manual/update принимают elements. Фронт: компонент CompetitorElementsEditor встроен в формы создания и правки на экранах Поле и Предложения. Прежний баг - пересбор directory_urls из двух полей - закрыт. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
import CompetitorElementsEditor from '../../resources/js/views/autopodbor/screens/CompetitorElementsEditor.vue';
|
|
import type { CompetitorElement } from '../../resources/js/api/autopodbor';
|
|
|
|
describe('CompetitorElementsEditor', () => {
|
|
it('показывает элемент с его сайтом и карточкой', () => {
|
|
const model: CompetitorElement[] = [{ name: 'Нанжуль', sites: ['nanzhul.ru'], cards: ['https://2gis.ru/x/firm/1'] }];
|
|
const w = mount(CompetitorElementsEditor, { props: { modelValue: model } });
|
|
const inputs = w.findAll('input');
|
|
// имя + 1 сайт + 1 карточка = 3 поля ввода
|
|
expect(inputs.length).toBe(3);
|
|
expect((inputs[0].element as HTMLInputElement).value).toBe('Нанжуль');
|
|
});
|
|
|
|
it('добавляет элемент по кнопке', async () => {
|
|
const model: CompetitorElement[] = [{ name: 'A', sites: [''], cards: [''] }];
|
|
const w = mount(CompetitorElementsEditor, { props: { modelValue: model } });
|
|
await w.find('.ld-btn.ghost').trigger('click'); // «+ добавить элемент»
|
|
expect(model.length).toBe(2);
|
|
});
|
|
|
|
it('добавляет сайт внутри элемента', async () => {
|
|
const model: CompetitorElement[] = [{ name: 'A', sites: ['a.ru'], cards: [] }];
|
|
const w = mount(CompetitorElementsEditor, { props: { modelValue: model } });
|
|
const addSite = w.findAll('.ld-elem__add').find((b) => b.text().includes('сайт'));
|
|
await addSite!.trigger('click');
|
|
expect(model[0].sites.length).toBe(2);
|
|
});
|
|
|
|
it('удаляет элемент', async () => {
|
|
const model: CompetitorElement[] = [
|
|
{ name: 'A', sites: [], cards: [] },
|
|
{ name: 'B', sites: [], cards: [] },
|
|
];
|
|
const w = mount(CompetitorElementsEditor, { props: { modelValue: model } });
|
|
await w.find('.ld-elem__delel').trigger('click');
|
|
expect(model.length).toBe(1);
|
|
expect(model[0].name).toBe('B');
|
|
});
|
|
});
|