debian-mirror-gitlab/spec/frontend/diffs/components/compare_dropdown_layout_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { mount } from '@vue/test-utils';
2020-04-22 19:07:51 +05:30
import { trimText } from 'helpers/text_helper';
import CompareDropdownLayout from '~/diffs/components/compare_dropdown_layout.vue';
2021-03-11 19:13:27 +05:30
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
2020-04-22 19:07:51 +05:30
const TEST_COMMIT_TEXT = '1 commit';
const TEST_CREATED_AT = '2018-10-23T11:49:16.611Z';
describe('CompareDropdownLayout', () => {
let wrapper;
const createVersion = ({ id, isHead, isBase, selected, commitsText, createdAt }) => ({
id,
href: `version/${id}`,
versionName: `version ${id}`,
isHead,
isBase,
short_commit_sha: `abcdef${id}`,
commitsText,
created_at: createdAt,
selected,
});
const createComponent = (propsData = {}) => {
2021-02-22 17:27:13 +05:30
wrapper = mount(CompareDropdownLayout, {
2020-04-22 19:07:51 +05:30
propsData: {
...propsData,
},
});
};
const findListItems = () => wrapper.findAll('li');
const findListItemsData = () =>
2021-03-08 18:12:59 +05:30
findListItems().wrappers.map((listItem) => ({
2020-04-22 19:07:51 +05:30
href: listItem.find('a').attributes('href'),
text: trimText(listItem.text()),
2022-10-11 01:57:18 +05:30
createdAt: listItem.findAllComponents(TimeAgo).wrappers[0]?.props('time'),
2021-02-22 17:27:13 +05:30
isActive: listItem.classes().includes('is-active'),
2020-04-22 19:07:51 +05:30
}));
describe('with versions', () => {
beforeEach(() => {
const versions = [
createVersion({
id: 1,
isHead: false,
isBase: true,
selected: true,
commitsText: TEST_COMMIT_TEXT,
createdAt: TEST_CREATED_AT,
}),
createVersion({ id: 2, isHead: true, isBase: false, selected: false }),
createVersion({ id: 3, isHead: false, isBase: false, selected: false }),
];
createComponent({ versions });
});
it('renders the selected version name', () => {
expect(wrapper.text()).toContain('version 1');
});
it('renders versions in order', () => {
expect(findListItemsData()).toEqual([
{
href: 'version/1',
2021-03-11 19:13:27 +05:30
text: 'version 1 (base) abcdef1 1 commit 1 year ago',
2020-04-22 19:07:51 +05:30
createdAt: TEST_CREATED_AT,
isActive: true,
},
{
href: 'version/2',
text: 'version 2 (HEAD) abcdef2',
createdAt: undefined,
isActive: false,
},
{
href: 'version/3',
text: 'version 3 abcdef3',
createdAt: undefined,
isActive: false,
},
]);
});
});
});