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>2020-02-07 21:09:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 21:09:03 +0300
commitd7ce7307dca551759ffa972015875f8ebe476927 (patch)
tree7cb8c211b737de7120dd2f1e825852e77ac5d380 /spec/frontend/vue_shared
parente43077ab4742ba5083a01a1e5341db1a1b7a1701 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared')
-rw-r--r--spec/frontend/vue_shared/components/file_tree_spec.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/file_tree_spec.js b/spec/frontend/vue_shared/components/file_tree_spec.js
new file mode 100644
index 00000000000..38979d9d844
--- /dev/null
+++ b/spec/frontend/vue_shared/components/file_tree_spec.js
@@ -0,0 +1,88 @@
+import { pick } from 'lodash';
+import { shallowMount } from '@vue/test-utils';
+import FileTree from '~/vue_shared/components/file_tree.vue';
+
+const MockFileRow = {
+ name: 'MockFileRow',
+ render() {
+ return this.$slots.default;
+ },
+};
+
+const TEST_LEVEL = 4;
+const TEST_EXTA_ARGS = {
+ foo: 'lorem-ipsum',
+ bar: 'zoo',
+};
+
+describe('File Tree component', () => {
+ let wrapper;
+
+ const createComponent = (props = {}) => {
+ wrapper = shallowMount(FileTree, {
+ propsData: { level: TEST_LEVEL, fileRowComponent: MockFileRow, ...props },
+ attrs: { ...TEST_EXTA_ARGS },
+ });
+ };
+
+ const findFileRow = () => wrapper.find(MockFileRow);
+ const findChildrenTrees = () => wrapper.findAll(FileTree).wrappers.slice(1);
+ const findChildrenTreeProps = () =>
+ findChildrenTrees().map(x => ({
+ ...x.props(),
+ ...pick(x.attributes(), Object.keys(TEST_EXTA_ARGS)),
+ }));
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ describe('file row component', () => {
+ beforeEach(() => {
+ createComponent({ file: {} });
+ });
+
+ it('renders file row component', () => {
+ expect(findFileRow().exists()).toEqual(true);
+ });
+
+ it('contains the required attribute keys', () => {
+ const fileRow = findFileRow();
+
+ // Checking strings b/c value in attributes are always strings
+ expect(fileRow.attributes()).toEqual({
+ file: {}.toString(),
+ level: TEST_LEVEL.toString(),
+ ...TEST_EXTA_ARGS,
+ });
+ });
+ });
+
+ describe('file tree', () => {
+ const createChildren = () => [{ id: 1 }, { id: 2 }];
+ const createChildrenExpectation = (props = {}) =>
+ createChildren().map(file => ({
+ fileRowComponent: MockFileRow,
+ file,
+ ...TEST_EXTA_ARGS,
+ ...props,
+ }));
+
+ it.each`
+ key | value | desc | expectedChildren
+ ${'isHeader'} | ${true} | ${'is shown if file is header'} | ${createChildrenExpectation({ level: 0 })}
+ ${'opened'} | ${true} | ${'is shown if file is open'} | ${createChildrenExpectation({ level: TEST_LEVEL + 1 })}
+ ${'isHeader'} | ${false} | ${'is hidden if file is header'} | ${[]}
+ ${'opened'} | ${false} | ${'is hidden if file is open'} | ${[]}
+ `('$desc', ({ key, value, expectedChildren }) => {
+ createComponent({
+ file: {
+ [key]: value,
+ tree: createChildren(),
+ },
+ });
+
+ expect(findChildrenTreeProps()).toEqual(expectedChildren);
+ });
+ });
+});