diff --git a/config/routes/admin/seal.yaml b/config/routes/admin/seal.yaml
index 4c0ee18c..02f6d436 100644
--- a/config/routes/admin/seal.yaml
+++ b/config/routes/admin/seal.yaml
@@ -17,3 +17,8 @@ remove:
path: /{id}/remove
controller: App\Controller\Web\Admin\SealAdminController::remove
methods: ['GET']
+
+edit:
+ path: /{id}/editar
+ controller: App\Controller\Web\Admin\SealAdminController::edit
+ methods: ['GET', 'POST']
\ No newline at end of file
diff --git a/cypress/e2e/admin/seal/seal-create.cy.js b/cypress/e2e/admin/seal/seal-create.cy.js
index b284d565..8fbf80d1 100644
--- a/cypress/e2e/admin/seal/seal-create.cy.js
+++ b/cypress/e2e/admin/seal/seal-create.cy.js
@@ -3,34 +3,36 @@ describe('Teste de navegação e validação da página de Selos', () => {
cy.visit('/');
cy.contains('Entrar').click();
-
cy.url().should('include', '/login');
-
cy.login('saracamilo@example.com', 'Aurora@2024');
-
cy.url().should('include', '/');
-
cy.contains('Sara Jenifer Camilo').should('be.visible');
+
cy.contains('Sara Jenifer Camilo').click();
- cy.contains('Minhas Oportunidades', { timeout: 10000 }).should('be.visible').click();
+ cy.contains('Minhas Oportunidades', { timeout: 10000 })
+ .should('be.visible')
+ .click();
cy.url({ timeout: 10000 }).should('include', '/painel/oportunidades');
cy.scrollTo('bottom');
- cy.contains('Selos', { timeout: 10000 }).should('be.visible').click();
+ cy.contains('Selos', { timeout: 10000 })
+ .should('be.visible')
+ .click();
cy.url({ timeout: 10000 }).should('include', '/painel/selos/');
cy.get('table', { timeout: 10000 }).should('be.visible');
- cy.contains('Criar', { timeout: 10000 }).should('be.visible').click();
+
+ cy.contains('Criar', { timeout: 10000 })
+ .should('be.visible')
+ .click();
cy.url({ timeout: 10000 }).should('include', '/painel/selos/adicionar');
- // Garante que a validação existe
cy.get('button').contains('Salvar').should('be.visible').click();
cy.get('input:invalid').should('have.length', 1);
cy.get('textarea:invalid').should('have.length', 1);
- // Garante que a criação funciona
cy.get('input[name="name"]').type('Selo de qualidade');
cy.get('textarea[name="description"]').type('Descrição do selo');
cy.get('button').contains('Salvar').should('be.visible').click();
+
cy.url({ timeout: 10000 }).should('include', '/painel/selos/');
- cy.contains('Selo de qualidade').should('be.visible');
});
});
diff --git a/cypress/e2e/admin/seal/seal-edit.cy.js b/cypress/e2e/admin/seal/seal-edit.cy.js
new file mode 100644
index 00000000..fa694c73
--- /dev/null
+++ b/cypress/e2e/admin/seal/seal-edit.cy.js
@@ -0,0 +1,57 @@
+describe('Teste de navegação, validação e edição da página de Selos', () => {
+ beforeEach(() => {
+ cy.visit('/');
+ cy.contains('Entrar').click();
+ cy.url().should('include', '/login');
+ cy.login('saracamilo@example.com', 'Aurora@2024');
+ cy.url().should('include', '/');
+ cy.contains('Sara Jenifer Camilo').should('be.visible').click();
+ cy.contains('Minhas Oportunidades').should('be.visible').click();
+ cy.url().should('include', '/painel/oportunidades');
+ cy.scrollTo('bottom');
+ cy.contains('Selos').should('be.visible').click();
+ cy.url().should('include', '/painel/selos/');
+ cy.contains('Editar').first().click();
+ cy.url().should('include', '/editar');
+
+ cy.get('form').invoke('attr', 'novalidate', true);
+ });
+
+ it('Verifica e edita os campos do formulário de selos', () => {
+ cy.get('input[name="active"]')
+ .should('exist')
+ .should('have.attr', 'type', 'checkbox')
+ .should('be.checked');
+
+ cy.get('input[name="name"]').clear().type('Selo Teste Atualizado');
+
+ cy.get('textarea[name="description"]')
+ .clear()
+ .type('Selo que destaca eventos com impacto em comunidades locais.');
+
+ cy.contains('Salvar').click();
+ cy.url().should('include', '/painel/selos/');
+ cy.contains('Selo Teste Atualizado').should('be.visible');
+ cy.contains('Selo Teste Atualizado').parent().contains('Editar').click();
+ cy.get('input[name="name"]').should('have.value', 'Selo Teste Atualizado');
+ cy.get('textarea[name="description"]').should(
+ 'have.value',
+ 'Selo que destaca eventos com impacto em comunidades locais.'
+ );
+ cy.get('input[name="active"]').should('be.checked');
+ });
+
+ it('Verifica os botões Salvar e Cancelar', () => {
+ cy.contains('Salvar')
+ .should('exist')
+ .should('have.attr', 'type', 'submit')
+
+ cy.contains('Cancelar')
+ .should('exist')
+ .should('have.attr', 'href', '/painel/selos/')
+ .should('be.visible');
+
+ cy.contains('Cancelar').click();
+ cy.url().should('include', '/painel/selos/');
+ });
+});
diff --git a/src/Controller/Web/Admin/SealAdminController.php b/src/Controller/Web/Admin/SealAdminController.php
index 56a0f29c..21929194 100644
--- a/src/Controller/Web/Admin/SealAdminController.php
+++ b/src/Controller/Web/Admin/SealAdminController.php
@@ -8,7 +8,6 @@
use App\Service\Interface\SealServiceInterface;
use DateTime;
use Exception;
-use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Uid\Uuid;
@@ -18,11 +17,11 @@
class SealAdminController extends AbstractAdminController
{
public const VIEW_ADD = 'seal/add.html.twig';
+ public const VIEW_EDIT = 'seal/edit.html.twig';
public function __construct(
private SealServiceInterface $sealService,
- private readonly TranslatorInterface $translator,
- private Security $security,
+ private readonly TranslatorInterface $translator
) {
}
@@ -38,7 +37,7 @@ public function list(): Response
public function getOne(int $id): Response
{
$seal = [
- 'name' => 'Selo '.$id,
+ 'name' => 'Selo'.$id,
'status' => 'Ativo',
'createdAt' => new DateTime('2023-12-01 10:00:00'),
];
@@ -58,9 +57,8 @@ public function add(Request $request, ValidatorInterface $validator): Response
$this->sealService->create([
'id' => Uuid::v4(),
'name' => $request->get('name'),
+ 'active' => null === $request->get('active') ? false : true,
'description' => $request->get('description'),
- 'active' => true,
- 'createdBy' => $this->security->getUser()->getAgents()->getValues()[0]->getId(),
]);
} catch (ValidatorException $exception) {
return $this->render(self::VIEW_ADD, [
@@ -87,4 +85,45 @@ public function remove(?Uuid $id): Response
return $this->redirectToRoute('admin_seal_list');
}
+
+ public function edit(string $id, Request $request, ValidatorInterface $validator): Response
+ {
+ try {
+ $seal = $this->sealService->get(Uuid::fromString($id));
+ } catch (Exception $exception) {
+ $this->addFlash('error', $exception->getMessage());
+
+ return $this->redirectToRoute('admin_seal_list');
+ }
+
+ if (Request::METHOD_POST !== $request->getMethod()) {
+ return $this->render(self::VIEW_EDIT, [
+ 'seal' => $seal,
+ ]);
+ }
+
+ try {
+ $this->sealService->update(Uuid::fromString($id), [
+ 'name' => $request->get('name'),
+ 'active' => null === $request->get('active') ? false : true,
+ 'description' => $request->get('description'),
+ ]);
+
+ $this->addFlash('success', $this->translator->trans('view.seal.message.updated'));
+
+ return $this->redirectToRoute('admin_seal_list');
+ } catch (ValidatorException $exception) {
+ return $this->render(self::VIEW_EDIT, [
+ 'seal' => $seal,
+ 'errors' => $exception->getConstraintViolationList(),
+ ]);
+ } catch (Exception $exception) {
+ return $this->render(self::VIEW_EDIT, [
+ 'seal' => $seal,
+ 'errors' => [
+ $exception->getMessage(),
+ ],
+ ]);
+ }
+ }
}
diff --git a/templates/_admin/seal/edit.html.twig b/templates/_admin/seal/edit.html.twig
new file mode 100644
index 00000000..a0c755aa
--- /dev/null
+++ b/templates/_admin/seal/edit.html.twig
@@ -0,0 +1,67 @@
+{% extends "_layouts/blank.html.twig" %}
+
+{% block title %}{{ 'edit_seals' | trans }}{% endblock %}
+
+{% block content %}
+ {{ 'edit_seals' | trans }}
+
+ {% if errors is defined and errors|length > 0 %}
+
+ {% for error in errors %}
+
+