1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
import ForksButton from '~/forks/components/forks_button.vue';
describe('ForksButton', () => {
let wrapper;
const findForkButton = () => wrapper.findByTestId('fork-button');
const findForksCountButton = () => wrapper.findByTestId('forks-count');
const mountComponent = ({ injections } = {}) => {
wrapper = mountExtended(ForksButton, {
provide: {
forksCount: 10,
projectForksUrl: '/project/forks',
userForkUrl: '/user/fork',
newForkUrl: '/new/fork',
canReadCode: true,
canCreateFork: true,
canForkProject: true,
...injections,
},
});
};
describe('forks count button', () => {
it('renders the correct number of forks', () => {
mountComponent();
expect(findForksCountButton().text()).toBe('10');
});
it('is disabled when the user cannot read code', () => {
mountComponent({ injections: { canReadCode: false } });
expect(findForksCountButton().props('disabled')).toBe(true);
});
it('is enabled when the user can read code and has the correct link', () => {
mountComponent();
expect(findForksCountButton().props('disabled')).toBe(false);
expect(findForksCountButton().attributes('href')).toBe('/project/forks');
});
});
describe('fork button', () => {
const userForkUrlPath = '/user/fork';
const newForkPath = '/new/fork';
const goToYourForkTitle = 'Go to your fork';
const createNewForkTitle = 'Create new fork';
const reachedLimitTitle = 'You have reached your project limit';
const noPermissionsTitle = "You don't have permission to fork this project";
it.each`
userForkUrl | canReadCode | canCreateFork | canForkProject | isDisabled | title | href
${userForkUrlPath} | ${true} | ${true} | ${true} | ${false} | ${goToYourForkTitle} | ${userForkUrlPath}
${userForkUrlPath} | ${false} | ${true} | ${true} | ${true} | ${createNewForkTitle} | ${userForkUrlPath}
${null} | ${true} | ${true} | ${true} | ${false} | ${createNewForkTitle} | ${newForkPath}
${null} | ${false} | ${true} | ${true} | ${true} | ${createNewForkTitle} | ${newForkPath}
${null} | ${true} | ${false} | ${true} | ${true} | ${reachedLimitTitle} | ${newForkPath}
${null} | ${true} | ${true} | ${false} | ${true} | ${noPermissionsTitle} | ${newForkPath}
`(
'has the right enabled state, title, and link',
({ userForkUrl, canReadCode, canCreateFork, canForkProject, isDisabled, title, href }) => {
mountComponent({ injections: { userForkUrl, canReadCode, canCreateFork, canForkProject } });
expect(findForkButton().props('disabled')).toBe(isDisabled);
expect(findForkButton().attributes('title')).toBe(title);
expect(findForkButton().attributes('href')).toBe(href);
},
);
});
});
|