2021-08-24 18:10:53 +00:00
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2020-10-02 12:09:03 +00:00
|
|
|
import ItemStats from '~/groups/components/item_stats.vue';
|
|
|
|
import ItemStatsValue from '~/groups/components/item_stats_value.vue';
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
import { mockParentGroupItem, ITEM_TYPE } from '../mock_data';
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
describe('ItemStats', () => {
|
|
|
|
let wrapper;
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const defaultProps = {
|
|
|
|
item: mockParentGroupItem,
|
|
|
|
};
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const createComponent = (props = {}) => {
|
2021-08-24 18:10:53 +00:00
|
|
|
wrapper = shallowMountExtended(ItemStats, {
|
2020-10-02 12:09:03 +00:00
|
|
|
propsData: { ...defaultProps, ...props },
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
2020-10-02 12:09:03 +00:00
|
|
|
};
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
|
2022-08-29 09:10:06 +00:00
|
|
|
const findItemStatsValue = () => wrapper.findComponent(ItemStatsValue);
|
2020-10-02 12:09:03 +00:00
|
|
|
|
2017-10-04 14:10:24 +00:00
|
|
|
describe('template', () => {
|
2017-12-22 07:36:24 +00:00
|
|
|
it('renders component container element correctly', () => {
|
2020-10-02 12:09:03 +00:00
|
|
|
createComponent();
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(wrapper.classes()).toContain('stats');
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
|
2017-12-22 07:36:24 +00:00
|
|
|
it('renders start count and last updated information for project item correctly', () => {
|
2020-10-02 12:09:03 +00:00
|
|
|
const item = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
type: ITEM_TYPE.PROJECT,
|
|
|
|
starCount: 4,
|
2022-01-10 15:14:26 +00:00
|
|
|
lastActivityAt: '2017-04-09T18:40:39.101Z',
|
2020-10-02 12:09:03 +00:00
|
|
|
};
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
createComponent({ item });
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(findItemStatsValue().exists()).toBe(true);
|
|
|
|
expect(findItemStatsValue().props('cssClass')).toBe('project-stars');
|
2020-12-25 09:10:31 +00:00
|
|
|
expect(wrapper.find('.last-updated').exists()).toBe(true);
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
2021-08-24 18:10:53 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
});
|