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

user_lists_table_spec.js « components « feature_flags « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6ced3be16893e1e275fe2b3052976455960f2f0 (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
import { mount } from '@vue/test-utils';
import * as timeago from 'timeago.js';
import { GlModal } from '@gitlab/ui';
import UserListsTable from '~/feature_flags/components/user_lists_table.vue';
import { userList } from '../mock_data';

jest.mock('timeago.js', () => ({
  format: jest.fn().mockReturnValue('2 weeks ago'),
  register: jest.fn(),
}));

describe('User Lists Table', () => {
  let wrapper;
  let userLists;

  beforeEach(() => {
    userLists = new Array(5).fill(userList).map((x, i) => ({ ...x, id: i }));
    wrapper = mount(UserListsTable, {
      propsData: { userLists },
    });
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('should display the details of a user list', () => {
    expect(wrapper.find('[data-testid="ffUserListName"]').text()).toBe(userList.name);
    expect(wrapper.find('[data-testid="ffUserListIds"]').text()).toBe(
      userList.user_xids.replace(/,/g, ', '),
    );
    expect(wrapper.find('[data-testid="ffUserListTimestamp"]').text()).toBe('created 2 weeks ago');
    expect(timeago.format).toHaveBeenCalledWith(userList.created_at);
  });

  it('should set the title for a tooltip on the created stamp', () => {
    expect(wrapper.find('[data-testid="ffUserListTimestamp"]').attributes('title')).toBe(
      'Feb 4, 2020 8:13am GMT+0000',
    );
  });

  it('should display a user list entry per user list', () => {
    const lists = wrapper.findAll('[data-testid="ffUserList"]');
    expect(lists).toHaveLength(5);
    lists.wrappers.forEach(list => {
      expect(list.find('[data-testid="ffUserListName"]').exists()).toBe(true);
      expect(list.find('[data-testid="ffUserListIds"]').exists()).toBe(true);
      expect(list.find('[data-testid="ffUserListTimestamp"]').exists()).toBe(true);
    });
  });

  describe('edit button', () => {
    it('should link to the path for the user list', () => {
      expect(wrapper.find('[data-testid="edit-user-list"]').attributes('href')).toBe(userList.path);
    });
  });

  describe('delete button', () => {
    it('should display the confirmation modal', () => {
      const modal = wrapper.find(GlModal);

      wrapper.find('[data-testid="delete-user-list"]').trigger('click');

      return wrapper.vm.$nextTick().then(() => {
        expect(modal.text()).toContain(`Delete ${userList.name}?`);
        expect(modal.text()).toContain(`User list ${userList.name} will be removed.`);
      });
    });
  });

  describe('confirmation modal', () => {
    let modal;

    beforeEach(() => {
      modal = wrapper.find(GlModal);

      wrapper.find('button').trigger('click');

      return wrapper.vm.$nextTick();
    });

    it('should emit delete with list on confirmation', () => {
      modal.find('[data-testid="modal-confirm"]').trigger('click');

      return wrapper.vm.$nextTick().then(() => {
        expect(wrapper.emitted('delete')).toEqual([[userLists[0]]]);
      });
    });

    it('should not emit delete with list when not confirmed', () => {
      modal.find('button').trigger('click');

      return wrapper.vm.$nextTick().then(() => {
        expect(wrapper.emitted('delete')).toBeUndefined();
      });
    });
  });
});