Merge pull request 'Add drag and drop sorting for slides' (#8) from feature/slide-drag-drop into main
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
commit
4034a65498
8 files changed
+301
-8
No files matched your search
@@ -182,6 +182,46 @@ class AdminControllerTest extends TestCase
|
||||
$this->assertSame(1, $this->slidesTable()->get($first->id)->position);
|
||||
}
|
||||
|
||||
public function testReorderSlidesByDragAndDrop(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$a = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$b = $this->createSlide($poll, Slide::TYPE_SCALE);
|
||||
$c = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$positions = fn(): array => array_map(
|
||||
fn($s) => $s->id,
|
||||
$this->slidesTable()->listForPoll($poll->id),
|
||||
);
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains('data-sortable=');
|
||||
$this->assertResponseContains('data-slide-id="' . $a->id . '"');
|
||||
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => [$c->id, $a->id, $b->id]]);
|
||||
$this->assertResponseOk();
|
||||
$this->assertTrue(json_decode((string)$this->_response->getBody(), true)['ok']);
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
$this->assertSame(1, $this->slidesTable()->get($c->id)->position);
|
||||
|
||||
// Same order again is fine (idempotent).
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => [$c->id, $a->id, $b->id]]);
|
||||
$this->assertResponseOk();
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
|
||||
// Incomplete, duplicated or foreign ids change nothing.
|
||||
[$other] = $this->createPoll('Andere');
|
||||
$foreign = $this->createSlide($other, Slide::TYPE_OPEN);
|
||||
foreach ([[$a->id, $b->id], [$a->id, $a->id, $b->id], [$a->id, $b->id, $foreign->id], []] as $ids) {
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => $ids]);
|
||||
$this->assertResponseCode(409);
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
}
|
||||
$this->assertSame(1, $this->slidesTable()->get($foreign->id)->position);
|
||||
}
|
||||
|
||||
public function testPresentStartsWithFirstSlideAndControlNavigates(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
|
||||
Reference in new issue
Block a user