summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/repo_file_buttons_spec.js
blob: c86bdb132b45f1b88f8524f3510ed6cdcfc34faf (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
import Vue from 'vue';
import repoFileButtons from '~/ide/components/repo_file_buttons.vue';
import createVueComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';

describe('RepoFileButtons', () => {
  const activeFile = file();
  let vm;

  function createComponent() {
    const RepoFileButtons = Vue.extend(repoFileButtons);

    activeFile.rawPath = 'test';
    activeFile.blamePath = 'test';
    activeFile.commitsPath = 'test';

    return createVueComponent(RepoFileButtons, {
      file: activeFile,
    });
  }

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

  it('renders Raw, Blame, History, Permalink and Preview toggle', done => {
    vm = createComponent();

    vm.$nextTick(() => {
      const raw = vm.$el.querySelector('.raw');
      const blame = vm.$el.querySelector('.blame');
      const history = vm.$el.querySelector('.history');

      expect(raw.href).toMatch(`/${activeFile.rawPath}`);
      expect(raw.textContent.trim()).toEqual('Raw');
      expect(blame.href).toMatch(`/${activeFile.blamePath}`);
      expect(blame.textContent.trim()).toEqual('Blame');
      expect(history.href).toMatch(`/${activeFile.commitsPath}`);
      expect(history.textContent.trim()).toEqual('History');
      expect(vm.$el.querySelector('.permalink').textContent.trim()).toEqual(
        'Permalink',
      );

      done();
    });
  });
});