/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
web_src/js/components/RepoFileSearch.test.ts
67 строк
3 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
import {createApp, h, nextTick} from 'vue'; import RepoFileSearch from './RepoFileSearch.vue'; test('показывает ошибку загрузки и повторяет поиск без потери запроса', async () => { const fetchMock = vi.fn() .mockResolvedValueOnce(new Response('{}', {status: 200, headers: {'content-type': 'application/json'}})) .mockResolvedValueOnce(Response.json(['README.md', 'docs/architecture.md'], { status: 200, })); vi.stubGlobal('fetch', fetchMock); const root = document.createElement('div'); document.body.append(root); const app = createApp({ render: () => h(RepoFileSearch, { repoLink: '/owner/repository', currentRefNameSubURL: 'branch/main', treeListUrl: '/owner/repository/tree-list/branch/main', noResultsText: 'Совпадающих файлов не найдено', loadErrorText: 'Не удалось загрузить список файлов.', loadingText: 'Загрузка…', placeholder: 'Перейти к файлу', retryText: 'Повторить', }), }); try { app.mount(root); const input = root.querySelector<HTMLInputElement>('input')!; input.value = 'README'; input.dispatchEvent(new Event('input', {bubbles: true})); await vi.waitFor(() => { expect(document.body.querySelector('[role="alert"]')?.textContent).toContain('Не удалось загрузить список файлов.'); }); expect(document.body.textContent).not.toContain('Совпадающих файлов не найдено'); expect(input.getAttribute('aria-busy')).toBe('false'); input.value = 'README.md'; input.dispatchEvent(new Event('input', {bubbles: true})); await new Promise((resolve) => setTimeout(resolve, 350)); expect(fetchMock).toHaveBeenCalledTimes(1); const retryButton = Array.from(document.body.querySelectorAll('button')) .find((button) => button.textContent?.trim() === 'Повторить')!; const bubbledRetryClick = vi.fn(); document.body.addEventListener('click', bubbledRetryClick); retryButton.click(); expect(bubbledRetryClick).not.toHaveBeenCalled(); document.body.removeEventListener('click', bubbledRetryClick); await vi.waitFor(() => { expect(document.body.querySelector('[role="option"]')?.textContent).toContain('README.md'); }); await nextTick(); const selectedOption = document.body.querySelector<HTMLElement>('[role="option"][aria-selected="true"]')!; expect(input.value).toBe('README.md'); expect(input).toBe(document.activeElement); expect(input.getAttribute('aria-activedescendant')).toBe(selectedOption.id); expect(fetchMock).toHaveBeenCalledTimes(2); } finally { app.unmount(); root.remove(); vi.unstubAllGlobals(); } });