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

mr_collapsible_extension_spec.js « components « vue_mr_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ba2a8ee0a411d80bc370705daf39f49d35f7359d (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
import { mount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui';
import MrCollapsibleSection from '~/vue_merge_request_widget/components/mr_collapsible_extension.vue';

describe('Merge Request Collapsible Extension', () => {
  let wrapper;
  const data = {
    title: 'View artifacts',
  };

  const mountComponent = (props) => {
    wrapper = mount(MrCollapsibleSection, {
      propsData: {
        ...props,
      },
      slots: {
        default: '<div class="js-slot">Foo</div>',
      },
    });
  };

  const findTitle = () => wrapper.find('.js-title');
  const findErrorMessage = () => wrapper.find('.js-error-state');

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

  describe('while collapsed', () => {
    beforeEach(() => {
      mountComponent(data);
    });

    it('renders provided title', () => {
      expect(findTitle().text()).toBe(data.title);
    });

    it('renders angle-right icon', () => {
      expect(wrapper.vm.arrowIconName).toBe('angle-right');
    });

    describe('onClick', () => {
      beforeEach(() => {
        wrapper.find('button').trigger('click');
        return wrapper.vm.$nextTick();
      });

      it('rendes the provided slot', () => {
        expect(wrapper.find('.js-slot').isVisible()).toBe(true);
      });

      it('renders `Collapse` as the title', () => {
        expect(findTitle().text()).toBe('Collapse');
      });

      it('renders angle-down icon', () => {
        expect(wrapper.vm.arrowIconName).toBe('angle-down');
      });
    });
  });

  describe('while loading', () => {
    beforeEach(() => {
      mountComponent({ ...data, isLoading: true });
    });

    it('renders the buttons disabled', () => {
      expect(wrapper.findAll('button').at(0).attributes('disabled')).toEqual('disabled');
      expect(wrapper.findAll('button').at(1).attributes('disabled')).toEqual('disabled');
    });

    it('renders loading spinner', () => {
      expect(wrapper.find(GlLoadingIcon).isVisible()).toBe(true);
    });
  });

  describe('with error', () => {
    beforeEach(() => {
      mountComponent({ ...data, hasError: true });
    });

    it('does not render the buttons', () => {
      expect(wrapper.findAll('button').exists()).toBe(false);
    });

    it('renders title message provided', () => {
      expect(findErrorMessage().text()).toBe(data.title);
    });
  });
});