environment_actions_spec.js.es6 1.7 KB
Newer Older
1
require('../spec_helper');
2 3
require('vue');
require('environments/components/environment_actions');
F
Filipa Lacerda 已提交
4 5

describe('Actions Component', () => {
6
  preloadFixtures('static/environments/element.html.raw');
F
Filipa Lacerda 已提交
7 8

  beforeEach(() => {
9
    loadFixtures('static/environments/element.html.raw');
F
Filipa Lacerda 已提交
10 11
  });

F
Filipa Lacerda 已提交
12
  it('should render a dropdown with the provided actions', () => {
F
Filipa Lacerda 已提交
13 14 15
    const actionsMock = [
      {
        name: 'bar',
F
Filipa Lacerda 已提交
16
        play_path: 'https://gitlab.com/play',
F
Filipa Lacerda 已提交
17 18 19
      },
      {
        name: 'foo',
F
Filipa Lacerda 已提交
20
        play_path: '#',
F
Filipa Lacerda 已提交
21 22 23 24 25 26 27
      },
    ];

    const component = new window.gl.environmentsList.ActionsComponent({
      el: document.querySelector('.test-dom-element'),
      propsData: {
        actions: actionsMock,
F
Filipa Lacerda 已提交
28
        playIconSvg: '<svg></svg>',
F
Filipa Lacerda 已提交
29 30 31 32
      },
    });

    expect(
33
      component.$el.querySelectorAll('.dropdown-menu li').length,
F
Filipa Lacerda 已提交
34 35
    ).toEqual(actionsMock.length);
    expect(
36
      component.$el.querySelector('.dropdown-menu li a').getAttribute('href'),
F
Filipa Lacerda 已提交
37
    ).toEqual(actionsMock[0].play_path);
F
Filipa Lacerda 已提交
38
  });
F
Filipa Lacerda 已提交
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

  it('should render a dropdown with the provided svg', () => {
    const actionsMock = [
      {
        name: 'bar',
        play_path: 'https://gitlab.com/play',
      },
      {
        name: 'foo',
        play_path: '#',
      },
    ];

    const component = new window.gl.environmentsList.ActionsComponent({
      el: document.querySelector('.test-dom-element'),
      propsData: {
        actions: actionsMock,
        playIconSvg: '<svg></svg>',
      },
    });

    expect(
      component.$el.querySelector('.js-dropdown-play-icon-container').children,
    ).toContain('svg');

    expect(
      component.$el.querySelector('.js-action-play-icon-container').children,
    ).toContain('svg');
  });
F
Filipa Lacerda 已提交
68
});