/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
web_src/js/components/ViewFileTreeStore.test.ts
50 строк
2 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
import {createViewFileTreeStore} from './ViewFileTreeStore.ts'; test('не меняет URL и выбор до успешной частичной навигации', async () => { const fetchMock = vi.fn() .mockResolvedValueOnce(new Response('<p>Некорректный ответ</p>', {status: 200})) .mockResolvedValueOnce(new Response(` <div class="repo-view-content-data" data-document-title="docs" data-document-title-common="Rixea"></div> `, {status: 200})); vi.stubGlobal('fetch', fetchMock); const content = document.createElement('div'); content.className = 'repo-view-content'; content.innerHTML = '<p>Исходное содержимое</p>'; document.body.append(content); const initialUrl = window.location.href; const pushState = vi.spyOn(window.history, 'pushState').mockImplementation(() => {}); const store = createViewFileTreeStore({ repoLink: '/owner/repository', treePath: '', currentRefNameSubURL: 'branch/main', loadErrorText: 'Не удалось загрузить дерево файлов.', contentLoadErrorText: 'Не удалось открыть выбранный путь.', retryText: 'Повторить', }); try { expect(await store.navigateTreeView('docs')).toBe(false); expect(window.location.href).toBe(initialUrl); expect(pushState).not.toHaveBeenCalled(); expect(store.selectedItem).toBe(''); expect(store.navigationLoadError).toBe(true); expect(content.textContent).toBe('Исходное содержимое'); expect(await store.retryNavigation()).toBe(true); expect(pushState).toHaveBeenCalledWith( {treePath: 'docs', url: '/owner/repository/src/branch/main/docs'}, '', '/owner/repository/src/branch/main/docs', ); expect(store.selectedItem).toBe('docs'); expect(store.navigationLoadError).toBe(false); expect(document.title).toBe('docs - Rixea'); expect(fetchMock).toHaveBeenCalledTimes(2); } finally { window.history.replaceState({}, '', initialUrl); pushState.mockRestore(); content.remove(); vi.unstubAllGlobals(); } });