summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/projects_list/project_list_item_spec.js
blob: e3a8e36f36bc5fa73eb4033370465067ad6ae26f (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import Vue from 'vue';
import ProjectListItem from '~/vue_shared/components/projects_list/project_list_item.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

// TODO: move to shallow mount / vue test utils ??

loadJSONFixtures('projects.json');
const projects = getJSONFixture('projects.json');
const ownedProject = projects[0];
const selectedProject = projects[1];

const createComponent = (props, defaultComponent = ProjectListItem) => {
  const Component = Vue.extend(defaultComponent);

  return mountComponent(Component, props);
};

describe('ProjectListItem', () => {
  let vm;

  beforeEach(() => {
    // const pathname = '/dashboard/projects';
    // spyOn(window.location, 'pathname', 'get').and.returnValue(pathname);
    vm = createComponent({ project: selectedProject });
  });

  afterEach(() => {
    vm.$destroy();
  });

  // TODO: Possible BE changes needed for missing fields:
  // - Populate namespace with correct data:
  //  * no group set => should default to the user's name
  //  * subgroups??
  //  * pipeline-status
  //  * last_activity_at (api) != last_activity_date (haml)
  //  * open_merge_requests_count
  //  * open_issues_count
  //  * project visibility
  // - description field: should show the last commit as a description if available otherwise just the project description

  // TODO: additional cases
  // - project.archived?

  describe('data', () => {
    it('returns default data props', () => {
      const projectFields = [
        'id',
        'name',
        'description',
        'path',
        'path_with_namespace',
        'created_at',
        'tag_list',
        'star_count',
        'forks_count',
        'open_issues_count',
        'last_activity_at',
      ];
      projectFields.forEach(field => {
        expect(vm.project[field]).toBe(selectedProject[field]);
      });

      const namespaceFields = ['id', 'name', 'path', 'kind', 'full_path', 'parent_id'];
      namespaceFields.forEach(field => {
        expect(vm.project.namespace[field]).toBe(selectedProject.namespace[field]);
      });
    });
  });

  describe('template', () => {
    describe('User owns project', () => {
      beforeEach(() => {
        vm = createComponent({ project: ownedProject });
      });

      afterEach(() => {
        vm.$destroy();
      });

      it(`renders the owner name for the namespace`, () => {
        expect(vm.$el.querySelector('.namespace-name').innerText).toEqual(
          `${ownedProject.owner.name} /`,
        );
      });

      it(`renders the project name`, () => {
        expect(vm.$el.querySelector('.project-name').innerText).toEqual(`${ownedProject.name}`);
      });
    });

    describe('User does not own the project', () => {
      beforeEach(() => {
        vm = createComponent({ project: selectedProject });
      });

      afterEach(() => {
        vm.$destroy();
      });

      it(`renders the project name for the namespace`, () => {
        expect(vm.$el.querySelector('.namespace-name').innerText).toEqual(
          `${selectedProject.namespace.name} /`,
        );
      });

      it(`renders the project name`, () => {
        expect(vm.$el.querySelector('.project-name').innerText).toEqual(`${selectedProject.name}`);
      });
    });

    fdescribe('Viewing explore projects', () => {
      beforeEach(() => {
        vm = createComponent({ project: selectedProject, isExploreTab: true });
      });

      afterEach(() => {
        vm.$destroy();
      });

      it('does not render project access', () => {});
    });

    describe('Project meta', () => {
      it('renders the correct project name', () => {
        expect(vm.$el.querySelector('.project-name').innerText).toBe(selectedProject.name);
      });

      it('renders the project avatar as a link', () => {
        expect(vm.$el.querySelector('.avatar-container a').href).toContain(selectedProject.path);
      });

      it('renders the correct project description', () => {
        expect(vm.$el.querySelector('.description').innerText).toBe(selectedProject.description);
        expect(vm.$el.querySelector('.description').classList).not.toContain('no-description');
      });

      it('does not render the description if it is missing', () => {
        ['', null].forEach(description => {
          const noDescVm = createComponent({ project: { ...selectedProject, description } });

          expect(noDescVm.$el.querySelector('.description')).toBeNull();
          expect(noDescVm.$el.classList).toContain('no-description');
        });
      });
    });
  });
});