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:
Diffstat (limited to 'spec/frontend/diffs/components/collapsed_files_warning_spec.js')
-rw-r--r--spec/frontend/diffs/components/collapsed_files_warning_spec.js93
1 files changed, 59 insertions, 34 deletions
diff --git a/spec/frontend/diffs/components/collapsed_files_warning_spec.js b/spec/frontend/diffs/components/collapsed_files_warning_spec.js
index 77c2e19cb68..46caeb01132 100644
--- a/spec/frontend/diffs/components/collapsed_files_warning_spec.js
+++ b/spec/frontend/diffs/components/collapsed_files_warning_spec.js
@@ -1,10 +1,13 @@
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
+import { nextTick } from 'vue';
import Vuex from 'vuex';
import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue';
import { CENTERED_LIMITED_CONTAINER_CLASSES, EVT_EXPAND_ALL_FILES } from '~/diffs/constants';
import eventHub from '~/diffs/event_hub';
import createStore from '~/diffs/store/modules';
+import file from '../mock_data/diff_file';
+
const propsData = {
limited: true,
mergeable: true,
@@ -12,6 +15,13 @@ const propsData = {
};
const limitedClasses = CENTERED_LIMITED_CONTAINER_CLASSES.split(' ');
+async function files(store, count) {
+ const copies = Array(count).fill(file);
+ store.state.diffs.diffFiles.push(...copies);
+
+ return nextTick();
+}
+
describe('CollapsedFilesWarning', () => {
const localVue = createLocalVue();
let store;
@@ -42,48 +52,63 @@ describe('CollapsedFilesWarning', () => {
wrapper.destroy();
});
- it.each`
- limited | containerClasses
- ${true} | ${limitedClasses}
- ${false} | ${[]}
- `(
- 'has the correct container classes when limited is $limited',
- ({ limited, containerClasses }) => {
- createComponent({ limited });
-
- expect(wrapper.classes()).toEqual(['col-12'].concat(containerClasses));
- },
- );
-
- it.each`
- present | dismissed
- ${false} | ${true}
- ${true} | ${false}
- `('toggles the alert when dismissed is $dismissed', ({ present, dismissed }) => {
- createComponent({ dismissed });
-
- expect(wrapper.find('[data-testid="root"]').exists()).toBe(present);
- });
+ describe('when there is more than one file', () => {
+ it.each`
+ limited | containerClasses
+ ${true} | ${limitedClasses}
+ ${false} | ${[]}
+ `(
+ 'has the correct container classes when limited is $limited',
+ async ({ limited, containerClasses }) => {
+ createComponent({ limited });
+ await files(store, 2);
+
+ expect(wrapper.classes()).toEqual(['col-12'].concat(containerClasses));
+ },
+ );
- it('dismisses the component when the alert "x" is clicked', async () => {
- createComponent({}, { full: true });
+ it.each`
+ present | dismissed
+ ${false} | ${true}
+ ${true} | ${false}
+ `('toggles the alert when dismissed is $dismissed', async ({ present, dismissed }) => {
+ createComponent({ dismissed });
+ await files(store, 2);
- expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(present);
+ });
- getAlertCloseButton().element.click();
+ it('dismisses the component when the alert "x" is clicked', async () => {
+ createComponent({}, { full: true });
+ await files(store, 2);
- await wrapper.vm.$nextTick();
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
- expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
- });
+ getAlertCloseButton().element.click();
- it(`emits the \`${EVT_EXPAND_ALL_FILES}\` event when the alert action button is clicked`, () => {
- createComponent({}, { full: true });
+ await wrapper.vm.$nextTick();
- jest.spyOn(eventHub, '$emit');
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
+ });
- getAlertActionButton().vm.$emit('click');
+ it(`emits the \`${EVT_EXPAND_ALL_FILES}\` event when the alert action button is clicked`, async () => {
+ createComponent({}, { full: true });
+ await files(store, 2);
- expect(eventHub.$emit).toHaveBeenCalledWith(EVT_EXPAND_ALL_FILES);
+ jest.spyOn(eventHub, '$emit');
+
+ getAlertActionButton().vm.$emit('click');
+
+ expect(eventHub.$emit).toHaveBeenCalledWith(EVT_EXPAND_ALL_FILES);
+ });
+ });
+
+ describe('when there is a single file', () => {
+ it('should not display', async () => {
+ createComponent();
+ await files(store, 1);
+
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
+ });
});
});