applications_spec.js 11.5 KB
Newer Older
1 2
import Vue from 'vue';
import applications from '~/clusters/components/applications.vue';
3
import { CLUSTER_TYPE } from '~/clusters/constants';
4
import mountComponent from 'helpers/vue_mount_component_helper';
5
import { APPLICATIONS_MOCK_STATE } from '../services/mock_data';
6 7 8
import eventHub from '~/clusters/event_hub';
import { shallowMount } from '@vue/test-utils';
import KnativeDomainEditor from '~/clusters/components/knative_domain_editor.vue';
9 10 11 12 13 14 15 16 17 18 19 20 21

describe('Applications', () => {
  let vm;
  let Applications;

  beforeEach(() => {
    Applications = Vue.extend(applications);
  });

  afterEach(() => {
    vm.$destroy();
  });

22
  describe('Project cluster applications', () => {
23 24
    beforeEach(() => {
      vm = mountComponent(Applications, {
25
        applications: APPLICATIONS_MOCK_STATE,
26
        type: CLUSTER_TYPE.PROJECT,
27 28 29 30
      });
    });

    it('renders a row for Helm Tiller', () => {
31
      expect(vm.$el.querySelector('.js-cluster-application-row-helm')).not.toBeNull();
32 33 34
    });

    it('renders a row for Ingress', () => {
35
      expect(vm.$el.querySelector('.js-cluster-application-row-ingress')).not.toBeNull();
36 37
    });

38
    it('renders a row for Cert-Manager', () => {
39
      expect(vm.$el.querySelector('.js-cluster-application-row-cert_manager')).not.toBeNull();
40 41
    });

42
    it('renders a row for Prometheus', () => {
43
      expect(vm.$el.querySelector('.js-cluster-application-row-prometheus')).not.toBeNull();
44 45
    });

46
    it('renders a row for GitLab Runner', () => {
47
      expect(vm.$el.querySelector('.js-cluster-application-row-runner')).not.toBeNull();
48
    });
49 50

    it('renders a row for Jupyter', () => {
51
      expect(vm.$el.querySelector('.js-cluster-application-row-jupyter')).not.toBeNull();
52
    });
Chris Baumbauer's avatar
Chris Baumbauer committed
53 54

    it('renders a row for Knative', () => {
55 56 57 58 59 60 61 62
      expect(vm.$el.querySelector('.js-cluster-application-row-knative')).not.toBeNull();
    });
  });

  describe('Group cluster applications', () => {
    beforeEach(() => {
      vm = mountComponent(Applications, {
        type: CLUSTER_TYPE.GROUP,
63
        applications: APPLICATIONS_MOCK_STATE,
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
      });
    });

    it('renders a row for Helm Tiller', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-helm')).not.toBeNull();
    });

    it('renders a row for Ingress', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-ingress')).not.toBeNull();
    });

    it('renders a row for Cert-Manager', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-cert_manager')).not.toBeNull();
    });

    it('renders a row for Prometheus', () => {
80
      expect(vm.$el.querySelector('.js-cluster-application-row-prometheus')).not.toBeNull();
81 82 83
    });

    it('renders a row for GitLab Runner', () => {
84
      expect(vm.$el.querySelector('.js-cluster-application-row-runner')).not.toBeNull();
85 86 87
    });

    it('renders a row for Jupyter', () => {
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
      expect(vm.$el.querySelector('.js-cluster-application-row-jupyter')).not.toBeNull();
    });

    it('renders a row for Knative', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-knative')).toBeNull();
    });
  });

  describe('Instance cluster applications', () => {
    beforeEach(() => {
      vm = mountComponent(Applications, {
        type: CLUSTER_TYPE.INSTANCE,
        applications: APPLICATIONS_MOCK_STATE,
      });
    });

    it('renders a row for Helm Tiller', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-helm')).not.toBeNull();
    });

    it('renders a row for Ingress', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-ingress')).not.toBeNull();
    });

    it('renders a row for Cert-Manager', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-cert_manager')).not.toBeNull();
    });

    it('renders a row for Prometheus', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-prometheus')).not.toBeNull();
    });

    it('renders a row for GitLab Runner', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-runner')).not.toBeNull();
    });

    it('renders a row for Jupyter', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-jupyter')).not.toBeNull();
126 127 128 129
    });

    it('renders a row for Knative', () => {
      expect(vm.$el.querySelector('.js-cluster-application-row-knative')).toBeNull();
Chris Baumbauer's avatar
Chris Baumbauer committed
130
    });
131
  });
132 133 134 135 136 137 138

  describe('Ingress application', () => {
    describe('when installed', () => {
      describe('with ip address', () => {
        it('renders ip address with a clipboard button', () => {
          vm = mountComponent(Applications, {
            applications: {
139
              ...APPLICATIONS_MOCK_STATE,
140 141 142
              ingress: {
                title: 'Ingress',
                status: 'installed',
143
                externalIp: '0.0.0.0',
144 145 146
              },
            },
          });
147

148
          expect(vm.$el.querySelector('.js-endpoint').value).toEqual('0.0.0.0');
149

150 151 152 153 154 155
          expect(
            vm.$el.querySelector('.js-clipboard-btn').getAttribute('data-clipboard-text'),
          ).toEqual('0.0.0.0');
        });
      });

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
      describe('with hostname', () => {
        it('renders hostname with a clipboard button', () => {
          vm = mountComponent(Applications, {
            applications: {
              ingress: {
                title: 'Ingress',
                status: 'installed',
                externalHostname: 'localhost.localdomain',
              },
              helm: { title: 'Helm Tiller' },
              cert_manager: { title: 'Cert-Manager' },
              runner: { title: 'GitLab Runner' },
              prometheus: { title: 'Prometheus' },
              jupyter: { title: 'JupyterHub', hostname: '' },
              knative: { title: 'Knative', hostname: '' },
            },
          });

          expect(vm.$el.querySelector('.js-endpoint').value).toEqual('localhost.localdomain');

          expect(
            vm.$el.querySelector('.js-clipboard-btn').getAttribute('data-clipboard-text'),
          ).toEqual('localhost.localdomain');
        });
      });

182
      describe('without ip address', () => {
183
        it('renders an input text with a loading icon and an alert text', () => {
184 185
          vm = mountComponent(Applications, {
            applications: {
186
              ...APPLICATIONS_MOCK_STATE,
187 188 189 190 191 192 193
              ingress: {
                title: 'Ingress',
                status: 'installed',
              },
            },
          });

194
          expect(vm.$el.querySelector('.js-ingress-ip-loading-icon')).not.toBe(null);
195
          expect(vm.$el.querySelector('.js-no-endpoint-message')).not.toBe(null);
196 197 198 199 200 201 202
        });
      });
    });

    describe('before installing', () => {
      it('does not render the IP address', () => {
        vm = mountComponent(Applications, {
203
          applications: APPLICATIONS_MOCK_STATE,
204 205 206
        });

        expect(vm.$el.textContent).not.toContain('Ingress IP Address');
207
        expect(vm.$el.querySelector('.js-endpoint')).toBe(null);
208 209
      });
    });
210

211 212 213 214 215
    describe('Cert-Manager application', () => {
      describe('when not installed', () => {
        it('renders email & allows editing', () => {
          vm = mountComponent(Applications, {
            applications: {
216
              ...APPLICATIONS_MOCK_STATE,
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
              cert_manager: {
                title: 'Cert-Manager',
                email: 'before@example.com',
                status: 'installable',
              },
            },
          });

          expect(vm.$el.querySelector('.js-email').value).toEqual('before@example.com');
          expect(vm.$el.querySelector('.js-email').getAttribute('readonly')).toBe(null);
        });
      });

      describe('when installed', () => {
        it('renders email in readonly', () => {
          vm = mountComponent(Applications, {
            applications: {
234
              ...APPLICATIONS_MOCK_STATE,
235 236 237 238 239 240 241 242 243 244 245 246 247 248
              cert_manager: {
                title: 'Cert-Manager',
                email: 'after@example.com',
                status: 'installed',
              },
            },
          });

          expect(vm.$el.querySelector('.js-email').value).toEqual('after@example.com');
          expect(vm.$el.querySelector('.js-email').getAttribute('readonly')).toEqual('readonly');
        });
      });
    });

249
    describe('Jupyter application', () => {
250
      describe('with ingress installed with ip & jupyter installable', () => {
251 252 253
        it('renders hostname active input', () => {
          vm = mountComponent(Applications, {
            applications: {
254 255 256 257 258 259
              ...APPLICATIONS_MOCK_STATE,
              ingress: {
                title: 'Ingress',
                status: 'installed',
                externalIp: '1.1.1.1',
              },
260 261 262 263 264
            },
          });

          expect(vm.$el.querySelector('.js-hostname').getAttribute('readonly')).toEqual(null);
        });
Filipa Lacerda's avatar
Filipa Lacerda committed
265
      });
266

Filipa Lacerda's avatar
Filipa Lacerda committed
267 268 269 270
      describe('with ingress installed without external ip', () => {
        it('does not render hostname input', () => {
          vm = mountComponent(Applications, {
            applications: {
271
              ...APPLICATIONS_MOCK_STATE,
Filipa Lacerda's avatar
Filipa Lacerda committed
272 273 274 275 276 277 278
              ingress: { title: 'Ingress', status: 'installed' },
            },
          });

          expect(vm.$el.querySelector('.js-hostname')).toBe(null);
        });
      });
279

Filipa Lacerda's avatar
Filipa Lacerda committed
280 281 282 283
      describe('with ingress & jupyter installed', () => {
        it('renders readonly input', () => {
          vm = mountComponent(Applications, {
            applications: {
284
              ...APPLICATIONS_MOCK_STATE,
Filipa Lacerda's avatar
Filipa Lacerda committed
285 286 287
              ingress: { title: 'Ingress', status: 'installed', externalIp: '1.1.1.1' },
              jupyter: { title: 'JupyterHub', status: 'installed', hostname: '' },
            },
288
          });
Filipa Lacerda's avatar
Filipa Lacerda committed
289 290

          expect(vm.$el.querySelector('.js-hostname').getAttribute('readonly')).toEqual('readonly');
291 292 293 294 295 296
        });
      });

      describe('without ingress installed', () => {
        beforeEach(() => {
          vm = mountComponent(Applications, {
297
            applications: APPLICATIONS_MOCK_STATE,
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
          });
        });

        it('does not render input', () => {
          expect(vm.$el.querySelector('.js-hostname')).toBe(null);
        });

        it('renders disabled install button', () => {
          expect(
            vm.$el
              .querySelector(
                '.js-cluster-application-row-jupyter .js-cluster-application-install-button',
              )
              .getAttribute('disabled'),
          ).toEqual('disabled');
        });
      });
    });
316
  });
317 318

  describe('Knative application', () => {
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    const propsData = {
      applications: {
        ...APPLICATIONS_MOCK_STATE,
        knative: {
          title: 'Knative',
          hostname: 'example.com',
          status: 'installed',
          externalIp: '1.1.1.1',
          installed: true,
        },
      },
    };
    const newHostname = 'newhostname.com';
    let wrapper;
    let knativeDomainEditor;
334

335 336 337
    beforeEach(() => {
      wrapper = shallowMount(Applications, { propsData });
      jest.spyOn(eventHub, '$emit');
338

339 340
      knativeDomainEditor = wrapper.find(KnativeDomainEditor);
    });
341

342 343 344
    afterEach(() => {
      wrapper.destroy();
    });
345

346 347
    it('emits saveKnativeDomain event when knative domain editor emits save event', () => {
      knativeDomainEditor.vm.$emit('save', newHostname);
348

349 350 351
      expect(eventHub.$emit).toHaveBeenCalledWith('saveKnativeDomain', {
        id: 'knative',
        params: { hostname: newHostname },
352
      });
353
    });
354

355 356
    it('emits setKnativeHostname event when knative domain editor emits change event', () => {
      wrapper.find(KnativeDomainEditor).vm.$emit('set', newHostname);
357

358 359 360
      expect(eventHub.$emit).toHaveBeenCalledWith('setKnativeHostname', {
        id: 'knative',
        hostname: newHostname,
361 362 363
      });
    });
  });
364
});