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

projects_list_spec.js « components « super_sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 93a414e1e8c27ac1be6765d98b11483d01c597f5 (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
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { s__ } from '~/locale';
import ProjectsList from '~/super_sidebar/components/projects_list.vue';
import SearchResults from '~/super_sidebar/components/search_results.vue';
import FrequentItemsList from '~/super_sidebar/components/frequent_items_list.vue';
import NavItem from '~/super_sidebar/components/nav_item.vue';
import { MAX_FREQUENT_PROJECTS_COUNT } from '~/super_sidebar/constants';

const username = 'root';
const viewAllLink = '/path/to/projects';
const storageKey = `${username}/frequent-projects`;

describe('ProjectsList component', () => {
  let wrapper;

  const findSearchResults = () => wrapper.findComponent(SearchResults);
  const findFrequentItemsList = () => wrapper.findComponent(FrequentItemsList);
  const findViewAllLink = () => wrapper.findComponent(NavItem);

  const itRendersViewAllItem = () => {
    it('renders the "View all..." item', () => {
      const link = findViewAllLink();

      expect(link.props('item')).toEqual({
        icon: 'project',
        link: viewAllLink,
        title: s__('Navigation|View all your projects'),
      });
      expect(link.props('linkClasses')).toEqual({ 'dashboard-shortcuts-projects': true });
    });
  };

  const createWrapper = (props = {}) => {
    wrapper = shallowMountExtended(ProjectsList, {
      propsData: {
        username,
        viewAllLink,
        ...props,
      },
    });
  };

  describe('when displaying search results', () => {
    const searchResults = ['A search result'];

    beforeEach(() => {
      createWrapper({
        isSearch: true,
        searchResults,
      });
    });

    it('renders the search results component', () => {
      expect(findSearchResults().exists()).toBe(true);
      expect(findFrequentItemsList().exists()).toBe(false);
    });

    it('passes the correct props to the search results component', () => {
      expect(findSearchResults().props()).toEqual({
        title: s__('Navigation|Projects'),
        noResultsText: s__('Navigation|No project matches found'),
        searchResults,
      });
    });

    itRendersViewAllItem();
  });

  describe('when displaying frequent projects', () => {
    beforeEach(() => {
      createWrapper();
    });

    it('passes the correct props to the frequent items list', () => {
      expect(findFrequentItemsList().props()).toEqual({
        title: s__('Navigation|Frequently visited projects'),
        storageKey,
        maxItems: MAX_FREQUENT_PROJECTS_COUNT,
        pristineText: s__('Navigation|Projects you visit often will appear here.'),
      });
    });

    itRendersViewAllItem();
  });
});