Refactor repo-projects.ts (#32892)

- Remove jQuery
- Add types to all functions
- Tested all modified functionality

---------

Co-authored-by: Giteabot <teabot@gitea.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind 2024-12-19 09:37:12 +01:00 committed by GitHub
parent dc8f59baa5
commit 141d782c1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 148 additions and 235 deletions

View file

@ -2,7 +2,8 @@ import {beforeEach, describe, expect, test, vi} from 'vitest';
import {initRepoSettingsBranchesDrag} from './repo-settings-branches.ts';
import {POST} from '../modules/fetch.ts';
import {createSortable} from '../modules/sortable.ts';
import type {SortableEvent} from 'sortablejs';
import type {SortableEvent, SortableOptions} from 'sortablejs';
import type Sortable from 'sortablejs';
vi.mock('../modules/fetch.ts', () => ({
POST: vi.fn(),
@ -55,9 +56,10 @@ describe('Repository Branch Settings', () => {
vi.mocked(POST).mockResolvedValue({ok: true} as Response);
// Mock createSortable to capture and execute the onEnd callback
vi.mocked(createSortable).mockImplementation(async (_el: Element, options) => {
vi.mocked(createSortable).mockImplementation(async (_el: Element, options: SortableOptions) => {
options.onEnd(new Event('SortableEvent') as SortableEvent);
return {destroy: vi.fn()};
// @ts-expect-error: mock is incomplete
return {destroy: vi.fn()} as Sortable;
});
initRepoSettingsBranchesDrag();