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

settings_block_spec.js « settings « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2db0b001b5bf725057b95faed15bdc1737739139 (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
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import component from '~/vue_shared/components/settings/settings_block.vue';

describe('Settings Block', () => {
  let wrapper;

  const mountComponent = (propsData) => {
    wrapper = shallowMount(component, {
      propsData,
      slots: {
        title: '<div data-testid="title-slot"></div>',
        description: '<div data-testid="description-slot"></div>',
        default: '<div data-testid="default-slot"></div>',
      },
    });
  };

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

  const findDefaultSlot = () => wrapper.find('[data-testid="default-slot"]');
  const findTitleSlot = () => wrapper.find('[data-testid="title-slot"]');
  const findDescriptionSlot = () => wrapper.find('[data-testid="description-slot"]');
  const findExpandButton = () => wrapper.find(GlButton);

  it('renders the correct markup', () => {
    mountComponent();

    expect(wrapper.element).toMatchSnapshot();
  });

  it('has a default slot', () => {
    mountComponent();

    expect(findDefaultSlot().exists()).toBe(true);
  });

  it('has a title slot', () => {
    mountComponent();

    expect(findTitleSlot().exists()).toBe(true);
  });

  it('has a description slot', () => {
    mountComponent();

    expect(findDescriptionSlot().exists()).toBe(true);
  });

  describe('expanded behaviour', () => {
    it('is collapsed by default', () => {
      mountComponent();

      expect(wrapper.classes('expanded')).toBe(false);
    });

    it('adds expanded class when the expand button is clicked', async () => {
      mountComponent();

      expect(wrapper.classes('expanded')).toBe(false);
      expect(findExpandButton().text()).toBe('Expand');

      await findExpandButton().vm.$emit('click');

      expect(wrapper.classes('expanded')).toBe(true);
      expect(findExpandButton().text()).toBe('Collapse');
    });

    it('is expanded when `defaultExpanded` is true no matter what', async () => {
      mountComponent({ defaultExpanded: true });

      expect(wrapper.classes('expanded')).toBe(true);

      await findExpandButton().vm.$emit('click');

      expect(wrapper.classes('expanded')).toBe(true);

      await findExpandButton().vm.$emit('click');

      expect(wrapper.classes('expanded')).toBe(true);
    });
  });
});