summaryrefslogtreecommitdiff
path: root/spec/javascripts/performance_bar/components/request_selector_spec.js
blob: a272e03c0e188f952bdd706da6de3ca878602a16 (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
import Vue from 'vue';
import requestSelector from '~/performance_bar/components/request_selector.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

describe('request selector', () => {
  const requests = [
    { id: '123', url: 'https://gitlab.com/' },
    {
      id: '456',
      url: 'https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/1',
    },
    {
      id: '789',
      url: 'https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/1.json?serializer=widget',
    },
  ];

  let vm;

  beforeEach(() => {
    vm = mountComponent(Vue.extend(requestSelector), {
      requests,
      currentRequest: requests[1],
    });
  });

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

  function optionText(requestId) {
    return vm.$el.querySelector(`[value='${requestId}']`).innerText.trim();
  }

  it('displays the last component of the path', () => {
    expect(optionText(requests[2].id)).toEqual('1.json?serializer=widget');
  });

  it('keeps the last two components of the path when the last component is numeric', () => {
    expect(optionText(requests[1].id)).toEqual('merge_requests/1');
  });

  it('ignores trailing slashes', () => {
    expect(optionText(requests[0].id)).toEqual('gitlab.com');
  });
});