2020-10-05 14:08:51 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { last } from 'lodash';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Default from '~/feature_flags/components/strategies/default.vue';
|
|
|
|
import GitlabUserList from '~/feature_flags/components/strategies/gitlab_user_list.vue';
|
|
|
|
import PercentRollout from '~/feature_flags/components/strategies/percent_rollout.vue';
|
|
|
|
import UsersWithId from '~/feature_flags/components/strategies/users_with_id.vue';
|
|
|
|
import StrategyParameters from '~/feature_flags/components/strategy_parameters.vue';
|
2020-10-05 14:08:51 -04:00
|
|
|
import {
|
|
|
|
ROLLOUT_STRATEGY_ALL_USERS,
|
|
|
|
ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
|
|
|
|
ROLLOUT_STRATEGY_USER_ID,
|
|
|
|
ROLLOUT_STRATEGY_GITLAB_USER_LIST,
|
|
|
|
} from '~/feature_flags/constants';
|
2020-11-03 04:09:07 -05:00
|
|
|
import { allUsersStrategy } from '../mock_data';
|
2020-10-05 14:08:51 -04:00
|
|
|
|
|
|
|
const DEFAULT_PROPS = {
|
|
|
|
strategy: allUsersStrategy,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('~/feature_flags/components/strategy_parameters.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (props = {}) =>
|
|
|
|
shallowMount(StrategyParameters, {
|
|
|
|
propsData: {
|
|
|
|
...DEFAULT_PROPS,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper?.destroy) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
name | component
|
|
|
|
${ROLLOUT_STRATEGY_ALL_USERS} | ${Default}
|
|
|
|
${ROLLOUT_STRATEGY_PERCENT_ROLLOUT} | ${PercentRollout}
|
|
|
|
${ROLLOUT_STRATEGY_USER_ID} | ${UsersWithId}
|
|
|
|
${ROLLOUT_STRATEGY_GITLAB_USER_LIST} | ${GitlabUserList}
|
|
|
|
`('with $name', ({ name, component }) => {
|
|
|
|
let strategy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
strategy = { name, parameters: {} };
|
|
|
|
wrapper = factory({ strategy });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the correct component', () => {
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(wrapper.find(component).exists()).toBe(true);
|
2020-10-05 14:08:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit changes from the lower component', () => {
|
|
|
|
const strategyParameterWrapper = wrapper.find(component);
|
|
|
|
|
|
|
|
strategyParameterWrapper.vm.$emit('change', { parameters: { foo: 'bar' } });
|
|
|
|
|
|
|
|
expect(last(wrapper.emitted('change'))).toEqual([
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
parameters: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('pass through props', () => {
|
|
|
|
it('should pass through any extra props that might be needed', () => {
|
2020-11-03 04:09:07 -05:00
|
|
|
const strategy = {
|
|
|
|
name: ROLLOUT_STRATEGY_USER_ID,
|
|
|
|
};
|
2020-10-05 14:08:51 -04:00
|
|
|
wrapper = factory({
|
2020-11-03 04:09:07 -05:00
|
|
|
strategy,
|
2020-10-05 14:08:51 -04:00
|
|
|
});
|
|
|
|
|
2020-11-03 04:09:07 -05:00
|
|
|
expect(wrapper.find(UsersWithId).props('strategy')).toEqual(strategy);
|
2020-10-05 14:08:51 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|