diff options
author | 6543 <6543@obermui.de> | 2024-11-27 05:41:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-27 05:41:06 +0100 |
commit | 846f6187168c807e1353d46d5d2260bf077b43cd (patch) | |
tree | c3c36ad22c01cdaeaa71fd5e7e9fd0cb7738538f /web_src/js/features/repo-settings-branches.test.ts | |
parent | 3fc1bbe971db0b1591d32c4f561fdccc9c34daf4 (diff) | |
download | gitea-846f6187168c807e1353d46d5d2260bf077b43cd.tar.gz gitea-846f6187168c807e1353d46d5d2260bf077b43cd.zip |
Add priority to protected branch (#32286)
## Solves
Currently for rules to re-order them you have to alter the creation
date. so you basicly have to delete and recreate them in the right
order. This is more than just inconvinient ...
## Solution
Add a new col for prioritization
## Demo WebUI Video
https://github.com/user-attachments/assets/92182a31-9705-4ac5-b6e3-9bb74108cbd1
---
*Sponsored by Kithara Software GmbH*
Diffstat (limited to 'web_src/js/features/repo-settings-branches.test.ts')
-rw-r--r-- | web_src/js/features/repo-settings-branches.test.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/web_src/js/features/repo-settings-branches.test.ts b/web_src/js/features/repo-settings-branches.test.ts new file mode 100644 index 0000000000..023039334f --- /dev/null +++ b/web_src/js/features/repo-settings-branches.test.ts @@ -0,0 +1,71 @@ +import {beforeEach, describe, expect, test, vi} from 'vitest'; +import {initRepoBranchesSettings} from './repo-settings-branches.ts'; +import {POST} from '../modules/fetch.ts'; +import {createSortable} from '../modules/sortable.ts'; + +vi.mock('../modules/fetch.ts', () => ({ + POST: vi.fn(), +})); + +vi.mock('../modules/sortable.ts', () => ({ + createSortable: vi.fn(), +})); + +describe('Repository Branch Settings', () => { + beforeEach(() => { + document.body.innerHTML = ` + <div id="protected-branches-list" data-update-priority-url="some/repo/branches/priority"> + <div class="flex-item tw-items-center item" data-id="1" > + <div class="drag-handle"></div> + </div> + <div class="flex-item tw-items-center item" data-id="2" > + <div class="drag-handle"></div> + </div> + <div class="flex-item tw-items-center item" data-id="3" > + <div class="drag-handle"></div> + </div> + </div> + `; + + vi.clearAllMocks(); + }); + + test('should initialize sortable for protected branches list', () => { + initRepoBranchesSettings(); + + expect(createSortable).toHaveBeenCalledWith( + document.querySelector('#protected-branches-list'), + expect.objectContaining({ + handle: '.drag-handle', + animation: 150, + }), + ); + }); + + test('should not initialize if protected branches list is not present', () => { + document.body.innerHTML = ''; + + initRepoBranchesSettings(); + + expect(createSortable).not.toHaveBeenCalled(); + }); + + test('should post new order after sorting', async () => { + vi.mocked(POST).mockResolvedValue({ok: true} as Response); + + // Mock createSortable to capture and execute the onEnd callback + vi.mocked(createSortable).mockImplementation((_el, options) => { + options.onEnd(); + return {destroy: vi.fn()}; + }); + + initRepoBranchesSettings(); + + expect(POST).toHaveBeenCalledWith( + 'some/repo/branches/priority', + expect.objectContaining({ + data: {ids: [1, 2, 3]}, + }), + ); + }); +}); |