debian-mirror-gitlab/spec/frontend/feature_flags/components/strategy_parameters_spec.js

84 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { shallowMount } from '@vue/test-utils';
import { last } from 'lodash';
import {
ROLLOUT_STRATEGY_ALL_USERS,
ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
ROLLOUT_STRATEGY_USER_ID,
ROLLOUT_STRATEGY_GITLAB_USER_LIST,
} from '~/feature_flags/constants';
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';
2021-01-29 00:20:46 +05:30
import { allUsersStrategy } from '../mock_data';
2021-01-03 14:25:43 +05:30
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', () => {
expect(wrapper.contains(component)).toBe(true);
});
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', () => {
2021-01-29 00:20:46 +05:30
const strategy = {
name: ROLLOUT_STRATEGY_USER_ID,
};
2021-01-03 14:25:43 +05:30
wrapper = factory({
2021-01-29 00:20:46 +05:30
strategy,
2021-01-03 14:25:43 +05:30
});
2021-01-29 00:20:46 +05:30
expect(wrapper.find(UsersWithId).props('strategy')).toEqual(strategy);
2021-01-03 14:25:43 +05:30
});
});
});