2022-10-11 01:57:18 +05:30
|
|
|
import { GlDaterangePicker } from '@gitlab/ui';
|
|
|
|
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { useFakeDate } from 'helpers/fake_date';
|
|
|
|
import Daterange from '~/analytics/shared/components/daterange.vue';
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
startDate: new Date(2019, 8, 1),
|
|
|
|
endDate: new Date(2019, 8, 11),
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Daterange component', () => {
|
|
|
|
useFakeDate(2019, 8, 25);
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const factory = (props = defaultProps, mountFn = shallowMountExtended) => {
|
2022-04-04 11:22:00 +05:30
|
|
|
wrapper = mountFn(Daterange, {
|
2021-09-30 23:02:18 +05:30
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const findDaterangePicker = () => wrapper.findComponent(GlDaterangePicker);
|
2022-10-11 01:57:18 +05:30
|
|
|
const findDateRangeIndicator = () => wrapper.findByTestId('daterange-picker-indicator');
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
describe('when show is false', () => {
|
|
|
|
it('does not render the daterange picker', () => {
|
|
|
|
factory({ show: false });
|
|
|
|
expect(findDaterangePicker().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when show is true', () => {
|
|
|
|
it('renders the daterange picker', () => {
|
|
|
|
factory({ show: true });
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(findDaterangePicker().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a minDate being set', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('emits the change event with the minDate when the user enters a start date before the minDate', async () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
const startDate = new Date('2019-09-01');
|
|
|
|
const endDate = new Date('2019-09-30');
|
|
|
|
const minDate = new Date('2019-06-01');
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
factory({ show: true, startDate, endDate, minDate }, mountExtended);
|
2021-09-30 23:02:18 +05:30
|
|
|
const input = findDaterangePicker().find('input');
|
|
|
|
|
|
|
|
input.setValue('2019-01-01');
|
2022-04-04 11:22:00 +05:30
|
|
|
await input.trigger('change');
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(wrapper.emitted().change).toEqual([[{ startDate: minDate, endDate }]]);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a maxDateRange being set', () => {
|
|
|
|
beforeEach(() => {
|
2022-10-11 01:57:18 +05:30
|
|
|
factory({ maxDateRange: 30 }, mountExtended);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the max date range indicator', () => {
|
|
|
|
expect(findDateRangeIndicator().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct number of selected days in the indicator', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(findDateRangeIndicator().text()).toBe('10 days selected');
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('sets the tooltip', () => {
|
|
|
|
const tooltip = findDaterangePicker().props('tooltip');
|
|
|
|
expect(tooltip).toBe(
|
2023-01-13 00:05:48 +05:30
|
|
|
'Showing data for workflow items completed in this date range. Date range limited to 30 days.',
|
2021-09-30 23:02:18 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('dateRange', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({ show: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('set', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
it('emits the change event with an object containing startDate and endDate', async () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
const startDate = new Date('2019-10-01');
|
|
|
|
const endDate = new Date('2019-10-05');
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await findDaterangePicker().vm.$emit('input', { startDate, endDate });
|
|
|
|
|
|
|
|
expect(wrapper.emitted('change')).toEqual([[{ startDate, endDate }]]);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('get', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
it("datepicker to have default of dateRange from state's startDate and endDate", () => {
|
|
|
|
expect(findDaterangePicker().props('value')).toEqual({
|
2021-09-30 23:02:18 +05:30
|
|
|
startDate: defaultProps.startDate,
|
|
|
|
endDate: defaultProps.endDate,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|