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

search_list_spec.js « branches « components « ide « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 72a3c2d5dcdf501b8e8d7eac3c30b0769f505875 (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
import Vue from 'vue';
import store from '~/ide/stores';
import * as types from '~/ide/stores/modules/branches/mutation_types';
import List from '~/ide/components/branches/search_list.vue';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { branches as testBranches } from '../../mock_data';
import { resetStore } from '../../helpers';

describe('IDE branches search list', () => {
  const Component = Vue.extend(List);
  let vm;

  beforeEach(() => {
    vm = createComponentWithStore(Component, store, {});

    spyOn(vm, 'fetchBranches');

    vm.$mount();
  });

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

    resetStore(store);
  });

  it('calls fetch on mounted', () => {
    expect(vm.fetchBranches).toHaveBeenCalledWith({
      search: '',
    });
  });

  it('renders loading icon', done => {
    vm.$store.state.branches.isLoading = true;

    vm.$nextTick()
      .then(() => {
        expect(vm.$el).toContainElement('.loading-container');
      })
      .then(done)
      .catch(done.fail);
  });

  it('renders branches not found when search is not empty', done => {
    vm.search = 'testing';

    vm.$nextTick(() => {
      expect(vm.$el).toContainText('No branches found');

      done();
    });
  });

  describe('with branches', () => {
    const currentBranch = testBranches[1];

    beforeEach(done => {
      vm.$store.state.currentBranchId = currentBranch.name;
      vm.$store.commit(`branches/${types.RECEIVE_BRANCHES_SUCCESS}`, testBranches);

      vm.$nextTick(done);
    });

    it('renders list', () => {
      const elementText = Array.from(vm.$el.querySelectorAll('li strong')).map(x =>
        x.textContent.trim(),
      );

      expect(elementText).toEqual(testBranches.map(x => x.name));
    });

    it('renders check next to active branch', () => {
      const checkedText = Array.from(vm.$el.querySelectorAll('li'))
        .filter(x => x.querySelector('.ide-search-list-current-icon svg'))
        .map(x => x.querySelector('strong').textContent.trim());

      expect(checkedText).toEqual([currentBranch.name]);
    });
  });
});