jojo/web_src/js/components/RepoActivityTopAuthors.test.js
forgejo-backport-action 15f891abd7 [v14.0/forgejo] fix(ui): don't stretch activity top author image (#10628)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/10556

This is a followup to !10524.

In addition I changed that the tooltip triggers for the whole height, instead for only the bar height, because otherwise it is esp for small bars nearly impossible to get the tooltip to open.

Co-authored-by: Beowulf <beowulf@beocode.eu>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10628
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Beowulf <beowulf@beocode.eu>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
2025-12-29 22:13:14 +01:00

28 lines
1,020 B
JavaScript

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
import {flushPromises, mount} from '@vue/test-utils';
import RepoActivityTopAuthors from './RepoActivityTopAuthors.vue';
import {expect, test, vi} from 'vitest';
test('calc image size and shift', async () => {
vi.spyOn(RepoActivityTopAuthors.methods, 'init').mockResolvedValue({});
const repoActivityTopAuthors = mount(RepoActivityTopAuthors, {
props: {
locale: {
commitActivity: '',
},
},
});
await flushPromises();
const square = repoActivityTopAuthors.vm.calcImageSizeAndShift({naturalWidth: 50, naturalHeight: 50});
expect(square).toEqual([20, 20, 0, 0]);
const portrait = repoActivityTopAuthors.vm.calcImageSizeAndShift({naturalWidth: 5, naturalHeight: 50});
expect(portrait).toEqual([2, 20, 9, 0]);
const landscape = repoActivityTopAuthors.vm.calcImageSizeAndShift({naturalWidth: 500, naturalHeight: 5});
expect(landscape).toEqual([20, 0.2, 0, 9.9]);
});