Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-01 03:09:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-01 03:09:44 +0300
commit83e25d14371953c18ac41b3a0cc27aadefd9bc69 (patch)
tree69d4b7cc955c7a7c414baf4e60d53ad6f5647732 /spec/frontend
parent5376a0c41d6264e6cc820b5d12220ae4ff79f2ae (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/forks/component/forks_button_spec.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/frontend/forks/component/forks_button_spec.js b/spec/frontend/forks/component/forks_button_spec.js
new file mode 100644
index 00000000000..a743f015ef4
--- /dev/null
+++ b/spec/frontend/forks/component/forks_button_spec.js
@@ -0,0 +1,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);
+ },
+ );
+ });
+});