From d25b0188118a5ab8fdfff9dd4f83899855fd0f1e Mon Sep 17 00:00:00 2001 From: Curtis Conard Date: Sat, 28 Dec 2024 16:32:14 -0500 Subject: [PATCH 1/2] fix dashboard class undefined --- src/Glpi/Dashboard/Grid.php | 112 +++++++++++++++-------------- src/Html.php | 4 -- tests/cypress/e2e/dashboards.cy.js | 55 ++++++++++++++ 3 files changed, 112 insertions(+), 59 deletions(-) create mode 100644 tests/cypress/e2e/dashboards.cy.js diff --git a/src/Glpi/Dashboard/Grid.php b/src/Glpi/Dashboard/Grid.php index d11fc02fa0c..2ea95e31e16 100644 --- a/src/Glpi/Dashboard/Grid.php +++ b/src/Glpi/Dashboard/Grid.php @@ -421,64 +421,66 @@ public function show(bool $mini = false, ?string $token = null) TWIG, $params); } - // display the grid - $html = << - - $toolbars - $filters - $grid_guide -
- $gridstack_items -
- -HTML; - - if ($mini) { - $html = "
-
- $html -
-
"; - } - $ajax_cards = GLPI_AJAX_DASHBOARD; $cache_key = sha1($_SESSION['glpiactiveentities_string'] ?? ""); - $js_params = json_encode([ - 'current' => $this->current, - 'cols' => $this->grid_cols, - 'rows' => $this->grid_rows, - 'cell_margin' => $this->cell_margin, - 'rand' => $rand, - 'ajax_cards' => $ajax_cards, - 'all_cards' => $cards, - 'all_widgets' => $all_widgets, - 'context' => $this->context, - 'cache_key' => $cache_key, - 'embed' => self::$embed, - 'token' => $token, - 'entities_id' => $_SESSION['glpiactive_entity'], - 'is_recursive' => $_SESSION['glpiactive_entity_recursive'] ? 1 : 0 - ]); - $js = << $mini, + 'embed_class' => $embed_class, + 'mini_class' => $mini_class, + 'toolbars' => $toolbars, + 'filters' => $filters, + 'grid_guide' => $grid_guide, + 'gridstack_items' => $gridstack_items, + 'rand' => $rand, + 'grid_cols' => $this->grid_cols, + 'grid_rows' => $this->grid_rows, + 'js_params' => [ + 'current' => $this->current, + 'cols' => $this->grid_cols, + 'rows' => $this->grid_rows, + 'cell_margin' => $this->cell_margin, + 'rand' => $rand, + 'ajax_cards' => $ajax_cards, + 'all_cards' => $cards, + 'all_widgets' => $all_widgets, + 'context' => $this->context, + 'cache_key' => $cache_key, + 'embed' => self::$embed, + 'token' => $token, + 'entities_id' => $_SESSION['glpiactive_entity'], + 'is_recursive' => $_SESSION['glpiactive_entity_recursive'] ? 1 : 0 + ] + ]; + // language=Twig + echo TemplateRenderer::getInstance()->renderFromStringTemplate(<< +
+ {% endif %} +
+ + {{ toolbars|raw }} + {{ filters|raw }} + {{ grid_guide|raw }} +
+ {{ gridstack_items|raw }} +
+
+ {% if mini %} +
+ + {% endif %} + +TWIG, $twig_params); } diff --git a/src/Html.php b/src/Html.php index 59e31cbee63..7f6cabae6ab 100644 --- a/src/Html.php +++ b/src/Html.php @@ -1112,7 +1112,6 @@ public static function includeHeader( if (in_array('dashboard', $jslibs)) { $tpl_vars['css_files'][] = ['path' => 'css/standalone/dashboard.scss']; - Html::requireJs('dashboard'); } if (in_array('marketplace', $jslibs)) { @@ -5950,9 +5949,6 @@ public static function requireJs($name) case 'fuzzy': $_SESSION['glpi_js_toload'][$name][] = 'lib/fuzzy.js'; break; - case 'dashboard': - $_SESSION['glpi_js_toload'][$name][] = 'js/dashboard.js'; - break; case 'marketplace': $_SESSION['glpi_js_toload'][$name][] = 'js/marketplace.js'; break; diff --git a/tests/cypress/e2e/dashboards.cy.js b/tests/cypress/e2e/dashboards.cy.js new file mode 100644 index 00000000000..82e1d2c9e64 --- /dev/null +++ b/tests/cypress/e2e/dashboards.cy.js @@ -0,0 +1,55 @@ +/** + * --------------------------------------------------------------------- + * + * GLPI - Gestionnaire Libre de Parc Informatique + * + * http://glpi-project.org + * + * @copyright 2015-2025 Teclib' and contributors. + * @copyright 2003-2014 by the INDEPNET Development Team. + * @licence https://www.gnu.org/licenses/gpl-3.0.html + * + * --------------------------------------------------------------------- + * + * LICENSE + * + * This file is part of GLPI. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * --------------------------------------------------------------------- + */ +describe('Dashboard', () => { + beforeEach(() => { + cy.login(); + }); + + const dashboards = new Map([ + ['Asset', '/front/dashboard_assets.php'], + ['Assistance', '/front/dashboard_helpdesk.php'], + ['Central', '/front/central.php'], + ['Tickets Mini', '/front/ticket.php'], + ]); + + dashboards.forEach((value, key) => { + it(`${key} Dashboard Loads`, () => { + cy.visit(value); + cy.get('.grid-stack-item .g-chart, .grid-stack-item .big-number').should('be.visible'); + // grid-stack-items should have reasonable height + cy.get('.grid-stack-item:not(.lock-bottom)').each(($el) => { + cy.get($el).invoke('height').should('be.gt', 30); + }); + }); + }); +}); From b4fb23696e85d5b2359a7d73734743e3924b7cc8 Mon Sep 17 00:00:00 2001 From: AdrienClairembault Date: Thu, 9 Jan 2025 11:00:06 +0100 Subject: [PATCH 2/2] Fix tests --- tests/cypress/e2e/search/display_preferences.cy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/cypress/e2e/search/display_preferences.cy.js b/tests/cypress/e2e/search/display_preferences.cy.js index d8880376c7f..9366f973041 100644 --- a/tests/cypress/e2e/search/display_preferences.cy.js +++ b/tests/cypress/e2e/search/display_preferences.cy.js @@ -145,9 +145,7 @@ describe('Display preferences', () => { cy.wait(250); } - cy.intercept('GET', '/ajax/common.tabs.php?*').as('refresh_tab_request'); cy.get('@iframeBody').find('#tabspanel-select').select(name); - cy.wait('@refresh_tab_request'); } function addDisplayPeference(name) {