feat(KAN-24): rebuild project creation flow
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Models\ProjectTemplate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectCreationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
#[DataProvider('missingSources')]
|
||||
public function test_creation_requires_the_selected_source(string $mode, string $field): void
|
||||
{
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->actingAs($user)->from(route('projects.create'))
|
||||
->post(route('projects.store'), ['creation_mode' => $mode, 'name' => 'New project', 'key' => 'NEW'])
|
||||
->assertRedirect(route('projects.create'))->assertSessionHasErrors($field);
|
||||
$this->assertDatabaseMissing('projects', ['key' => 'NEW']);
|
||||
}
|
||||
|
||||
/** @return array<string, array{string, string}> */
|
||||
public static function missingSources(): array
|
||||
{
|
||||
return ['duplicate' => ['duplicate', 'source_project_id'], 'template' => ['template', 'source_template_id']];
|
||||
}
|
||||
|
||||
public function test_an_unpublished_template_cannot_be_used_to_create_a_project(): void
|
||||
{
|
||||
$user = User::factory()->admin()->create();
|
||||
$template = ProjectTemplate::factory()->create(['is_published' => false]);
|
||||
$this->actingAs($user)->post(route('projects.store'), [
|
||||
'creation_mode' => 'template', 'source_template_id' => $template->id, 'name' => 'New project', 'key' => 'NEW',
|
||||
])->assertSessionHasErrors('source_template_id');
|
||||
$this->assertDatabaseMissing('projects', ['key' => 'NEW']);
|
||||
}
|
||||
|
||||
public function test_creation_page_rendering_and_localization(): void
|
||||
{
|
||||
$process = new Process(['node', 'tests/Fixtures/project-creation.mjs'], base_path());
|
||||
$process->setTimeout(60);
|
||||
$process->run();
|
||||
$this->assertTrue($process->isSuccessful(), $process->getOutput().$process->getErrorOutput());
|
||||
$this->assertStringContainsString('Project creation rendering checks passed.', $process->getOutput());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user