Skip to content

Commit b72f5b8

Browse files
build: create charts by targeting specific library
1 parent 196978a commit b72f5b8

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

cypress/integration/free-gutenberg.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ describe('Test Free - gutenberg', function() {
1212
it.skip('temp test', function() {
1313
});
1414

15-
it('Create all charts', function() {
16-
cy.create_available_charts(Cypress.env('chart_types').free);
15+
it('Create GoogleCharts charts', function() {
16+
cy.create_available_charts(Cypress.env('chart_types').free, 'GoogleCharts');
17+
});
18+
19+
it('Create DataTable charts', function() {
20+
cy.create_available_charts(1, 'DataTable');
1721
});
1822

1923
it('Verify insertion of charts', function() {
2024
cy.visit('/post-new.php');
2125

2226
cy.clear_welcome();
2327

24-
var charts = [];
25-
for(var i = 1; i <= parseInt(Cypress.env('chart_types').free); i++){
26-
charts.push(i);
27-
}
28+
var charts = Array.from({ length: parseInt(Cypress.env('chart_types').free) + 1 }, function(_item, index) {
29+
return index + 1;
30+
});
2831

2932
cy.wrap(charts).each((value, i, array) => {
3033
// insert a visualizer block
@@ -50,6 +53,11 @@ describe('Test Free - gutenberg', function() {
5053

5154
cy.wrap($block).find('.visualizer-settings .visualizer-settings__chart').should('have.length', 1);
5255

56+
// log a line to show which chart we are trying to insert.
57+
cy.wrap($block).find('.visualizer-settings .visualizer-settings__chart').then( ($chart_block) => {
58+
cy.log('Processing chart: ' + Cypress.$($chart_block).attr('data-chart-type'));
59+
});
60+
5361
// chart and footer divs
5462
cy.wrap($block).find('.visualizer-settings .visualizer-settings__chart > div').should('have.length', 2);
5563

cypress/support/commands.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Cypress.Commands.add( 'test_advanced_settings', ($create_new_chart) => {
265265
});
266266

267267
// create the first N charts available
268-
Cypress.Commands.add( 'create_available_charts', ($num) => {
268+
Cypress.Commands.add( 'create_available_charts', ($num, $lib = '') => {
269269
var charts = [];
270270
for(var i = 1; i <= parseInt($num); i++){
271271
charts.push(i);
@@ -283,10 +283,22 @@ Cypress.Commands.add( 'create_available_charts', ($num) => {
283283
.then(function ($iframe) {
284284
const $body = $iframe.contents().find('body');
285285

286-
// select the chart.
287-
cy.wrap($body).find('#type-picker .type-box:nth-child(' + chart + ') .type-radio').check();
288-
// create the chart.
289-
cy.wrap($body).find('#toolbar input[type="submit"]').click();
286+
cy.wrap($body).then(function($body){
287+
// if we are targeting a particular library, remove charts that do not support it
288+
// like Google may support 2nd, 3rd and 10th charts - so we will remove all but these.
289+
if('' !== $lib){
290+
$body.find('#type-picker .type-box:not(.type-lib-' + $lib + ')').remove();
291+
}
292+
// select the chart.
293+
cy.wrap($body).find('#type-picker .type-box:nth-child(' + chart + ') .type-radio').check();
294+
295+
// if we are targeting a particular library, then select it in the toolbar
296+
if('' !== $lib){
297+
cy.wrap($body).find('.viz-select-library').select($lib);
298+
}
299+
// create the chart.
300+
cy.wrap($body).find('#toolbar input[type="submit"]').click();
301+
});
290302
});
291303

292304
cy.wait( Cypress.env('wait') );
@@ -299,7 +311,6 @@ Cypress.Commands.add( 'create_available_charts', ($num) => {
299311
});
300312

301313
cy.wait( Cypress.env('wait') );
302-
303314
// verify that the chart was created and the count increased by 1
304315
cy.visit(Cypress.env('urls').library ).then(() => {
305316
cy.get('#visualizer-library .visualizer-chart').should('have.length', chart);

0 commit comments

Comments
 (0)