summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/project_item_spec.js
blob: a55031355c65f655f03d69019669521467178211 (plain)
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
import Vue from 'vue';
import projectItemComponent from '~/groups/components/project_item.vue';
import GroupsStore from '~/groups/stores/groups_store';
import { group1 } from './mock_data';

const createComponent = () => {
  const Component = Vue.extend(projectItemComponent);
  const store = new GroupsStore();
  const group = store.decorateGroup(group1);
  const project = group.projects[0];

  return new Component({
    propsData: {
      project,
    },
  }).$mount();
};

describe('ProjectItemComponent', () => {
  const project = group1.projects[0];
  let vm;

  beforeEach(() => {
    vm = createComponent();
  });

  describe('computed', () => {
    describe('projectDomId', () => {
      it('should return ID string using Project ID', () => {
        expect(vm.projectDomId).toBe(`project-${project.id}`);
      });
    });

    describe('rowClass', () => {
      it('should return appropriate classes present in row element classes for project', () => {
        expect(vm.rowClass['no-description']).toBeFalsy(); // Since group1.projects[0].description is defined
      });
    });

    describe('visibilityIcon', () => {
      it('should return correct classes for different project visibility types', () => {
        vm.project.visibility = 'public';
        expect(vm.visibilityIcon).toBe('fa-globe');

        vm.project.visibility = 'internal';
        expect(vm.visibilityIcon).toBeTruthy('fa-shield');

        vm.project.visibility = 'private';
        expect(vm.visibilityIcon).toBeTruthy('fa-lock');
      });
    });

    describe('visibilityTooltip', () => {
      it('should return capitalized visibility type in tooltip string', () => {
        vm.project.visibility = 'public';
        expect(vm.visibilityTooltip).toContain('Public');
      });
    });
  });

  describe('template', () => {
    it('should render project row element correctly', () => {
      expect(vm.$el.querySelector('#project-17')).toBeDefined();
      expect(vm.$el.querySelector('#project-17 .folder-toggle-wrap .folder-icon fa.fa-bookmark')).toBeDefined();
      expect(vm.$el.querySelector('#project-17 .metadata .title a').getAttribute('href')).toBe(project.project_path);
      expect(vm.$el.querySelector('#project-17 .metadata .description').textContent.trim()).toBe(project.description);
      expect(vm.$el.querySelector('#project-17 .stats .project-stars').textContent.trim()).toBe(`${project.star_count}`);
      expect(vm.$el.querySelector('#project-17 .stats .project-visibility').dataset.originalTitle).toContain('Public');
    });
  });
});