diff --git a/backend/tests/Feature/ElementsEndpointTest.php b/backend/tests/Feature/ElementsEndpointTest.php index 8f24235..a24a6c8 100644 --- a/backend/tests/Feature/ElementsEndpointTest.php +++ b/backend/tests/Feature/ElementsEndpointTest.php @@ -27,6 +27,7 @@ class ElementsEndpointTest extends TestCase title: 'Baderech HaAvodah', description: 'A structured path for growth', richText: '
A structured path for growth
', + pdfPath: '/assets/pdfs/baderech.pdf', parentElement: null, )); $firstChildElement = $elementRepository->create(new CreateElementDto( @@ -34,6 +35,7 @@ class ElementsEndpointTest extends TestCase title: 'Avodah Foundations', description: 'Foundations for steady avodah', richText: 'Foundations rich text
', + pdfPath: '/assets/pdfs/foundations.pdf', parentElement: $element, )); $secondChildElement = $elementRepository->create(new CreateElementDto( @@ -41,6 +43,7 @@ class ElementsEndpointTest extends TestCase title: 'Daily Practice', description: 'Daily practices for growth', richText: 'Daily practice rich text
', + pdfPath: null, parentElement: $element, )); @@ -65,6 +68,7 @@ class ElementsEndpointTest extends TestCase 'title' => 'Baderech HaAvodah', 'description' => 'A structured path for growth', 'richText' => 'A structured path for growth
', + 'pdfPath' => '/assets/pdfs/baderech.pdf', ], ]); } diff --git a/backend/tests/Unit/Controllers/ElementControllerTest.php b/backend/tests/Unit/Controllers/ElementControllerTest.php index 569835e..d9ffe2f 100644 --- a/backend/tests/Unit/Controllers/ElementControllerTest.php +++ b/backend/tests/Unit/Controllers/ElementControllerTest.php @@ -31,6 +31,7 @@ class ElementControllerTest extends TestCase 'Baderech HaAvodah', 'A structured path for growth', 'A structured path for growth
', + '/assets/pdfs/baderech.pdf', null, ); $firstChildElement = $this->createElement( @@ -38,6 +39,7 @@ class ElementControllerTest extends TestCase 'Avodah Foundations', 'Foundations for steady avodah', 'Foundations rich text
', + '/assets/pdfs/foundations.pdf', $element, ); $secondChildElement = $this->createElement( @@ -45,6 +47,7 @@ class ElementControllerTest extends TestCase 'Daily Practice', 'Daily practices for growth', 'Daily practice rich text
', + null, $element, ); @@ -62,6 +65,10 @@ class ElementControllerTest extends TestCase 'A structured path for growth
', $body['element']['richText'], ); + $this->assertSame( + '/assets/pdfs/baderech.pdf', + $body['element']['pdfPath'], + ); $this->assertSame([ [ 'id' => $firstChildElement->getId(), @@ -113,6 +120,7 @@ class ElementControllerTest extends TestCase string $title, string $description, string $richText, + ?string $pdfPath, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( @@ -120,6 +128,7 @@ class ElementControllerTest extends TestCase title: $title, description: $description, richText: $richText, + pdfPath: $pdfPath, parentElement: $parentElement, )); } diff --git a/backend/tests/Unit/Element/ElementTest.php b/backend/tests/Unit/Element/ElementTest.php index 8c09251..7808344 100644 --- a/backend/tests/Unit/Element/ElementTest.php +++ b/backend/tests/Unit/Element/ElementTest.php @@ -21,6 +21,7 @@ class ElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: null, set: $set, parentElement: null, ); @@ -29,6 +30,7 @@ class ElementTest extends TestCase title: 'Child', description: 'Child description', richText: 'Child rich text
', + pdfPath: '/assets/pdfs/child.pdf', set: $set, parentElement: $rootElement, ); @@ -43,8 +45,13 @@ class ElementTest extends TestCase 'Child rich text
', $childElement->getRichText(), ); + $this->assertSame( + '/assets/pdfs/child.pdf', + $childElement->getPdfPath(), + ); $this->assertSame($set, $childElement->getSet()); $this->assertSame($rootElement, $childElement->getParentElement()); + $this->assertNull($rootElement->getPdfPath()); $this->assertNull($rootElement->getParentElement()); } } diff --git a/backend/tests/Unit/Element/UseCases/CreateElementTest.php b/backend/tests/Unit/Element/UseCases/CreateElementTest.php index 55458eb..2b34873 100644 --- a/backend/tests/Unit/Element/UseCases/CreateElementTest.php +++ b/backend/tests/Unit/Element/UseCases/CreateElementTest.php @@ -49,6 +49,7 @@ class CreateElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: '/assets/pdfs/root.pdf', parentElementId: null, )); @@ -56,6 +57,7 @@ class CreateElementTest extends TestCase $this->assertSame('Root', $element->getTitle()); $this->assertSame('Root description', $element->getDescription()); $this->assertSame('Root rich text
', $element->getRichText()); + $this->assertSame('/assets/pdfs/root.pdf', $element->getPdfPath()); $this->assertSame($set->getId(), $element->getSet()->getId()); $this->assertNull($element->getParentElement()); } @@ -69,6 +71,7 @@ class CreateElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: null, parentElementId: null, ) ); @@ -79,6 +82,7 @@ class CreateElementTest extends TestCase title: 'Child', description: 'Child description', richText: 'Child rich text
', + pdfPath: '/assets/pdfs/child.pdf', parentElementId: $rootElement->getId(), ) ); @@ -92,6 +96,10 @@ class CreateElementTest extends TestCase 'Child rich text
', $childElement->getRichText(), ); + $this->assertSame( + '/assets/pdfs/child.pdf', + $childElement->getPdfPath(), + ); $this->assertSame( $rootElement->getId(), $childElement->getParentElement()->getId(), @@ -107,11 +115,29 @@ class CreateElementTest extends TestCase title: 'Root', description: null, richText: null, + pdfPath: null, parentElementId: null, )); $this->assertSame('', $element->getDescription()); $this->assertSame('', $element->getRichText()); + $this->assertNull($element->getPdfPath()); + } + + public function testCreatesElementWithNullPdfPathWhenBlank(): void + { + $set = $this->createSet('Daily learning'); + + $element = $this->createElement->execute(new CreateElementRequest( + setId: $set->getId(), + title: 'Root', + description: 'Root description', + richText: 'Root rich text
', + pdfPath: '', + parentElementId: null, + )); + + $this->assertNull($element->getPdfPath()); } public function testThrowsWhenSetIdMissing(): void @@ -124,6 +150,7 @@ class CreateElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: null, parentElementId: null, )); } @@ -138,6 +165,7 @@ class CreateElementTest extends TestCase title: null, description: 'Root description', richText: 'Root rich text
', + pdfPath: null, parentElementId: null, )); } @@ -152,6 +180,7 @@ class CreateElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: null, parentElementId: null, )); } @@ -170,6 +199,7 @@ class CreateElementTest extends TestCase title: 'Child', description: 'Child description', richText: 'Child rich text
', + pdfPath: null, parentElementId: 99, )); } @@ -182,6 +212,7 @@ class CreateElementTest extends TestCase title: 'Root', description: 'Root description', richText: 'Root rich text
', + pdfPath: null, parentElementId: null, )); @@ -195,6 +226,7 @@ class CreateElementTest extends TestCase title: 'Another root', description: 'Another root description', richText: 'Another root rich text
', + pdfPath: null, parentElementId: null, )); } @@ -209,6 +241,7 @@ class CreateElementTest extends TestCase title: 'Parent root', description: 'Parent root description', richText: 'Parent root rich text
', + pdfPath: null, parentElementId: null, ) ); @@ -223,6 +256,7 @@ class CreateElementTest extends TestCase title: 'Invalid child', description: 'Invalid child description', richText: 'Invalid child rich text
', + pdfPath: null, parentElementId: $parentElement->getId(), )); } diff --git a/backend/tests/Unit/Element/UseCases/GetElementTest.php b/backend/tests/Unit/Element/UseCases/GetElementTest.php index 71c67a0..2b11d63 100644 --- a/backend/tests/Unit/Element/UseCases/GetElementTest.php +++ b/backend/tests/Unit/Element/UseCases/GetElementTest.php @@ -32,6 +32,7 @@ class GetElementTest extends TestCase 'Baderech HaAvodah', 'A structured path for growth', 'A structured path for growth
', + '/assets/pdfs/baderech.pdf', null, ); @@ -51,6 +52,10 @@ class GetElementTest extends TestCase 'A structured path for growth
', $foundElement->getRichText(), ); + $this->assertSame( + '/assets/pdfs/baderech.pdf', + $foundElement->getPdfPath(), + ); } public function testReturnsDirectChildElements(): void @@ -61,6 +66,7 @@ class GetElementTest extends TestCase 'Baderech HaAvodah', 'A structured path for growth', 'A structured path for growth
', + '/assets/pdfs/baderech.pdf', null, ); $firstChildElement = $this->createElement( @@ -68,6 +74,7 @@ class GetElementTest extends TestCase 'Avodah Foundations', 'Foundations for steady avodah', 'Foundations rich text
', + '/assets/pdfs/foundations.pdf', $parentElement, ); $secondChildElement = $this->createElement( @@ -75,6 +82,7 @@ class GetElementTest extends TestCase 'Daily Practice', 'Daily practices for growth', 'Daily practice rich text
', + null, $parentElement, ); $this->createElement( @@ -82,6 +90,7 @@ class GetElementTest extends TestCase 'Nested Practice', 'Nested description', 'Nested rich text
', + null, $firstChildElement, ); $otherSet = $this->createSet(2, 'Daily Learning'); @@ -91,12 +100,14 @@ class GetElementTest extends TestCase 'Other parent description', 'Other parent rich text
', null, + null, ); $this->createElement( $otherSet, 'Other Child', 'Other child description', 'Other child rich text
', + null, $otherParentElement, ); @@ -157,6 +168,7 @@ class GetElementTest extends TestCase string $title, string $description, string $richText, + ?string $pdfPath, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( @@ -164,6 +176,7 @@ class GetElementTest extends TestCase title: $title, description: $description, richText: $richText, + pdfPath: $pdfPath, parentElement: $parentElement, )); } diff --git a/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts b/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts index 4dda0e4..5901c8e 100644 --- a/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts +++ b/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts @@ -46,6 +46,10 @@ describe('media page sets', () => { .should('be.visible') cy.contains('strong', 'Move steadily').should('be.visible') }) + cy.contains('[data-cy="element-pdf-link"]', 'View PDF') + .should('be.visible') + .and('have.attr', 'href', '/assets/pdfs/baderech.pdf') + .and('have.attr', 'target', '_blank') cy.get('[data-cy="child-element-list"]').should('be.visible') cy.get('[data-cy="child-element-list"]') .should( @@ -78,5 +82,6 @@ describe('media page sets', () => { 'contain.text', 'Avodah foundations begin with honest awareness', ) + cy.get('[data-cy="element-pdf-link"]').should('not.exist') }) })