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

deprecated_type_keyword_notification_spec.js « notification « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f626652a94433718ee0a13b3073754f833cc0fff (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
import VueApollo from 'vue-apollo';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlAlert, GlSprintf } from '@gitlab/ui';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import DeprecatedTypeKeywordNotification from '~/pipelines/components/notification/deprecated_type_keyword_notification.vue';
import getPipelineWarnings from '~/pipelines/graphql/queries/get_pipeline_warnings.query.graphql';
import {
  mockWarningsWithoutDeprecation,
  mockWarningsRootType,
  mockWarningsType,
  mockWarningsTypesAll,
} from './mock_data';

const defaultProvide = {
  deprecatedKeywordsDocPath: '/help/ci/yaml/index.md#deprecated-keywords',
  fullPath: '/namespace/my-project',
  pipelineIid: 4,
};

let wrapper;

const mockWarnings = jest.fn();

const createComponent = ({ isLoading = false, options = {} } = {}) => {
  return shallowMount(DeprecatedTypeKeywordNotification, {
    stubs: {
      GlSprintf,
    },
    provide: {
      ...defaultProvide,
    },
    mocks: {
      $apollo: {
        queries: {
          warnings: {
            loading: isLoading,
          },
        },
      },
    },
    ...options,
  });
};

const createComponentWithApollo = () => {
  const localVue = createLocalVue();
  localVue.use(VueApollo);

  const handlers = [[getPipelineWarnings, mockWarnings]];
  const mockApollo = createMockApollo(handlers);

  return createComponent({
    options: {
      localVue,
      apolloProvider: mockApollo,
      mocks: {},
    },
  });
};

const findAlert = () => wrapper.findComponent(GlAlert);
const findAlertItems = () => findAlert().findAll('li');

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

describe('Deprecated keyword notification', () => {
  describe('while loading the pipeline warnings', () => {
    beforeEach(() => {
      wrapper = createComponent({ isLoading: true });
    });

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

  describe('if there is an error in the query', () => {
    beforeEach(async () => {
      mockWarnings.mockResolvedValue({ errors: ['It didnt work'] });
      wrapper = createComponentWithApollo();
      await waitForPromises();
    });

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

  describe('with a valid query result', () => {
    describe('if there are no deprecation warnings', () => {
      beforeEach(async () => {
        mockWarnings.mockResolvedValue(mockWarningsWithoutDeprecation);
        wrapper = createComponentWithApollo();
        await waitForPromises();
      });
      it('does not show the notification', () => {
        expect(findAlert().exists()).toBe(false);
      });
    });

    describe('with a root type deprecation message', () => {
      beforeEach(async () => {
        mockWarnings.mockResolvedValue(mockWarningsRootType);
        wrapper = createComponentWithApollo();
        await waitForPromises();
      });
      it('shows the notification with one item', () => {
        expect(findAlert().exists()).toBe(true);
        expect(findAlertItems()).toHaveLength(1);
        expect(findAlertItems().at(0).text()).toContain('types');
      });
    });

    describe('with a job type deprecation message', () => {
      beforeEach(async () => {
        mockWarnings.mockResolvedValue(mockWarningsType);
        wrapper = createComponentWithApollo();
        await waitForPromises();
      });
      it('shows the notification with one item', () => {
        expect(findAlert().exists()).toBe(true);
        expect(findAlertItems()).toHaveLength(1);
        expect(findAlertItems().at(0).text()).toContain('type');
        expect(findAlertItems().at(0).text()).not.toContain('types');
      });
    });

    describe('with both the root types and job type deprecation message', () => {
      beforeEach(async () => {
        mockWarnings.mockResolvedValue(mockWarningsTypesAll);
        wrapper = createComponentWithApollo();
        await waitForPromises();
      });
      it('shows the notification with two items', () => {
        expect(findAlert().exists()).toBe(true);
        expect(findAlertItems()).toHaveLength(2);
        expect(findAlertItems().at(0).text()).toContain('types');
        expect(findAlertItems().at(1).text()).toContain('type');
        expect(findAlertItems().at(1).text()).not.toContain('types');
      });
    });
  });
});