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

sidebar_store_spec.js « sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b73dc868b72f1002a186c552e60a1408e3ea18f (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import UsersMockHelper from 'helpers/user_mock_data_helper';
import SidebarStore from '~/sidebar/stores/sidebar_store';
import Mock from './mock_data';

const ASSIGNEE = {
  id: 2,
  name: 'gitlab user 2',
  username: 'gitlab2',
  avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
};

const ANOTHER_ASSINEE = {
  id: 3,
  name: 'gitlab user 3',
  username: 'gitlab3',
  avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
};

const PARTICIPANT = {
  id: 1,
  state: 'active',
  username: 'marcene',
  name: 'Allie Will',
  web_url: 'foo.com',
  avatar_url: 'gravatar.com/avatar/xxx',
};

const PARTICIPANT_LIST = [PARTICIPANT, { ...PARTICIPANT, id: 2 }, { ...PARTICIPANT, id: 3 }];

describe('Sidebar store', () => {
  let testContext;

  beforeEach(() => {
    testContext = {};
  });

  beforeEach(() => {
    testContext.store = new SidebarStore({
      currentUser: {
        id: 1,
        name: 'Administrator',
        username: 'root',
        avatar_url:
          'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
      },
      editable: true,
      rootPath: '/',
      endpoint: '/gitlab-org/gitlab-shell/issues/5.json',
    });
  });

  afterEach(() => {
    SidebarStore.singleton = null;
  });

  it('has default isFetching values', () => {
    expect(testContext.store.isFetching.assignees).toBe(true);
  });

  it('resets changing when resetChanging is called', () => {
    testContext.store.changing = true;

    testContext.store.resetChanging();

    expect(testContext.store.changing).toBe(false);
  });

  describe('when it adds a new assignee', () => {
    beforeEach(() => {
      testContext.store.addAssignee(ASSIGNEE);
    });

    it('adds a new assignee', () => {
      expect(testContext.store.assignees).toHaveLength(1);
    });

    it('sets changing to true', () => {
      expect(testContext.store.changing).toBe(true);
    });
  });

  describe('when it removes an assignee', () => {
    beforeEach(() => {
      testContext.store.removeAssignee(ASSIGNEE);
    });

    it('removes an assignee', () => {
      expect(testContext.store.assignees).toHaveLength(0);
    });

    it('sets changing to true', () => {
      expect(testContext.store.changing).toBe(true);
    });
  });

  it('finds an existent assignee', () => {
    let foundAssignee;

    testContext.store.addAssignee(ASSIGNEE);
    foundAssignee = testContext.store.findAssignee(ASSIGNEE);

    expect(foundAssignee).toBeDefined();
    expect(foundAssignee).toEqual(ASSIGNEE);
    foundAssignee = testContext.store.findAssignee(ANOTHER_ASSINEE);

    expect(foundAssignee).toBeUndefined();
  });

  it('removes all assignees', () => {
    testContext.store.removeAllAssignees();

    expect(testContext.store.assignees.length).toEqual(0);
    expect(testContext.store.changing).toBe(true);
  });

  it('sets participants data', () => {
    expect(testContext.store.participants.length).toEqual(0);

    testContext.store.setParticipantsData({
      participants: PARTICIPANT_LIST,
    });

    expect(testContext.store.isFetching.participants).toEqual(false);
    expect(testContext.store.participants.length).toEqual(PARTICIPANT_LIST.length);
  });

  it('sets subcriptions data', () => {
    expect(testContext.store.subscribed).toEqual(null);

    testContext.store.setSubscriptionsData({
      subscribed: true,
    });

    expect(testContext.store.isFetching.subscriptions).toEqual(false);
    expect(testContext.store.subscribed).toEqual(true);
  });

  it('set assigned data', () => {
    const users = {
      assignees: UsersMockHelper.createNumberRandomUsers(3),
    };

    testContext.store.setAssigneeData(users);

    expect(testContext.store.isFetching.assignees).toBe(false);
    expect(testContext.store.assignees.length).toEqual(3);
  });

  it('sets fetching state', () => {
    expect(testContext.store.isFetching.participants).toEqual(true);

    testContext.store.setFetchingState('participants', false);

    expect(testContext.store.isFetching.participants).toEqual(false);
  });

  it('sets loading state', () => {
    testContext.store.setLoadingState('assignees', true);

    expect(testContext.store.isLoading.assignees).toEqual(true);
  });

  it('set time tracking data', () => {
    testContext.store.setTimeTrackingData(Mock.time);

    expect(testContext.store.timeEstimate).toEqual(Mock.time.time_estimate);
    expect(testContext.store.totalTimeSpent).toEqual(Mock.time.total_time_spent);
    expect(testContext.store.humanTimeEstimate).toEqual(Mock.time.human_time_estimate);
    expect(testContext.store.humanTotalTimeSpent).toEqual(Mock.time.human_total_time_spent);
  });

  it('set autocomplete projects', () => {
    const projects = [{ id: 0 }];
    testContext.store.setAutocompleteProjects(projects);

    expect(testContext.store.autocompleteProjects).toEqual(projects);
  });

  it('sets subscribed state', () => {
    expect(testContext.store.subscribed).toEqual(null);

    testContext.store.setSubscribedState(true);

    expect(testContext.store.subscribed).toEqual(true);
  });

  it('set move to project ID', () => {
    const projectId = 7;
    testContext.store.setMoveToProjectId(projectId);

    expect(testContext.store.moveToProjectId).toEqual(projectId);
  });
});