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

trigger_block_spec.js « components « jobs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78596612d230fa9ee5ea2ddea4f9072fd347d18b (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
import { GlButton, GlTableLite } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import TriggerBlock from '~/jobs/components/trigger_block.vue';

describe('Trigger block', () => {
  let wrapper;

  const findRevealButton = () => wrapper.findComponent(GlButton);
  const findVariableTable = () => wrapper.findComponent(GlTableLite);
  const findShortToken = () => wrapper.find('[data-testid="trigger-short-token"]');
  const findVariableValue = (index) =>
    wrapper.findAll('[data-testid="trigger-build-value"]').at(index);
  const findVariableKey = (index) => wrapper.findAll('[data-testid="trigger-build-key"]').at(index);

  const createComponent = (props) => {
    wrapper = mount(TriggerBlock, {
      propsData: {
        ...props,
      },
    });
  };

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

  describe('with short token and no variables', () => {
    it('renders short token', () => {
      createComponent({
        trigger: {
          short_token: '0a666b2',
          variables: [],
        },
      });

      expect(findShortToken().text()).toContain('0a666b2');
    });
  });

  describe('without variables or short token', () => {
    beforeEach(() => {
      createComponent({ trigger: { variables: [] } });
    });

    it('does not render short token', () => {
      expect(findShortToken().exists()).toBe(false);
    });

    it('does not render variables', () => {
      expect(findRevealButton().exists()).toBe(false);
      expect(findVariableTable().exists()).toBe(false);
    });
  });

  describe('with variables', () => {
    describe('hide/reveal variables', () => {
      it('should toggle variables on click', async () => {
        const hiddenValue = '••••••';
        const gcsVar = { key: 'UPLOAD_TO_GCS', value: 'false', public: false };
        const s3Var = { key: 'UPLOAD_TO_S3', value: 'true', public: false };

        createComponent({
          trigger: {
            variables: [gcsVar, s3Var],
          },
        });

        expect(findRevealButton().text()).toBe('Reveal values');

        expect(findVariableValue(0).text()).toBe(hiddenValue);
        expect(findVariableValue(1).text()).toBe(hiddenValue);

        expect(findVariableKey(0).text()).toBe(gcsVar.key);
        expect(findVariableKey(1).text()).toBe(s3Var.key);

        await findRevealButton().trigger('click');

        expect(findRevealButton().text()).toBe('Hide values');

        expect(findVariableValue(0).text()).toBe(gcsVar.value);
        expect(findVariableValue(1).text()).toBe(s3Var.value);
      });
    });
  });
});