-
Notifications
You must be signed in to change notification settings - Fork 4
Fix: Table question's columns panel forces the whole page to scroll w… #52
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
Open
UncleTomsCabi
wants to merge
3
commits into
pluginsGLPI:main
Choose a base branch
from
UncleTomsCabi:fix/table-config-scroll
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
tests/Model/QuestionType/TableQuestionAdminConfigRenderingTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * ------------------------------------------------------------------------- | ||
| * advancedforms plugin for GLPI | ||
| * ------------------------------------------------------------------------- | ||
| * | ||
| * MIT License | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| * ------------------------------------------------------------------------- | ||
| * @copyright Copyright (C) 2025 by the advancedforms plugin team. | ||
| * @license MIT https://opensource.org/licenses/mit-license.php | ||
| * @link https://github.com/pluginsGLPI/advancedforms | ||
| * ------------------------------------------------------------------------- | ||
| */ | ||
|
|
||
| namespace GlpiPlugin\Advancedforms\Tests\Model\QuestionType; | ||
|
|
||
| use Glpi\Form\Question; | ||
| use Glpi\Form\QuestionType\QuestionTypeShortText; | ||
| use Glpi\Tests\FormBuilder; | ||
| use GlpiPlugin\Advancedforms\Model\QuestionType\TableQuestion; | ||
| use GlpiPlugin\Advancedforms\Model\QuestionType\TableQuestionConfig; | ||
| use GlpiPlugin\Advancedforms\Tests\AdvancedFormsTestCase; | ||
| use Symfony\Component\DomCrawler\Crawler; | ||
|
|
||
| /** | ||
| * Regression test for a form editor bug: the columns configuration panel had | ||
| * no scroll of its own, so a Table question with enough columns to overflow | ||
| * the viewport made the whole PAGE scroll to reach the last ones — which, at | ||
| * least in Chromium/Bootstrap 5, could make the still-open dropdown menu jump | ||
| * back to the top instead of staying anchored to its toggle button. | ||
| */ | ||
| final class TableQuestionAdminConfigRenderingTest extends AdvancedFormsTestCase | ||
| { | ||
| private TableQuestion $type; | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->type = new TableQuestion(); | ||
| $this->login(); | ||
| } | ||
|
|
||
| public function testColumnsContainerScrollsOnItsOwnInsteadOfThePage(): void | ||
| { | ||
| $html = $this->renderConfig([ | ||
| $this->column('A', QuestionTypeShortText::class), | ||
| $this->column('B', QuestionTypeShortText::class), | ||
| ]); | ||
|
|
||
| $crawler = new Crawler($html); | ||
| $container = $crawler->filter('[data-af-table-columns-container]')->first(); | ||
|
|
||
| $this->assertGreaterThan( | ||
| 0, | ||
| $container->count(), | ||
| 'The columns configuration panel must be present in the rendered admin template.', | ||
| ); | ||
|
|
||
| $style = (string) $container->attr('style'); | ||
| $this->assertStringContainsString( | ||
| 'overflow-y: auto', | ||
| $style, | ||
| 'The columns container must scroll on its own once it has enough columns, ' . | ||
| 'instead of forcing the whole page (and the still-open dropdown menu with it) to scroll.', | ||
| ); | ||
| $this->assertMatchesRegularExpression( | ||
| '/max-height\s*:\s*\d+(\.\d+)?(vh|px|rem|em)/', | ||
| $style, | ||
| 'A bare `overflow-y: auto` with no height constraint never actually scrolls.', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<array{name: string, question_type: string, required: bool, itemtype: string, pattern: string}> $columns | ||
| */ | ||
| private function renderConfig(array $columns): string | ||
| { | ||
| $this->enableConfigurableItem($this->type); | ||
|
|
||
| $builder = new FormBuilder('Admin config rendering form'); | ||
| $builder->addQuestion( | ||
| 'Table', | ||
| TableQuestion::class, | ||
| extra_data: json_encode(new TableQuestionConfig(columns: $columns)), | ||
| ); | ||
| $form = $this->createForm($builder); | ||
|
|
||
| $question = Question::getById($this->getQuestionId($form, 'Table')); | ||
|
|
||
| return $this->type->renderAdvancedConfigurationTemplate($question); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{name: string, question_type: string, required: bool, itemtype: string, pattern: string} | ||
| */ | ||
| private function column(string $name, string $fqcn): array | ||
| { | ||
| return [ | ||
| TableQuestionConfig::COL_NAME => $name, | ||
| TableQuestionConfig::COL_QUESTION_TYPE => $fqcn, | ||
| TableQuestionConfig::COL_REQUIRED => false, | ||
| TableQuestionConfig::COL_ITEMTYPE => '', | ||
| TableQuestionConfig::COL_PATTERN => '', | ||
| ]; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.