/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
web_src/js/components/DiffCommitSelector.test.ts
105 строк
4 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
import {createApp} from 'vue'; import DiffCommitSelector from './DiffCommitSelector.vue'; test('показывает ошибку списка коммитов и восстанавливает открытое меню', async () => { const fetchMock = vi.fn() .mockResolvedValueOnce(Response.json({commits: 'invalid'}, {status: 200})) .mockResolvedValueOnce(Response.json({ commits: [{ id: '0123456789abcdef', summary: 'feat: добавить безопасный повтор', committer_or_author_name: 'Тестовый автор', time: '2026-08-01T03:00:00Z', short_sha: '0123456', }], last_review_commit_sha: '', locale: { lang: 'ru-RU', show_all_commits: 'Показать все коммиты', stats_num_commits: '1 коммит', stats_num_commits_1: '%d коммит', stats_num_commits_n: '%d коммитов', show_changes_since_your_last_review: 'Показать изменения после отзыва', select_commit_hold_shift_for_range: 'Выберите коммит.', }, }, {status: 200})); vi.stubGlobal('fetch', fetchMock); vi.stubGlobal('innerWidth', 375); const root = document.createElement('div'); root.id = 'diff-commit-select'; root.setAttribute('data-merge-base', '0000000000000000'); root.setAttribute('data-issuelink', '/owner/repository/pulls/1'); root.setAttribute('data-queryparams', '?style=unified'); root.setAttribute('data-filter_changes_by_commit', 'Фильтр по коммиту'); root.setAttribute('data-load-error', 'Не удалось загрузить список коммитов.'); root.setAttribute('data-loading', 'Загрузка…'); root.setAttribute('data-retry', 'Повторить'); document.body.append(root); const app = createApp(DiffCommitSelector); try { app.mount(root); const expandButton = root.querySelector<HTMLButtonElement>('button')!; expandButton.click(); await vi.waitFor(() => { expect(root.querySelector('[role="alert"]')?.textContent).toContain('Не удалось загрузить список коммитов.'); }); const retryButton = root.querySelector<HTMLButtonElement>('[role="alert"] button')!; expect(expandButton.getAttribute('aria-expanded')).toBe('true'); expect(expandButton.getAttribute('aria-busy')).toBe('false'); expect(root.textContent).not.toContain('Показать все коммиты'); expect(retryButton).toBe(document.activeElement); expandButton.click(); expandButton.click(); await vi.waitFor(() => expect(root.querySelector('[role="alert"]')).not.toBeNull()); expect(fetchMock).toHaveBeenCalledTimes(1); const menu = root.querySelector<HTMLElement>('[role="menu"]')!; const menuRectMock = vi.spyOn(menu, 'getBoundingClientRect').mockReturnValue({ x: -24, y: 100, width: 375, height: 180, top: 100, right: 351, bottom: 280, left: -24, toJSON: () => ({}), }); const bubbledRetryClick = vi.fn(); document.body.addEventListener('click', bubbledRetryClick); retryButton.click(); expect(bubbledRetryClick).not.toHaveBeenCalled(); document.body.removeEventListener('click', bubbledRetryClick); await vi.waitFor(() => { expect(root.querySelectorAll('[role="menuitem"]')).toHaveLength(2); }); const showAllItem = root.querySelector<HTMLElement>('[role="menuitem"]')!; expect(root.textContent).toContain('feat: добавить безопасный повтор'); expect(expandButton.getAttribute('aria-activedescendant')).toBe(showAllItem.id); expect(showAllItem).toBe(document.activeElement); await vi.waitFor(() => expect(menu.style.transform).toBe('translateX(32px)')); menuRectMock.mockReturnValue({ x: 100, y: 100, width: 300, height: 180, top: 100, right: 400, bottom: 280, left: 100, toJSON: () => ({}), }); window.dispatchEvent(new Event('resize')); await vi.waitFor(() => expect(menu.style.transform).toBe('translateX(-33px)')); expect(fetchMock).toHaveBeenCalledTimes(2); } finally { app.unmount(); root.remove(); vi.unstubAllGlobals(); } });