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

content_transition_spec.js « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bb6d31cce77e67e40828c4132e835a27a31e53c (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { groupBy, mapValues } from 'lodash';
import { shallowMount } from '@vue/test-utils';
import ContentTransition from '~/vue_shared/components/content_transition.vue';

const TEST_CURRENT_SLOT = 'default';
const TEST_TRANSITION_NAME = 'test_transition_name';
const TEST_SLOTS = [
  { key: 'default', attributes: { 'data-testval': 'default' } },
  { key: 'foo', attributes: { 'data-testval': 'foo' } },
  { key: 'bar', attributes: { 'data-testval': 'bar' } },
];

describe('~/vue_shared/components/content_transition.vue', () => {
  let wrapper;

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

  const createComponent = (props = {}, slots = {}) => {
    wrapper = shallowMount(ContentTransition, {
      propsData: {
        transitionName: TEST_TRANSITION_NAME,
        currentSlot: TEST_CURRENT_SLOT,
        slots: TEST_SLOTS,
        ...props,
      },
      slots: {
        default: '<p>Default</p>',
        foo: '<p>Foo</p>',
        bar: '<p>Bar</p>',
        dne: '<p>DOES NOT EXIST</p>',
        ...slots,
      },
    });
  };

  const findTransitionsData = () =>
    wrapper.findAll('transition-stub').wrappers.map((transition) => {
      const child = transition.find('[data-testval]');
      const { style, ...attributes } = child.attributes();

      return {
        transitionName: transition.attributes('name'),
        isVisible: child.isVisible(),
        attributes,
        text: transition.text(),
      };
    });
  const findVisibleData = () => {
    const group = groupBy(findTransitionsData(), (x) => x.attributes['data-testval']);

    return mapValues(group, (x) => x[0].isVisible);
  };

  describe('default', () => {
    beforeEach(() => {
      createComponent();
    });

    it('shows all transitions and only default is visible', () => {
      expect(wrapper.element).toMatchSnapshot();
    });

    it('render transitions for each slot', () => {
      expect(findTransitionsData()).toEqual([
        {
          attributes: {
            'data-testval': 'default',
          },
          isVisible: true,
          text: 'Default',
          transitionName: 'test_transition_name',
        },
        {
          attributes: {
            'data-testval': 'foo',
          },
          isVisible: false,
          text: 'Foo',
          transitionName: 'test_transition_name',
        },
        {
          attributes: {
            'data-testval': 'bar',
          },
          isVisible: false,
          text: 'Bar',
          transitionName: 'test_transition_name',
        },
      ]);
    });
  });

  describe('with currentSlot=foo', () => {
    beforeEach(() => {
      createComponent({ currentSlot: 'foo' });
    });

    it('should only show the foo slot', () => {
      expect(findVisibleData()).toEqual({
        default: false,
        foo: true,
        bar: false,
      });
    });
  });
});