Commit dd5332a4 authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch '356743-fix-flaky-vsa-tests' into 'master'

Fix TZ dependent flaky VSA test

See merge request gitlab-org/gitlab!83606
parents f610716c 5ca7001a
...@@ -70,6 +70,22 @@ export const buildProjectFromDataset = (dataset) => { ...@@ -70,6 +70,22 @@ export const buildProjectFromDataset = (dataset) => {
return null; return null;
}; };
/**
* Creates a new date object without time zone conversion.
*
* We use this method instead of `new Date(date)`.
* `new Date(date) will assume that the date string is UTC and it
* ant return different date depending on the user's time zone.
*
* @param {String} date - Date string.
* @returns {Date} - Date object.
*/
export const toLocalDate = (date) => {
const dateParts = date.split('-');
return new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
};
/** /**
* Creates an array of project objects from a json string. Returns null if no projects are present. * Creates an array of project objects from a json string. Returns null if no projects are present.
* *
...@@ -117,8 +133,8 @@ export const buildCycleAnalyticsInitialData = ({ ...@@ -117,8 +133,8 @@ export const buildCycleAnalyticsInitialData = ({
}), }),
) )
: null, : null,
createdBefore: createdBefore ? new Date(createdBefore) : null, createdBefore: createdBefore ? toLocalDate(createdBefore) : null,
createdAfter: createdAfter ? new Date(createdAfter) : null, createdAfter: createdAfter ? toLocalDate(createdAfter) : null,
selectedProjects: projects selectedProjects: projects
? buildProjectsFromJSON(projects).map(convertObjectPropsToCamelCase) ? buildProjectsFromJSON(projects).map(convertObjectPropsToCamelCase)
: null, : null,
......
...@@ -243,17 +243,21 @@ RSpec.describe 'Group value stream analytics filters and data', :js do ...@@ -243,17 +243,21 @@ RSpec.describe 'Group value stream analytics filters and data', :js do
end end
context 'with created_before and created_after set' do context 'with created_before and created_after set' do
let(:created_after) { '2019-11-01' }
let(:created_before) { '2019-12-31' }
date_range = '.js-daterange-picker' date_range = '.js-daterange-picker'
before do before do
visit "#{group_analytics_cycle_analytics_path(group)}?created_before=2019-12-31&created_after=2019-11-01" visit "#{group_analytics_cycle_analytics_path(group)}?created_before=#{created_before}&created_after=#{created_after}"
end end
it 'has the date range prepopulated' do it 'has the date range prepopulated' do
element = page.find(date_range) element = page.find(date_range)
expect(element.find('.js-daterange-picker-from input').value).to eq '2019-11-01' expect(element.find('.js-daterange-picker-from input').value).to eq created_after
expect(element.find('.js-daterange-picker-to input').value).to eq '2019-12-31' expect(element.find('.js-daterange-picker-to input').value).to eq created_before
expect(page.find('.js-tasks-by-type-chart')).to have_text(_("Showing data for group '%{group_name}' from Nov 1, 2019 to Dec 31, 2019") % { group_name: group.name }) expect(page.find('.js-tasks-by-type-chart')).to have_text(_("Showing data for group '%{group_name}' from Nov 1, 2019 to Dec 31, 2019") % { group_name: group.name })
end end
end end
......
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
buildGroupFromDataset, buildGroupFromDataset,
buildProjectFromDataset, buildProjectFromDataset,
buildCycleAnalyticsInitialData, buildCycleAnalyticsInitialData,
toLocalDate,
} from 'ee/analytics/shared/utils'; } from 'ee/analytics/shared/utils';
const rawValueStream = `{ const rawValueStream = `{
...@@ -80,6 +81,14 @@ describe('buildProjectFromDataset', () => { ...@@ -80,6 +81,14 @@ describe('buildProjectFromDataset', () => {
}); });
}); });
describe('toLocalDate', () => {
it('returns a Date object', () => {
const expectedDate = new Date(2022, 1, 10); // month is zero-based
expect(toLocalDate('2022-02-10')).toEqual(expectedDate);
});
});
describe('buildCycleAnalyticsInitialData', () => { describe('buildCycleAnalyticsInitialData', () => {
it.each` it.each`
field | value field | value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment