Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render charts only once in time scale tests #6347

Merged
merged 1 commit into from Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 12 additions & 18 deletions test/specs/scale.time.tests.js
@@ -1,6 +1,6 @@
// Time scale tests
describe('Time scale tests', function() {
function createScale(data, options) {
function createScale(data, options, dimensions) {
var scaleID = 'myScale';
var mockContext = window.createMockContext();
var Constructor = Chart.scaleService.getScaleConstructor('time');
Expand All @@ -13,7 +13,9 @@ describe('Time scale tests', function() {
id: scaleID
});

scale.update(400, 50);
var width = (dimensions && dimensions.width) || 400;
var height = (dimensions && dimensions.height) || 50;
scale.update(width, height);
return scale;
}

Expand Down Expand Up @@ -122,8 +124,7 @@ describe('Time scale tests', function() {
};

var scaleOptions = Chart.scaleService.getScaleDefaults('time');
var scale = createScale(mockData, scaleOptions);
scale.update(1000, 200);
var scale = createScale(mockData, scaleOptions, {width: 1000, height: 200});
var ticks = getTicksLabels(scale);

// `bounds === 'data'`: first and last ticks removed since outside the data range
Expand All @@ -134,8 +135,7 @@ describe('Time scale tests', function() {
var mockData = {
labels: [newDateFromRef(0), newDateFromRef(1), newDateFromRef(2), newDateFromRef(4), newDateFromRef(6), newDateFromRef(7), newDateFromRef(9)], // days
};
var scale = createScale(mockData, Chart.scaleService.getScaleDefaults('time'));
scale.update(1000, 200);
var scale = createScale(mockData, Chart.scaleService.getScaleDefaults('time'), {width: 1000, height: 200});
var ticks = getTicksLabels(scale);

// `bounds === 'data'`: first and last ticks removed since outside the data range
Expand Down Expand Up @@ -181,10 +181,9 @@ describe('Time scale tests', function() {
}],
}
}
});
}, {canvas: {width: 800, height: 200}});

var xScale = chart.scales.xScale0;
xScale.update(800, 200);
var ticks = getTicksLabels(xScale);

// `bounds === 'data'`: first and last ticks removed since outside the data range
Expand Down Expand Up @@ -230,10 +229,9 @@ describe('Time scale tests', function() {
}],
}
}
});
}, {canvas: {width: 800, height: 200}});

var tScale = chart.scales.tScale0;
tScale.update(800, 200);
var ticks = getTicksLabels(tScale);

// `bounds === 'data'`: first and last ticks removed since outside the data range
Expand Down Expand Up @@ -290,8 +288,7 @@ describe('Time scale tests', function() {
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
config.time.unit = 'hour';

var scale = createScale(mockData, config);
scale.update(2500, 200);
var scale = createScale(mockData, config, {width: 2500, height: 200});
var ticks = getTicksLabels(scale);

expect(ticks).toEqual(['8PM', '9PM', '10PM', '11PM', '12AM', '1AM', '2AM', '3AM', '4AM', '5AM', '6AM', '7AM', '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM']);
Expand Down Expand Up @@ -383,8 +380,7 @@ describe('Time scale tests', function() {
}
}, Chart.scaleService.getScaleDefaults('time'));

var scale = createScale(mockData, config);
scale.update(800, 200);
var scale = createScale(mockData, config, {width: 800, height: 200});
var ticks = getTicksLabels(scale);

// last date is feb 15 because we round to start of week
Expand All @@ -405,8 +401,7 @@ describe('Time scale tests', function() {
}
}, Chart.scaleService.getScaleDefaults('time'));

var scale = createScale(mockData, config);
scale.update(2500, 200);
var scale = createScale(mockData, config, {width: 2500, height: 200});
var ticks = getTicksLabels(scale);

expect(ticks).toEqual(['8PM', '10PM']);
Expand Down Expand Up @@ -600,10 +595,9 @@ describe('Time scale tests', function() {
}],
}
}
});
}, {canvas: {width: 800, height: 200}});

this.scale = this.chart.scales.xScale0;
this.scale.update(800, 200);
});

it('should be bounded by nearest step\'s year start and end', function() {
Expand Down