Skip to content

Commit

Permalink
Add description fields to service catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored Sep 11, 2024
1 parent c76c4cf commit 00f3fd2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
2 changes: 2 additions & 0 deletions install/migrations/update_10.0.x_to_11.0.0/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
`name` varchar(255) NOT NULL DEFAULT '',
`header` longtext,
`icon` varchar(255) NOT NULL DEFAULT '',
`description` longtext,
`date_mod` timestamp NULL DEFAULT NULL,
`date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
Expand Down Expand Up @@ -231,6 +232,7 @@
$migration->addField("glpi_forms_destinations_formdestinations", "config", "JSON NOT NULL COMMENT 'Extra configuration field(s) depending on the destination type'");

$migration->addField("glpi_forms_forms", "icon", "string");
$migration->addField("glpi_forms_forms", "description", "text");
}

CronTask::register('Glpi\Form\Form', 'purgedraftforms', DAY_TIMESTAMP, [
Expand Down
1 change: 1 addition & 0 deletions install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9414,6 +9414,7 @@ CREATE TABLE `glpi_forms_forms` (
`name` varchar(255) NOT NULL DEFAULT '',
`header` longtext,
`icon` varchar(255) NOT NULL DEFAULT '',
`description` longtext,
`date_mod` timestamp NULL DEFAULT NULL,
`date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
Expand Down
12 changes: 12 additions & 0 deletions templates/pages/admin/form/service_catalog_tab.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
}
) }}

{{ fields.textareaField(
'description',
form.fields.description,
__('Description'),
{
'is_horizontal': false,
'full_width' : true,
'enable_richtext': true,
'enable_images': false,
}
) }}

{# Hidden values #}
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="id" value="{{ form.getID() }}" />
Expand Down
5 changes: 1 addition & 4 deletions templates/pages/self-service/service_catalog.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
<h2 id="form-{{ form.fields.id }}" class="card-title">
{{ form.fields.name }}
</h2>
{# TODO: showing description instead of header (description does not yet
exist and header is meant to be displated above the form in its own
page). We use header for now to "fill" the space. #}
<div class="text-secondary">{{ form.fields.header|safe_html }}</div>
<div class="text-secondary">{{ form.fields.description|safe_html }}</div>
</div>
</div>
</section>
Expand Down
22 changes: 12 additions & 10 deletions tests/cypress/e2e/form/service_catalog/service_catalog_page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,29 @@

describe('Service catalog page', () => {
beforeEach(() => {
// Create at least one form to make sure the list is not empty.
cy.createFormWithAPI({
'name': "Test form for service_catalog_page.cy.js",
'header': "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam deleniti fugit incidunt, iste, itaque minima neque pariatur perferendis sed suscipit velit vitae voluptatem.",
'is_active': true,
});

cy.login();
cy.changeProfile('Self-Service', true);

});

it('can pick a form in the service catalog', () => {
const form_name = "Test form for service_catalog_page.cy.js " + (new Date()).getTime();

// Create at least one form to make sure the list is not empty.
cy.createFormWithAPI({
'name': form_name,
'description': "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
'is_active': true,
});

cy.visit('/ServiceCatalog');
cy.injectAndCheckA11y();
cy.findByRole('region', {'name': 'Test form for service_catalog_page.cy.js'}).as('form');
cy.findByRole('region', {'name': form_name}).as('form');

// Validate that the form is displayed correctly.
cy.get('@form').within(() => {
cy.findByText("Test form for service_catalog_page.cy.js").should('exist');
cy.findByText("Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam deleniti fugit incidunt, iste, itaque minima neque pariatur perferendis sed suscipit velit vitae voluptatem.").should('exist');
cy.findByText(form_name).should('exist');
cy.findByText("Lorem ipsum dolor sit amet, consectetur adipisicing elit.").should('exist');
});

// Go to form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ describe('Service catalog tab', () => {
// Make sure the values we are about to apply are are not already set to
// prevent false negative.
cy.getDropdownByLabelText("Icon").should('not.contain.text', 'ti-dog');
cy.findByLabelText("Description").awaitTinyMCE().should('not.contain.text', 'My description');

// Set values
cy.getDropdownByLabelText("Icon").selectDropdownValue('ti-dog');
cy.findByLabelText("Description").awaitTinyMCE().type('My description');

// Save changes
cy.findByRole('button', {'name': "Save changes"}).click();
cy.findByRole('alert').should('contain.text', 'Item successfully updated');

// Validate values
cy.getDropdownByLabelText("Icon").should('contain.text', 'ti-dog');
cy.findByLabelText("Description").awaitTinyMCE().should('contain.text', 'My description');
});
});

0 comments on commit 00f3fd2

Please sign in to comment.