glpi icon indicating copy to clipboard operation
glpi copied to clipboard

feat(forms): use an answer formatted by the question type to handle other types than string

Open ccailly opened this issue 1 year ago • 2 comments

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets

Update AnswerTagProvider to return the formatted answer instead of the raw answer. This change improves the display of answers by formatting them based on their type. The getFormattedAnswer() method has been added to the Answer class, which formats the raw answer using the corresponding QuestionType's formatRawAnswer() method.

ccailly avatar Aug 06 '24 10:08 ccailly

Need https://github.com/glpi-project/glpi/pull/17435 to be merged first.

ccailly avatar Aug 06 '24 10:08 ccailly

Looks great 👍

I was looking into fixing the urgency field (which display the raw value instead of the urgency name) but I think you already fixed it with this right ?

I was building this test case on my end, maybe you could copy it and try it to confirm ? sendFormAndGetCreatedTicket is from the urgency field PR, I'll extract it to main so it can be used without waiting for it to be merged.

namespace tests\units\Glpi\Form\QuestionType;

use DbTestCase;
use Glpi\Form\Destination\FormDestinationTicket;
use Glpi\Form\QuestionType\QuestionTypeUrgency;
use Glpi\Tests\FormBuilder;
use Glpi\Tests\FormTesterTrait;

final class QuestionTypeUrgencyTest extends DbTestCase
{
    use FormTesterTrait;

    public function testUrgencyAnswerIsDisplayedInTicketDescription(): void
    {
        $builder = new FormBuilder();
        $builder->addQuestion("What is the urgency", QuestionTypeUrgency::class);
        $builder->addDestination(FormDestinationTicket::class, "My ticket");
        $form = $this->createForm($builder);

        $ticket = $this->sendFormAndGetCreatedTicket($form, [
            "What is the urgency" => 5, // Very high
        ]);

        $this->assertStringContainsString(
            "1) What is the urgency: Very high",
            strip_tags($ticket->fields['content']),
        );
    }
}

AdrienClairembault avatar Aug 07 '24 09:08 AdrienClairembault

I accidentally overwrote the changes made by @AdrienClairembault. I reapplied them in the last commit.

ccailly avatar Sep 09 '24 14:09 ccailly