summaryrefslogtreecommitdiff
path: root/spec/frontend/import_entities/components/import_status_spec.js
blob: 56c4ed827d74bda309dcaba950142f4805198a07 (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
import { GlAccordionItem, GlBadge, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ImportStatus from '~/import_entities/components/import_status.vue';
import { STATUSES } from '~/import_entities/constants';

describe('Import entities status component', () => {
  let wrapper;

  const createComponent = (propsData) => {
    wrapper = shallowMount(ImportStatus, {
      propsData,
    });
  };

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

  describe('success status', () => {
    const getStatusText = () => wrapper.findComponent(GlBadge).text();
    const getStatusIcon = () => wrapper.findComponent(GlBadge).props('icon');

    it('displays finished status as complete when no stats are provided', () => {
      createComponent({
        status: STATUSES.FINISHED,
      });
      expect(getStatusText()).toBe('Complete');
    });

    it('displays finished status as complete when all stats items were processed', () => {
      const statItems = { label: 100, note: 200 };

      createComponent({
        status: STATUSES.FINISHED,
        stats: {
          fetched: { ...statItems },
          imported: { ...statItems },
        },
      });

      expect(getStatusText()).toBe('Complete');
      expect(getStatusIcon()).toBe('status-success');
    });

    it('displays finished status as partial when all stats items were processed', () => {
      const statItems = { label: 100, note: 200 };

      createComponent({
        status: STATUSES.FINISHED,
        stats: {
          fetched: { ...statItems },
          imported: { ...statItems, label: 50 },
        },
      });

      expect(getStatusText()).toBe('Partial import');
      expect(getStatusIcon()).toBe('status-alert');
    });
  });

  describe('details drawer', () => {
    const findDetailsDrawer = () => wrapper.findComponent(GlAccordionItem);

    it('renders details drawer to be present when stats are provided', () => {
      createComponent({
        status: 'created',
        stats: { fetched: { label: 1 }, imported: { label: 0 } },
      });

      expect(findDetailsDrawer().exists()).toBe(true);
    });

    it('does not render details drawer when no stats are provided', () => {
      createComponent({
        status: 'created',
      });

      expect(findDetailsDrawer().exists()).toBe(false);
    });

    it('does not render details drawer when stats are empty', () => {
      createComponent({
        status: 'created',
        stats: { fetched: {}, imported: {} },
      });

      expect(findDetailsDrawer().exists()).toBe(false);
    });

    it('does not render details drawer when no known stats are provided', () => {
      createComponent({
        status: 'created',
        stats: {
          fetched: {
            UNKNOWN_STAT: 100,
          },
          imported: {
            UNKNOWN_STAT: 0,
          },
        },
      });

      expect(findDetailsDrawer().exists()).toBe(false);
    });
  });

  describe('stats display', () => {
    const getStatusIcon = () =>
      wrapper.findComponent(GlAccordionItem).findComponent(GlIcon).props().name;

    const createComponentWithStats = ({ fetched, imported, status = 'created' }) => {
      createComponent({
        status,
        stats: {
          fetched: { label: fetched },
          imported: { label: imported },
        },
      });
    };

    it('displays scheduled status when imported is 0', () => {
      createComponentWithStats({
        fetched: 100,
        imported: 0,
      });

      expect(getStatusIcon()).toBe('status-scheduled');
    });

    it('displays running status when imported is not equal to fetched and import is not finished', () => {
      createComponentWithStats({
        fetched: 100,
        imported: 10,
      });

      expect(getStatusIcon()).toBe('status-running');
    });

    it('displays alert status when imported is not equal to fetched and import is finished', () => {
      createComponentWithStats({
        fetched: 100,
        imported: 10,
        status: STATUSES.FINISHED,
      });

      expect(getStatusIcon()).toBe('status-alert');
    });

    it('displays success status when imported is equal to fetched', () => {
      createComponentWithStats({
        fetched: 100,
        imported: 100,
      });

      expect(getStatusIcon()).toBe('status-success');
    });
  });
});