debian-mirror-gitlab/spec/frontend/jobs/components/trigger_block_spec.js

87 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlButton, GlTable } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import TriggerBlock from '~/jobs/components/trigger_block.vue';
2018-11-20 20:47:30 +05:30
describe('Trigger block', () => {
2021-03-11 19:13:27 +05:30
let wrapper;
const findRevealButton = () => wrapper.find(GlButton);
const findVariableTable = () => wrapper.find(GlTable);
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,
},
});
};
2018-11-20 20:47:30 +05:30
afterEach(() => {
2021-03-11 19:13:27 +05:30
wrapper.destroy();
wrapper = null;
2018-11-20 20:47:30 +05:30
});
2021-03-11 19:13:27 +05:30
describe('with short token and no variables', () => {
2018-11-20 20:47:30 +05:30
it('renders short token', () => {
2021-03-11 19:13:27 +05:30
createComponent({
2018-12-05 23:21:45 +05:30
trigger: {
short_token: '0a666b2',
2021-03-11 19:13:27 +05:30
variables: [],
2018-12-05 23:21:45 +05:30
},
2018-11-20 20:47:30 +05:30
});
2021-03-11 19:13:27 +05:30
expect(findShortToken().text()).toContain('0a666b2');
2018-11-20 20:47:30 +05:30
});
});
2021-03-11 19:13:27 +05:30
describe('without variables or short token', () => {
beforeEach(() => {
createComponent({ trigger: { variables: [] } });
});
2018-11-20 20:47:30 +05:30
it('does not render short token', () => {
2021-03-11 19:13:27 +05:30
expect(findShortToken().exists()).toBe(false);
});
2018-11-20 20:47:30 +05:30
2021-03-11 19:13:27 +05:30
it('does not render variables', () => {
expect(findRevealButton().exists()).toBe(false);
expect(findVariableTable().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
});
describe('with variables', () => {
2019-02-15 15:39:39 +05:30
describe('hide/reveal variables', () => {
2021-03-11 19:13:27 +05:30
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({
2018-12-05 23:21:45 +05:30
trigger: {
2021-03-11 19:13:27 +05:30
variables: [gcsVar, s3Var],
2018-11-20 20:47:30 +05:30
},
});
2021-03-11 19:13:27 +05:30
expect(findRevealButton().text()).toBe('Reveal values');
2018-12-13 13:39:08 +05:30
2021-03-11 19:13:27 +05:30
expect(findVariableValue(0).text()).toBe(hiddenValue);
expect(findVariableValue(1).text()).toBe(hiddenValue);
2018-12-13 13:39:08 +05:30
2021-03-11 19:13:27 +05:30
expect(findVariableKey(0).text()).toBe(gcsVar.key);
expect(findVariableKey(1).text()).toBe(s3Var.key);
2019-02-15 15:39:39 +05:30
2021-03-11 19:13:27 +05:30
await findRevealButton().trigger('click');
2019-02-15 15:39:39 +05:30
2021-03-11 19:13:27 +05:30
expect(findRevealButton().text()).toBe('Hide values');
2019-02-15 15:39:39 +05:30
2021-03-11 19:13:27 +05:30
expect(findVariableValue(0).text()).toBe(gcsVar.value);
expect(findVariableValue(1).text()).toBe(s3Var.value);
2018-11-20 20:47:30 +05:30
});
});
});
});