Skip to content

Commit 7e5bc4c

Browse files
committed
fix(create): centralize insert-at-position handling and close add-card form after creation
- Let CardService::create() decide when to reorder based on the requested order, so all card creation endpoints behave consistently. - Close the inline add-card form after a card is successfully created to prevent it from covering the new card and fix flaky Cypress tests. Signed-off-by: Theo <36564257+theoholl@users.noreply.github.com>
1 parent 7e606fa commit 7e5bc4c

5 files changed

Lines changed: 8 additions & 13 deletions

File tree

cypress/e2e/cardFeatures.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ describe('Card', function () {
110110
cy.get('.stack__card-add input[type="text"]').type(title)
111111
cy.get('.stack__card-add input[type="submit"]').click()
112112
cy.wait('@createCard')
113-
cy.get('.stack__card-add input[type="text"]').type('{esc}')
114113
})
115114
}
116115

@@ -380,13 +379,6 @@ describe('Card', function () {
380379
cy.get('.stack__card-add form input[type=submit]')
381380
.first().click()
382381
cy.get(`.card:contains("${newCardTitle}")`).should('be.visible').click()
383-
cy.get('body').then(($body) => {
384-
const addCardInput = $body.find('.stack__card-add form input#new-stack-input-main')
385-
if (addCardInput.length) {
386-
cy.wrap(addCardInput.first()).type('{esc}')
387-
}
388-
})
389-
cy.get('.stack__card-add form').should('not.exist')
390382

391383
// Add delay to ensure the events are bound
392384
cy.wait(1000)

lib/Controller/CardOcsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function create(string $title, int $stackId, ?int $boardId = null, ?strin
4848
if (!$owner) {
4949
$owner = $this->userId;
5050
}
51-
$card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate, $startdate, $color, insertAtPosition: $order !== 999);
51+
$card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate, $startdate, $color);
5252

5353
// foreach ($labels as $label) {
5454
// $this->assignLabel($card->getId(), $label);

lib/Service/CardService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function findCalendarEntries(int $boardId): array {
189189
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
190190
* @throws BadrequestException
191191
*/
192-
public function create(string $title, int $stackId, string $type, int $order, string $owner, string $description = '', $duedate = null, $startdate = null, ?string $color = null, bool $insertAtPosition = false): Card {
192+
public function create(string $title, int $stackId, string $type, int $order, string $owner, string $description = '', $duedate = null, $startdate = null, ?string $color = null): Card {
193193
$this->cardServiceValidator->check(compact('title', 'stackId', 'type', 'order', 'owner'));
194194

195195
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
@@ -207,9 +207,11 @@ public function create(string $title, int $stackId, string $type, int $order, st
207207
$card->setStartdate($startdate);
208208
$card->setColor($color);
209209

210-
if (!$insertAtPosition) {
210+
if ($order === 999) {
211+
// Append to the end of the stack
211212
$card = $this->cardMapper->insert($card);
212213
} else {
214+
// Insert at the requested position and shift the surrounding cards
213215
$this->connection->beginTransaction();
214216
try {
215217
$card = $this->cardMapper->insert($card);

src/components/board/StackCardAdd.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default {
108108
...(this.addAtTop ? { order: 0 } : {}),
109109
})
110110
this.title = ''
111+
this.visible = false
111112
this.$emit('created', newCard)
112113
if (!this.cardDetailsInModal) {
113114
this.$router.push({ name: 'card', params: { cardId: newCard.id } })

tests/unit/Service/CardServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function testCreateAtTopReordersCardsInTransaction(): void {
284284
->with(123)
285285
->willReturn($stack);
286286

287-
$createdCard = $this->cardService->create('New card', 123, 'plain', 0, 'admin', insertAtPosition: true);
287+
$createdCard = $this->cardService->create('New card', 123, 'plain', 0, 'admin');
288288

289289
$this->assertSame(0, $createdCard->getOrder());
290290
$this->assertSame(1, $firstCard->getOrder());
@@ -313,7 +313,7 @@ public function testCreateAtTopRollsBackWhenReorderingFails(): void {
313313
->willThrowException(new \RuntimeException('Could not reorder cards'));
314314

315315
$this->expectException(\RuntimeException::class);
316-
$this->cardService->create('New card', 123, 'plain', 0, 'admin', insertAtPosition: true);
316+
$this->cardService->create('New card', 123, 'plain', 0, 'admin');
317317
}
318318

319319
public function testClone() {

0 commit comments

Comments
 (0)