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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { shallowMount } from '@vue/test-utils';
import { last } from 'lodash';
2021-03-11 19:13:27 +05:30
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-03 14:25:43 +05:30
import {
ROLLOUT_STRATEGY_ALL_USERS,
ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
ROLLOUT_STRATEGY_USER_ID,
ROLLOUT_STRATEGY_GITLAB_USER_LIST,
} from '~/feature_flags/constants';
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,
},
});
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', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(component).exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
it('should emit changes from the lower component', () => {
2022-08-27 11:52:29 +05:30
const strategyParameterWrapper = wrapper.findComponent(component);
2021-01-03 14:25:43 +05:30
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
});
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(UsersWithId).props('strategy')).toEqual(strategy);
2021-01-03 14:25:43 +05:30
});
});
});