2021-11-11 11:23:49 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import ItemStats from '~/groups/components/item_stats.vue';
|
|
|
|
import ItemStatsValue from '~/groups/components/item_stats_value.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
import { mockParentGroupItem, ITEM_TYPE } from '../mock_data';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('ItemStats', () => {
|
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const defaultProps = {
|
|
|
|
item: mockParentGroupItem,
|
|
|
|
};
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const createComponent = (props = {}) => {
|
2021-11-11 11:23:49 +05:30
|
|
|
wrapper = shallowMountExtended(ItemStats, {
|
2021-01-03 14:25:43 +05:30
|
|
|
propsData: { ...defaultProps, ...props },
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findItemStatsValue = () => wrapper.findComponent(ItemStatsValue);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('template', () => {
|
|
|
|
it('renders component container element correctly', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
createComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(wrapper.classes()).toContain('stats');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders start count and last updated information for project item correctly', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
const item = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
type: ITEM_TYPE.PROJECT,
|
|
|
|
starCount: 4,
|
2022-03-02 08:16:31 +05:30
|
|
|
lastActivityAt: '2017-04-09T18:40:39.101Z',
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
createComponent({ item });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findItemStatsValue().exists()).toBe(true);
|
|
|
|
expect(findItemStatsValue().props('cssClass')).toBe('project-stars');
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.last-updated').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
describe('group specific rendering', () => {
|
|
|
|
describe.each`
|
|
|
|
provided | state | data
|
|
|
|
${true} | ${'displays'} | ${null}
|
|
|
|
${false} | ${'does not display'} | ${{ subgroupCount: undefined, projectCount: undefined }}
|
|
|
|
`('when provided = $provided', ({ provided, state, data }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const item = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
...data,
|
|
|
|
type: ITEM_TYPE.GROUP,
|
|
|
|
};
|
|
|
|
|
|
|
|
createComponent({ item });
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
entity | testId
|
|
|
|
${'subgroups'} | ${'subgroups-count'}
|
|
|
|
${'projects'} | ${'projects-count'}
|
|
|
|
`(`${state} $entity count`, ({ testId }) => {
|
|
|
|
expect(wrapper.findByTestId(testId).exists()).toBe(provided);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|