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

searchable_list_spec.js « components « model_registry « ml « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ea58a9a830abe6c6f95d6725c9d632563f420d9f (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
import { GlAlert } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import SearchableList from '~/ml/model_registry/components/searchable_list.vue';
import PackagesListLoader from '~/packages_and_registries/shared/components/packages_list_loader.vue';
import RegistryList from '~/packages_and_registries/shared/components/registry_list.vue';
import { defaultPageInfo } from '../mock_data';

describe('ml/model_registry/components/searchable_list.vue', () => {
  let wrapper;

  const findAlert = () => wrapper.findComponent(GlAlert);
  const findLoader = () => wrapper.findComponent(PackagesListLoader);
  const findRegistryList = () => wrapper.findComponent(RegistryList);
  const findEmptyState = () => wrapper.findByTestId('empty-state-slot');
  const findFirstRow = () => wrapper.findByTestId('element');
  const findRows = () => wrapper.findAllByTestId('element');

  const defaultProps = {
    items: ['a', 'b', 'c'],
    pageInfo: defaultPageInfo,
    isLoading: false,
    errorMessage: '',
  };

  const mountComponent = (props = {}) => {
    wrapper = shallowMountExtended(SearchableList, {
      propsData: {
        ...defaultProps,
        ...props,
      },
      stubs: {
        RegistryList,
      },
      slots: {
        'empty-state': '<div data-testid="empty-state-slot">This is empty</div>',
        item: '<div data-testid="element"></div>',
      },
    });
  };

  describe('when list is loaded and has no data', () => {
    beforeEach(() => mountComponent({ items: [] }));

    it('shows empty state', () => {
      expect(findEmptyState().text()).toBe('This is empty');
    });

    it('does not display loader', () => {
      expect(findLoader().exists()).toBe(false);
    });

    it('does not display rows', () => {
      expect(findFirstRow().exists()).toBe(false);
    });

    it('does not display registry list', () => {
      expect(findRegistryList().exists()).toBe(false);
    });

    it('does not display alert', () => {
      expect(findAlert().exists()).toBe(false);
    });
  });

  describe('if errorMessage', () => {
    beforeEach(() => mountComponent({ errorMessage: 'Failure!' }));

    it('shows error message', () => {
      expect(findAlert().text()).toContain('Failure!');
    });

    it('is not dismissible', () => {
      expect(findAlert().props('dismissible')).toBe(false);
    });

    it('is of variant danger', () => {
      expect(findAlert().attributes('variant')).toBe('danger');
    });

    it('hides loader', () => {
      expect(findLoader().exists()).toBe(false);
    });

    it('hides registry list', () => {
      expect(findRegistryList().exists()).toBe(false);
    });

    it('hides empty state', () => {
      expect(findEmptyState().exists()).toBe(false);
    });
  });

  describe('if loading', () => {
    beforeEach(() => mountComponent({ isLoading: true }));

    it('shows loader', () => {
      expect(findLoader().exists()).toBe(true);
    });

    it('hides error message', () => {
      expect(findAlert().exists()).toBe(false);
    });

    it('hides registry list', () => {
      expect(findRegistryList().exists()).toBe(false);
    });

    it('hides empty state', () => {
      expect(findEmptyState().exists()).toBe(false);
    });
  });

  describe('when list is loaded with data', () => {
    beforeEach(() => mountComponent());

    it('displays package registry list', () => {
      expect(findRegistryList().exists()).toEqual(true);
    });

    it('binds the right props', () => {
      expect(findRegistryList().props()).toMatchObject({
        items: ['a', 'b', 'c'],
        isLoading: false,
        pagination: defaultPageInfo,
        hiddenDelete: true,
      });
    });

    it('displays package version rows', () => {
      expect(findRows().exists()).toEqual(true);
      expect(findRows()).toHaveLength(3);
    });

    it('does not display loader', () => {
      expect(findLoader().exists()).toBe(false);
    });

    it('does not display empty state', () => {
      expect(findEmptyState().exists()).toBe(false);
    });
  });

  describe('when user interacts with pagination', () => {
    beforeEach(() => mountComponent());

    it('when list emits next-page emits fetchPage with correct pageInfo', () => {
      findRegistryList().vm.$emit('next-page');

      const expectedNewPageInfo = {
        after: 'eyJpZCI6IjIifQ',
        first: 30,
        last: null,
      };

      expect(wrapper.emitted('fetch-page')).toEqual([[expectedNewPageInfo]]);
    });

    it('when list emits prev-page emits fetchPage with correct pageInfo', () => {
      findRegistryList().vm.$emit('prev-page');

      const expectedNewPageInfo = {
        before: 'eyJpZCI6IjE2In0',
        first: null,
        last: 30,
      };

      expect(wrapper.emitted('fetch-page')).toEqual([[expectedNewPageInfo]]);
    });
  });
});