test element child list

This commit is contained in:
Yisroel Baum 2026-05-26 20:12:14 +03:00
parent d950fe55dd
commit aa746fe3f0
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 137 additions and 15 deletions

View file

@ -27,11 +27,31 @@ class ElementsEndpointTest extends TestCase
title: 'Baderech HaAvodah',
parentElement: null,
));
$firstChildElement = $elementRepository->create(new CreateElementDto(
set: $set,
title: 'Avodah Foundations',
parentElement: $element,
));
$secondChildElement = $elementRepository->create(new CreateElementDto(
set: $set,
title: 'Daily Practice',
parentElement: $element,
));
$response = $this->getJson("/api/elements/{$element->getId()}");
$response->assertOk();
$response->assertExactJson([
'childElements' => [
[
'id' => $firstChildElement->getId(),
'title' => 'Avodah Foundations',
],
[
'id' => $secondChildElement->getId(),
'title' => 'Daily Practice',
],
],
'element' => [
'id' => $element->getId(),
'title' => 'Baderech HaAvodah',

View file

@ -25,7 +25,18 @@ class ElementControllerTest extends TestCase
public function testShowReturnsElementPayload(): void
{
$element = $this->createElement('Baderech HaAvodah');
$set = $this->createSet(1, 'Baderech');
$element = $this->createElement($set, 'Baderech HaAvodah', null);
$firstChildElement = $this->createElement(
$set,
'Avodah Foundations',
$element,
);
$secondChildElement = $this->createElement(
$set,
'Daily Practice',
$element,
);
$response = $this->controller->show($element->getId());
@ -33,6 +44,16 @@ class ElementControllerTest extends TestCase
$body = json_decode($response->getContent(), true);
$this->assertSame($element->getId(), $body['element']['id']);
$this->assertSame('Baderech HaAvodah', $body['element']['title']);
$this->assertSame([
[
'id' => $firstChildElement->getId(),
'title' => 'Avodah Foundations',
],
[
'id' => $secondChildElement->getId(),
'title' => 'Daily Practice',
],
], $body['childElements']);
}
public function testShowReturns400WhenIdMissing(): void
@ -57,19 +78,25 @@ class ElementControllerTest extends TestCase
);
}
private function createElement(string $title): Element
private function createSet(int $id, string $name): DomainSet
{
$set = new DomainSet(
id: 1,
name: 'Baderech',
description: 'Baderech description',
return new DomainSet(
id: $id,
name: $name,
description: "$name description",
iconImageUrl: '/assets/baderech-icon.png',
);
}
private function createElement(
DomainSet $set,
string $title,
?Element $parentElement,
): Element {
return $this->elementRepo->create(new CreateElementDto(
set: $set,
title: $title,
parentElement: null,
parentElement: $parentElement,
));
}
}

View file

@ -26,17 +26,76 @@ class GetElementTest extends TestCase
public function testReturnsElementWhenFound(): void
{
$element = $this->createElement('Baderech HaAvodah');
$set = $this->createSet(1, 'Baderech');
$element = $this->createElement(
$set,
'Baderech HaAvodah',
null,
);
$foundElement = $this->getElement->execute(new GetElementRequest(
$result = $this->getElement->execute(new GetElementRequest(
id: $element->getId(),
));
$foundElement = $result->getElement();
$this->assertInstanceOf(Element::class, $foundElement);
$this->assertSame($element->getId(), $foundElement->getId());
$this->assertSame('Baderech HaAvodah', $foundElement->getTitle());
}
public function testReturnsDirectChildElements(): void
{
$set = $this->createSet(1, 'Baderech');
$parentElement = $this->createElement(
$set,
'Baderech HaAvodah',
null,
);
$firstChildElement = $this->createElement(
$set,
'Avodah Foundations',
$parentElement,
);
$secondChildElement = $this->createElement(
$set,
'Daily Practice',
$parentElement,
);
$this->createElement(
$set,
'Nested Practice',
$firstChildElement,
);
$otherSet = $this->createSet(2, 'Daily Learning');
$otherParentElement = $this->createElement(
$otherSet,
'Other Parent',
null,
);
$this->createElement(
$otherSet,
'Other Child',
$otherParentElement,
);
$result = $this->getElement->execute(new GetElementRequest(
id: $parentElement->getId(),
));
$childElements = $result->getChildElements();
$this->assertCount(2, $childElements);
$this->assertSame(
$firstChildElement->getId(),
$childElements[0]->getId(),
);
$this->assertSame('Avodah Foundations', $childElements[0]->getTitle());
$this->assertSame(
$secondChildElement->getId(),
$childElements[1]->getId(),
);
$this->assertSame('Daily Practice', $childElements[1]->getTitle());
}
public function testThrowsWhenIdMissing(): void
{
$this->expectException(BadRequestException::class);
@ -53,19 +112,25 @@ class GetElementTest extends TestCase
$this->getElement->execute(new GetElementRequest(id: 999));
}
private function createElement(string $title): Element
private function createSet(int $id, string $name): DomainSet
{
$set = new DomainSet(
id: 1,
name: 'Baderech',
description: 'Baderech description',
return new DomainSet(
id: $id,
name: $name,
description: "$name description",
iconImageUrl: '/assets/baderech-icon.png',
);
}
private function createElement(
DomainSet $set,
string $title,
?Element $parentElement,
): Element {
return $this->elementRepo->create(new CreateElementDto(
set: $set,
title: $title,
parentElement: null,
parentElement: $parentElement,
));
}
}

View file

@ -41,5 +41,15 @@ describe('media page sets', () => {
cy.location('pathname').should('eq', '/element/1')
cy.get('[data-cy="element-page"]').should('be.visible')
cy.contains('h1', 'Baderech HaAvodah').should('be.visible')
cy.get('[data-cy="child-element-list"]').should('be.visible')
cy.contains('[data-cy="child-element-link"]', 'Avodah Foundations')
.should('have.attr', 'href', '/element/2')
cy.contains('[data-cy="child-element-link"]', 'Daily Practice')
.should('have.attr', 'href', '/element/3')
cy.contains('[data-cy="child-element-link"]', 'Avodah Foundations')
.click()
cy.location('pathname').should('eq', '/element/2')
cy.contains('h1', 'Avodah Foundations').should('be.visible')
})
})