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