레이아웃 편집기 spec 중 저장(PUT)까지 수행하는 것들이 제품 화면에 편집 결과를 영속시켜, 실행할 때마다 개발 사이트에 노드가 누적됐다(home 에 빈 표 7개, 관리자 대시보드에 빈 차트 5개). spec 안에 "추가한 노드 삭제 후 재저장" 원복을 넣어도 소용이 없었다 — 원복 후에도 레이아웃이 오염 시점과 정확히 같은 크기로 되돌아왔다. 원복에 기대는 대신 저장 대상 자체를 E2E 전용 시드 화면으로 분리한다. 시드 화면은 활성 템플릿 디렉토리에만 설치되므로 배포 원본과 릴리스 산출물은 변하지 않는다. globalSetup 이 매 실행 fixture 원본으로 덮어써 회차 간 누적이 성립하지 않으므로 저장 spec 에 원복 절차가 필요 없다. 설치는 레이아웃 파일과 라우트, DB 행 세 가지를 함께 다루되 시드 행만 건드린다 — 전체 재동기화를 쓰면 편집기로 저장한(파일에 없는) 변경이 실행할 때마다 사라지기 때문이다. 전수 실행에서 드러난 기존 실패도 함께 처리했다. 35건 중 27건은 절전·부하 아티팩트였고 나머지는 원인을 확정해 고쳤다. 템플릿 식별자 자리에 모듈 id 를 넣어 라우트 트리가 비어 있었고, "캔버스 텍스트가 길어진다"는 대리 지표가 렌더 여부와 무관했으며(정상 렌더에도 짧아진다), 팔레트 삽입 위치가 잠금 서브트리 안이면 선택이 조상으로 밀려 노드를 지목할 수 없었고, 상태 개수 단언이 상태 추가로 낡았고, if 게이트상 그 탭에 등록되지 않는 소스를 refetch 하고 있었고, 무통신 구간이 오지 않는 관리자 화면에 networkidle 을 기다렸고, 테스트 종료 후 도착한 route 콜백이 워커를 중단시켰고, 같은 설정 화면에 저장하는 테스트들이 병렬로 충돌했다. 측정 방법에서 반복해 틀린 지점들은 E2E 가이드에 표로 남겼다 — 가림은 가시성 판정으로 잡히지 않고, 길이 증감은 렌더 신호가 아니며, 총 개수 단언은 스펙이 늘면 깨지고, networkidle 은 실시간 연결이 있는 화면에서 오지 않는다.
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Repositories;
|
|
|
|
use App\Models\Template;
|
|
use App\Models\TemplateLayout;
|
|
use App\Repositories\LayoutRepository;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* LayoutRepository::deleteByName 단위 테스트.
|
|
*
|
|
* 이름으로 재등록될 수 있는 레이아웃(파일 → DB 동기화 대상)은 soft delete 잔여 행이 남으면
|
|
* 재등록이 충돌하므로 `forceDelete` 여야 한다. 삭제 범위가 템플릿 경계를 넘지 않는지도 함께 잠근다.
|
|
*/
|
|
class LayoutRepositoryDeleteByNameTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private LayoutRepository $repository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->repository = app(LayoutRepository::class);
|
|
}
|
|
|
|
/**
|
|
* @effects delete_by_name_force_deletes_matching_layout
|
|
*/
|
|
#[Test]
|
|
public function delete_by_name_force_deletes_matching_layout(): void
|
|
{
|
|
$template = Template::factory()->create();
|
|
TemplateLayout::factory()->create([
|
|
'template_id' => $template->id,
|
|
'name' => 'e2e_sandbox',
|
|
]);
|
|
|
|
$this->assertTrue($this->repository->deleteByName($template->id, 'e2e_sandbox'));
|
|
|
|
// soft delete 잔여 행이 남으면 같은 이름 재등록이 유니크 제약과 충돌한다.
|
|
$this->assertFalse(
|
|
TemplateLayout::withTrashed()
|
|
->where('template_id', $template->id)
|
|
->where('name', 'e2e_sandbox')
|
|
->exists()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @effects delete_by_name_returns_false_when_absent
|
|
*/
|
|
#[Test]
|
|
public function delete_by_name_returns_false_when_absent(): void
|
|
{
|
|
$template = Template::factory()->create();
|
|
|
|
$this->assertFalse($this->repository->deleteByName($template->id, 'no_such_layout'));
|
|
}
|
|
|
|
/**
|
|
* @effects delete_by_name_does_not_touch_same_name_in_other_template
|
|
*/
|
|
#[Test]
|
|
public function delete_by_name_does_not_touch_same_name_in_other_template(): void
|
|
{
|
|
$target = Template::factory()->create();
|
|
$other = Template::factory()->create();
|
|
|
|
TemplateLayout::factory()->create(['template_id' => $target->id, 'name' => 'e2e_sandbox']);
|
|
TemplateLayout::factory()->create(['template_id' => $other->id, 'name' => 'e2e_sandbox']);
|
|
|
|
$this->repository->deleteByName($target->id, 'e2e_sandbox');
|
|
|
|
$this->assertTrue(
|
|
TemplateLayout::where('template_id', $other->id)->where('name', 'e2e_sandbox')->exists(),
|
|
'다른 템플릿의 동명 레이아웃은 삭제되지 않아야 한다'
|
|
);
|
|
}
|
|
}
|