diff --git a/phpunit/functional/Glpi/Form/Destination/CommonITILField/AssigneeFieldTest.php b/phpunit/functional/Glpi/Form/Destination/CommonITILField/AssigneeFieldTest.php index e65aff9d207..ad83ed1679e 100644 --- a/phpunit/functional/Glpi/Form/Destination/CommonITILField/AssigneeFieldTest.php +++ b/phpunit/functional/Glpi/Form/Destination/CommonITILField/AssigneeFieldTest.php @@ -477,8 +477,8 @@ protected function sendFormAndAssertTicketActors( // Check actors $this->assertEquals( - array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::ASSIGN)), - $expected_actors_ids + $expected_actors_ids, + array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::ASSIGN)) ); } diff --git a/phpunit/functional/Glpi/Form/Destination/CommonITILField/ObserverFieldTest.php b/phpunit/functional/Glpi/Form/Destination/CommonITILField/ObserverFieldTest.php index 31df64f1610..9db8599c80e 100644 --- a/phpunit/functional/Glpi/Form/Destination/CommonITILField/ObserverFieldTest.php +++ b/phpunit/functional/Glpi/Form/Destination/CommonITILField/ObserverFieldTest.php @@ -411,8 +411,8 @@ protected function sendFormAndAssertTicketActors( // Check actors $this->assertEquals( - array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::OBSERVER)), - $expected_actors_ids + $expected_actors_ids, + array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::OBSERVER)) ); } @@ -432,21 +432,4 @@ private function createAndGetFormWithMultipleActorsQuestions(): Form ); return $this->createForm($builder); } - - private function createAndGetFormWithItemQuestions(): Form - { - $builder = new FormBuilder(); - $builder->addQuestion( - 'Computer question', - QuestionTypeItem::class, - '', - json_encode((new QuestionTypeItemExtraDataConfig(Computer::class))->jsonSerialize()) - ); - $builder->addDestination( - FormDestinationTicket::class, - "My ticket", - ); - - return $this->createForm($builder); - } } diff --git a/phpunit/functional/Glpi/Form/Destination/CommonITILField/RequesterFieldTest.php b/phpunit/functional/Glpi/Form/Destination/CommonITILField/RequesterFieldTest.php index e751ece4013..27189e096a2 100644 --- a/phpunit/functional/Glpi/Form/Destination/CommonITILField/RequesterFieldTest.php +++ b/phpunit/functional/Glpi/Form/Destination/CommonITILField/RequesterFieldTest.php @@ -411,8 +411,8 @@ protected function sendFormAndAssertTicketActors( // Check actors $this->assertEquals( - array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::REQUESTER)), - $expected_actors_ids + $expected_actors_ids, + array_map(fn(array $actor) => $actor['items_id'], $ticket->getActorsForType(CommonITILActor::REQUESTER)) ); } @@ -432,21 +432,4 @@ private function createAndGetFormWithMultipleActorsQuestions(): Form ); return $this->createForm($builder); } - - private function createAndGetFormWithItemQuestions(): Form - { - $builder = new FormBuilder(); - $builder->addQuestion( - 'Computer question', - QuestionTypeItem::class, - '', - json_encode((new QuestionTypeItemExtraDataConfig(Computer::class))->jsonSerialize()) - ); - $builder->addDestination( - FormDestinationTicket::class, - "My ticket", - ); - - return $this->createForm($builder); - } } diff --git a/phpunit/src/Glpi/Form/Destination/CommonITILField/AbstractActorFieldTest.php b/phpunit/src/Glpi/Form/Destination/CommonITILField/AbstractActorFieldTest.php index 16c644fb895..102c86e9b83 100644 --- a/phpunit/src/Glpi/Form/Destination/CommonITILField/AbstractActorFieldTest.php +++ b/phpunit/src/Glpi/Form/Destination/CommonITILField/AbstractActorFieldTest.php @@ -1,5 +1,37 @@ . + * + * --------------------------------------------------------------------- + */ + namespace Glpi\PHPUnit\Tests\Glpi\Form\Destination\CommonITILField; use Computer; @@ -49,12 +81,12 @@ public function testUserActorsFromSpecificItemQuestions(): void [ 'name' => 'testUserActorsFromSpecificItemQuestions Computer 1', 'entities_id' => $this->getTestRootEntity(true), - '_users_id_tech' => [$users[0]->getID()] + 'users_id_tech' => $users[0]->getID() ], [ 'name' => 'testUserActorsFromSpecificItemQuestions Computer 2', 'entities_id' => $this->getTestRootEntity(true), - '_users_id' => [$users[1]->getID()] + 'users_id' => $users[1]->getID() ], ]); @@ -89,7 +121,7 @@ public function testUserActorsFromSpecificItemQuestions(): void 'items_id' => $computers[1]->getID(), ] ], - expected_actors_ids: [] + expected_actors_ids: [$users[1]->getID()] ); } @@ -114,12 +146,12 @@ public function testTechUserActorsFromSpecificItemQuestions(): void [ 'name' => 'testTechUserActorsFromSpecificItemQuestions Computer 1', 'entities_id' => $this->getTestRootEntity(true), - '_users_id_tech' => [$users[0]->getID()] + 'users_id_tech' => $users[0]->getID() ], [ 'name' => 'testTechUserActorsFromSpecificItemQuestions Computer 2', 'entities_id' => $this->getTestRootEntity(true), - '_users_id' => [$users[1]->getID()] + 'users_id' => $users[1]->getID() ], ]); @@ -234,7 +266,7 @@ public function testTechGroupActorsFromSpecificItemQuestions(): void $form = $this->createAndGetFormWithItemQuestions(); $config = new $config_class( strategies: [ITILActorFieldStrategy::TECH_GROUP_FROM_OBJECT_ANSWER], - specific_question_ids: [$this->getQuestionId($form, "Computer question")] + specific_question_ids: [$this->getQuestionId($form, 'Computer question')] ); $groups = $this->createItems(Group::class, [ ['name' => 'testGroupActorsFromSpecificItemQuestions Group 1'], diff --git a/src/Glpi/Form/Destination/CommonITILField/ITILActorFieldStrategy.php b/src/Glpi/Form/Destination/CommonITILField/ITILActorFieldStrategy.php index c4faa226e65..a15352504e3 100644 --- a/src/Glpi/Form/Destination/CommonITILField/ITILActorFieldStrategy.php +++ b/src/Glpi/Form/Destination/CommonITILField/ITILActorFieldStrategy.php @@ -271,8 +271,13 @@ private function getActorsIdsFromObjectAnswer( return null; } + $actors_ids = $item->fields[$fk_field]; + if (!is_array($actors_ids)) { + $actors_ids = [$actors_ids]; + } + return [ - getItemtypeForForeignKeyField(str_replace('_tech', '', $fk_field)) => [(int) $item->fields[$fk_field]], + getItemtypeForForeignKeyField(str_replace('_tech', '', $fk_field)) => $actors_ids, ]; } } diff --git a/tests/cypress/e2e/form/destination_config_fields/actors.cy.js b/tests/cypress/e2e/form/destination_config_fields/actors.cy.js new file mode 100644 index 00000000000..85bbfd4b55e --- /dev/null +++ b/tests/cypress/e2e/form/destination_config_fields/actors.cy.js @@ -0,0 +1,197 @@ +/** + * --------------------------------------------------------------------- + * + * GLPI - Gestionnaire Libre de Parc Informatique + * + * http://glpi-project.org + * + * @copyright 2015-2025 Teclib' and contributors. + * @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 . + * + * --------------------------------------------------------------------- + */ + +const actorTypes = [ + { + name: 'Requester', + type: 'requester', + dataAttr: 'requester', + defaultValue: 'User who filled the form' + }, + { + name: 'Assignee', + type: 'assignee', + dataAttr: 'assign', + defaultValue: 'From template' + }, + { + name: 'Observer', + type: 'observer', + dataAttr: 'observer', + defaultValue: 'From template' + } +]; + +describe('Actors configuration', () => { + actorTypes.forEach((actorConfig) => { + describe(`${actorConfig.name} configuration`, () => { + beforeEach(() => { + cy.login(); + cy.changeProfile('Super-Admin', true); + + cy.createFormWithAPI().as('form_id').visitFormTab('Form'); + + // Create actor, group and computer test data + cy.get('@form_id').then((form_id) => { + const actor_name = `Test ${actorConfig.name} - ${form_id}`; + const userParams = { + name: actor_name, + }; + + // Add technician profile for assignees + if (actorConfig.type === 'assignee') { + userParams._profiles_id = 6; + } + + cy.createWithAPI('User', userParams).as('actor_id'); + + // Create a Group + cy.createWithAPI('Group', { + name: `Test Group - ${form_id}`, + }).as('group_id'); + + // Create a Computer with users and groups + cy.get('@group_id').then((group_id) => { + cy.createWithAPI('Computer', { + name: `Test Computer - ${form_id}`, + users_id: 7, + users_id_tech: 7, + groups_id: group_id, + groups_id_tech: group_id, + }).as('computer_id'); + }); + + // Create actor question + cy.findByRole('button', {'name': "Add a new question"}).click(); + cy.focused().type(`My ${actorConfig.name} question`); + cy.getDropdownByLabelText('Question type').selectDropdownValue('Actors'); + cy.getDropdownByLabelText('Question sub type').selectDropdownValue(`${actorConfig.name}s`); + cy.getDropdownByLabelText("Select an actor...").selectDropdownValue(actor_name); + cy.findByRole('button', {'name': 'Save'}).click(); + cy.checkAndCloseAlert('Item successfully updated'); + + // Create computer question + cy.findByRole('button', {'name': "Add a new question"}).click(); + cy.focused().type("My Computer question"); + cy.getDropdownByLabelText('Question type').selectDropdownValue('Item'); + cy.getDropdownByLabelText('Question sub type').selectDropdownValue('GLPI Objects'); + cy.getDropdownByLabelText("Select an itemtype").selectDropdownValue('Computers'); + cy.findByRole('button', {'name': 'Save'}).click(); + + // Go to destination tab and add ticket + cy.findByRole('tab', { 'name': "Items to create" }).click(); + cy.findByRole('button', { 'name': "Add ticket" }).click(); + cy.checkAndCloseAlert('Item successfully added'); + }); + }); + + it('can use all possibles configuration options', () => { + const regionName = `${actorConfig.name}s configuration`; + const dropdownLabel = `${actorConfig.name}s`; + + cy.findByRole('region', { 'name': regionName }).as("config"); + cy.get('@config').getDropdownByLabelText(dropdownLabel).as("dropdown"); + + // Test default value + cy.get('@dropdown').should('have.text', actorConfig.defaultValue); + + // Test hidden dropdowns + cy.get('@config').getDropdownByLabelText('Select actors...').should('not.exist'); + cy.get('@config').getDropdownByLabelText('Select questions...').should('not.exist'); + + // Test common options + const commonOptions = [ + 'From template', + 'User who filled the form', + 'Specific actors', + 'Answer from specific questions', + `Answer to last "${actorConfig.name}s" question`, + 'User from GLPI object answer', + 'Tech user from GLPI object answer', + 'Group from GLPI object answer', + 'Tech group from GLPI object answer', + 'Supervisor of the user who filled the form' + ]; + + // Test each option + commonOptions.forEach((option) => { + cy.get('@dropdown').selectDropdownValue(option); + + // Handle specific cases that need additional input + if (option === 'Specific actors') { + cy.get('@config').getDropdownByLabelText('Select actors...').as('specific_dropdown'); + cy.get('@form_id').then((form_id) => { + const actor_name = `Test ${actorConfig.name} - ${form_id}`; + cy.get('@specific_dropdown').selectDropdownValue(actor_name); + }); + } else if (option === 'Answer from specific questions') { + cy.get('@config').getDropdownByLabelText('Select questions...').as('question_dropdown'); + cy.get('@question_dropdown').selectDropdownValue(`My ${actorConfig.name} question`); + } else if (option.includes('from GLPI object answer')) { + cy.get('@config').getDropdownByLabelText('Select questions...').as('object_dropdown'); + cy.get('@object_dropdown').selectDropdownValue('My Computer question'); + } + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@dropdown').should('have.text', option); + }); + }); + + it('can create ticket using default configuration', () => { + const regionName = `${actorConfig.name}s configuration`; + const dropdownLabel = `${actorConfig.name}s`; + + cy.findByRole('region', { 'name': regionName }).as("config"); + cy.get('@config').getDropdownByLabelText(dropdownLabel).as("dropdown"); + + // Set to "User who filled the form" + cy.get('@dropdown').selectDropdownValue('User who filled the form'); + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + + // Preview and submit form + cy.findByRole('tab', { 'name': "Form" }).click(); + cy.findByRole('link', { 'name': "Preview" }) + .invoke('removeAttr', 'target') + .click(); + cy.findByRole('button', { 'name': 'Send form' }).click(); + cy.findByRole('link', { 'name': 'My test form' }).click(); + + // Verify actor in ticket + cy.findByRole('region', { 'name': "Actors" }).within(() => { + cy.get(`select[data-actor-type="${actorConfig.dataAttr}"]`).contains('E2E Tests'); + }); + }); + }); + }); +}); diff --git a/tests/cypress/e2e/form/destination_config_fields/assignee.cy.js b/tests/cypress/e2e/form/destination_config_fields/assignee.cy.js index 5a6ccbcd997..cbfcf5e137e 100644 --- a/tests/cypress/e2e/form/destination_config_fields/assignee.cy.js +++ b/tests/cypress/e2e/form/destination_config_fields/assignee.cy.js @@ -46,6 +46,22 @@ describe('Assignee configuration', () => { _profiles_id: 6, // Technician }).as('assignee_id'); + // Create a Group + cy.createWithAPI('Group', { + name: `Test Group - ${form_id}`, + }).as('group_id'); + + // Create a Computer with users_id, users_id_tech, groups_id and groups_id_tech + cy.get('@group_id').then((group_id) => { + cy.createWithAPI('Computer', { + name: `Test Computer - ${form_id}`, + users_id: 7, // E2E Tests user + users_id_tech: 7, // E2E Tests user + groups_id: group_id, + groups_id_tech: group_id, + }).as('computer_id'); + }); + cy.findByRole('button', {'name': "Add a new question"}).click(); cy.focused().type("My Assignee question"); cy.getDropdownByLabelText('Question type').selectDropdownValue('Actors'); @@ -54,6 +70,15 @@ describe('Assignee configuration', () => { cy.findByRole('button', {'name': 'Save'}).click(); cy.checkAndCloseAlert('Item successfully updated'); + cy.findByRole('button', {'name': "Add a new question"}).click(); + cy.focused().type("My Computer question"); + cy.getDropdownByLabelText('Question type').selectDropdownValue('Item'); + cy.getDropdownByLabelText('Question sub type').selectDropdownValue('GLPI Objects'); + cy.getDropdownByLabelText("Select an itemtype").selectDropdownValue('Computers'); + + // Save form + cy.findByRole('button', {'name': 'Save'}).click(); + // Go to destination tab cy.findByRole('tab', { 'name': "Items to create" }).click(); cy.findByRole('button', { 'name': "Add ticket" }).click(); @@ -118,6 +143,49 @@ describe('Assignee configuration', () => { cy.findByRole('button', { 'name': 'Update item' }).click(); cy.checkAndCloseAlert('Item successfully updated'); cy.get('@assignees_dropdown').should('have.text', 'Answer to last "Assignees" question'); + + // Switch to "Supervisor of the user who filled the form" + cy.get('@assignees_dropdown').selectDropdownValue('Supervisor of the user who filled the form'); + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@assignees_dropdown').should('have.text', 'Supervisor of the user who filled the form'); + + // Switch to "User from GLPI object answer" + cy.get('@assignees_dropdown').selectDropdownValue('User from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('user_object_answer_dropdown'); + cy.get('@user_object_answer_dropdown').selectDropdownValue('My Computer question'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@assignees_dropdown').should('have.text', 'User from GLPI object answer'); + cy.get('@user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech user from GLPI object answer" + cy.get('@assignees_dropdown').selectDropdownValue('Tech user from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_user_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@assignees_dropdown').should('have.text', 'Tech user from GLPI object answer'); + cy.get('@tech_user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Group from GLPI object answer" + cy.get('@assignees_dropdown').selectDropdownValue('Group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@assignees_dropdown').should('have.text', 'Group from GLPI object answer'); + cy.get('@group_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech group from GLPI object answer" + cy.get('@assignees_dropdown').selectDropdownValue('Tech group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@assignees_dropdown').should('have.text', 'Tech group from GLPI object answer'); + cy.get('@tech_group_object_answer_dropdown').should('have.text', '×My Computer question'); }); it('can create ticket using default configuration', () => { diff --git a/tests/cypress/e2e/form/destination_config_fields/observer.cy.js b/tests/cypress/e2e/form/destination_config_fields/observer.cy.js index 6dc0a6d4873..1ad142bdf8c 100644 --- a/tests/cypress/e2e/form/destination_config_fields/observer.cy.js +++ b/tests/cypress/e2e/form/destination_config_fields/observer.cy.js @@ -45,6 +45,22 @@ describe('Observer configuration', () => { name: observer_name, }).as('observer_id'); + // Create a Group + cy.createWithAPI('Group', { + name: `Test Group - ${form_id}`, + }).as('group_id'); + + // Create a Computer with users_id, users_id_tech, groups_id and groups_id_tech + cy.get('@group_id').then((group_id) => { + cy.createWithAPI('Computer', { + name: `Test Computer - ${form_id}`, + users_id: 7, // E2E Tests user + users_id_tech: 7, // E2E Tests user + groups_id: group_id, + groups_id_tech: group_id, + }).as('computer_id'); + }); + cy.findByRole('button', {'name': "Add a new question"}).click(); cy.focused().type("My Observer question"); cy.getDropdownByLabelText('Question type').selectDropdownValue('Actors'); @@ -53,6 +69,15 @@ describe('Observer configuration', () => { cy.findByRole('button', {'name': 'Save'}).click(); cy.checkAndCloseAlert('Item successfully updated'); + cy.findByRole('button', {'name': "Add a new question"}).click(); + cy.focused().type("My Computer question"); + cy.getDropdownByLabelText('Question type').selectDropdownValue('Item'); + cy.getDropdownByLabelText('Question sub type').selectDropdownValue('GLPI Objects'); + cy.getDropdownByLabelText("Select an itemtype").selectDropdownValue('Computers'); + + // Save form + cy.findByRole('button', {'name': 'Save'}).click(); + // Go to destination tab cy.findByRole('tab', { 'name': "Items to create" }).click(); cy.findByRole('button', { 'name': "Add ticket" }).click(); @@ -117,6 +142,43 @@ describe('Observer configuration', () => { cy.findByRole('button', { 'name': 'Update item' }).click(); cy.checkAndCloseAlert('Item successfully updated'); cy.get('@observers_dropdown').should('have.text', 'Answer to last "Observers" question'); + + // Switch to "User from GLPI object answer" + cy.get('@observers_dropdown').selectDropdownValue('User from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('user_object_answer_dropdown'); + cy.get('@user_object_answer_dropdown').selectDropdownValue('My Computer question'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@observers_dropdown').should('have.text', 'User from GLPI object answer'); + cy.get('@user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech user from GLPI object answer" + cy.get('@observers_dropdown').selectDropdownValue('Tech user from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_user_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@observers_dropdown').should('have.text', 'Tech user from GLPI object answer'); + cy.get('@tech_user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Group from GLPI object answer" + cy.get('@observers_dropdown').selectDropdownValue('Group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@observers_dropdown').should('have.text', 'Group from GLPI object answer'); + cy.get('@group_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech group from GLPI object answer" + cy.get('@observers_dropdown').selectDropdownValue('Tech group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@observers_dropdown').should('have.text', 'Tech group from GLPI object answer'); + cy.get('@tech_group_object_answer_dropdown').should('have.text', '×My Computer question'); }); it('can create ticket using default configuration', () => { diff --git a/tests/cypress/e2e/form/destination_config_fields/requester.cy.js b/tests/cypress/e2e/form/destination_config_fields/requester.cy.js index d9410f30b52..d7b892b4d5d 100644 --- a/tests/cypress/e2e/form/destination_config_fields/requester.cy.js +++ b/tests/cypress/e2e/form/destination_config_fields/requester.cy.js @@ -50,6 +50,30 @@ describe('Requester configuration', () => { cy.getDropdownByLabelText('Question type').selectDropdownValue('Actors'); cy.getDropdownByLabelText('Question sub type').selectDropdownValue('Requesters'); cy.getDropdownByLabelText("Select an actor...").selectDropdownValue(requester_name); + + // Create a Group + cy.createWithAPI('Group', { + name: `Test Group - ${form_id}`, + }).as('group_id'); + + // Create a Computer with users_id, users_id_tech, groups_id and groups_id_tech + cy.get('@group_id').then((group_id) => { + cy.createWithAPI('Computer', { + name: `Test Computer - ${form_id}`, + users_id: 7, // E2E Tests user + users_id_tech: 7, // E2E Tests user + groups_id: group_id, + groups_id_tech: group_id, + }).as('computer_id'); + }); + + cy.findByRole('button', {'name': "Add a new question"}).click(); + cy.focused().type("My Computer question"); + cy.getDropdownByLabelText('Question type').selectDropdownValue('Item'); + cy.getDropdownByLabelText('Question sub type').selectDropdownValue('GLPI Objects'); + cy.getDropdownByLabelText("Select an itemtype").selectDropdownValue('Computers'); + + // Save form cy.findByRole('button', {'name': 'Save'}).click(); cy.checkAndCloseAlert('Item successfully updated'); @@ -86,6 +110,12 @@ describe('Requester configuration', () => { cy.checkAndCloseAlert('Item successfully updated'); cy.get('@requesters_dropdown').should('have.text', 'User who filled the form'); + // Switch to "Supervisor of the user who filled the form" + cy.get('@requesters_dropdown').selectDropdownValue('Supervisor of the user who filled the form'); + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@requesters_dropdown').should('have.text', 'Supervisor of the user who filled the form'); + // Switch to "Specific actors" cy.get('@requesters_dropdown').selectDropdownValue('Specific actors'); cy.get('@config').getDropdownByLabelText('Select actors...').as('specific_requesters_dropdown'); @@ -117,6 +147,43 @@ describe('Requester configuration', () => { cy.findByRole('button', { 'name': 'Update item' }).click(); cy.checkAndCloseAlert('Item successfully updated'); cy.get('@requesters_dropdown').should('have.text', 'Answer to last "Requesters" question'); + + // Switch to "User from GLPI object answer" + cy.get('@requesters_dropdown').selectDropdownValue('User from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('user_object_answer_dropdown'); + cy.get('@user_object_answer_dropdown').selectDropdownValue('My Computer question'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@requesters_dropdown').should('have.text', 'User from GLPI object answer'); + cy.get('@user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech user from GLPI object answer" + cy.get('@requesters_dropdown').selectDropdownValue('Tech user from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_user_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@requesters_dropdown').should('have.text', 'Tech user from GLPI object answer'); + cy.get('@tech_user_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Group from GLPI object answer" + cy.get('@requesters_dropdown').selectDropdownValue('Group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@requesters_dropdown').should('have.text', 'Group from GLPI object answer'); + cy.get('@group_object_answer_dropdown').should('have.text', '×My Computer question'); + + // Switch to "Tech group from GLPI object answer" + cy.get('@requesters_dropdown').selectDropdownValue('Tech group from GLPI object answer'); + cy.get('@config').getDropdownByLabelText('Select questions...').as('tech_group_object_answer_dropdown'); + + cy.findByRole('button', { 'name': 'Update item' }).click(); + cy.checkAndCloseAlert('Item successfully updated'); + cy.get('@requesters_dropdown').should('have.text', 'Tech group from GLPI object answer'); + cy.get('@tech_group_object_answer_dropdown').should('have.text', '×My Computer question'); }); it('can create ticket using default configuration', () => {