|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | +import { mount } from '@vue/test-utils' |
| 8 | + |
| 9 | +import FileEntryStatus from '../../../views/FilesList/FileEntry/FileEntryStatus.vue' |
| 10 | + |
| 11 | +function mountStatus(props: { status: number; statusText: string; signers?: unknown[] }) { |
| 12 | + return mount(FileEntryStatus, { |
| 13 | + props: { |
| 14 | + signers: [], |
| 15 | + ...props, |
| 16 | + }, |
| 17 | + }) |
| 18 | +} |
| 19 | + |
| 20 | +describe('FileEntryStatus.vue', () => { |
| 21 | + it('renders nothing when statusText is "none"', () => { |
| 22 | + const wrapper = mountStatus({ status: 0, statusText: 'none' }) |
| 23 | + expect(wrapper.find('.status-chip').exists()).toBe(false) |
| 24 | + }) |
| 25 | + |
| 26 | + it('renders chip when statusText is not "none"', () => { |
| 27 | + const wrapper = mountStatus({ status: 3, statusText: 'Signed' }) |
| 28 | + expect(wrapper.find('.status-chip').exists()).toBe(true) |
| 29 | + }) |
| 30 | + |
| 31 | + it('displays the statusText inside the chip', () => { |
| 32 | + const wrapper = mountStatus({ status: 3, statusText: 'Signed' }) |
| 33 | + expect(wrapper.find('.status-chip__text').text()).toBe('Signed') |
| 34 | + }) |
| 35 | + |
| 36 | + it.each([ |
| 37 | + { status: -1, expected: 'status-chip--not-libresign' }, |
| 38 | + { status: 0, expected: 'status-chip--draft' }, |
| 39 | + { status: 1, expected: 'status-chip--available' }, |
| 40 | + { status: 2, expected: 'status-chip--partial' }, |
| 41 | + { status: 3, expected: 'status-chip--signed' }, |
| 42 | + { status: 4, expected: 'status-chip--deleted' }, |
| 43 | + { status: 5, expected: 'status-chip--signing' }, |
| 44 | + ])('applies variant class "$expected" for status $status', ({ status, expected }) => { |
| 45 | + const wrapper = mountStatus({ status, statusText: 'any' }) |
| 46 | + expect(wrapper.find('.status-chip').classes()).toContain(expected) |
| 47 | + }) |
| 48 | + |
| 49 | + it('falls back to draft variant for unknown status', () => { |
| 50 | + const wrapper = mountStatus({ status: 99, statusText: 'Unknown' }) |
| 51 | + expect(wrapper.find('.status-chip').classes()).toContain('status-chip--draft') |
| 52 | + }) |
| 53 | + |
| 54 | + it('chip does not apply any inline style that would override the nowrap fix', () => { |
| 55 | + const wrapper = mountStatus({ status: 3, statusText: 'Signed' }) |
| 56 | + const chip = wrapper.find('.status-chip') |
| 57 | + // white-space is controlled by scoped CSS (nowrap); no inline style should override it |
| 58 | + expect(chip.exists()).toBe(true) |
| 59 | + expect(chip.attributes('style')).toBeUndefined() |
| 60 | + }) |
| 61 | +}) |
0 commit comments