add break time entries and simplified time tracker ui

This commit is contained in:
Gregor Vostrak
2026-07-21 16:48:37 +02:00
parent c07c62bfab
commit 64ca1e9115
128 changed files with 6252 additions and 437 deletions

View File

@@ -4,7 +4,11 @@ declare(strict_types=1);
namespace Tests\Unit\Service\Import\Importers;
use App\Enums\TimeEntryType;
use App\Models\Client;
use App\Models\Organization;
use App\Models\Project;
use App\Models\Tag;
use App\Models\TimeEntry;
use App\Service\Import\Importers\ClockifyTimeEntriesImporter;
use App\Service\Import\Importers\DefaultImporter;
@@ -196,4 +200,35 @@ class ClockifyTimeEntriesImporterTest extends ImporterTestAbstract
}
$this->fail();
}
public function test_import_creates_break_time_entry_when_type_is_break(): void
{
// Arrange
// Clockify lets a break carry a project, task, tags and billable status, but those are
// meaningless for non-work time. The break must import stripped of all of them, and must
// NOT create the project/tag it referenced (which would be an orphan).
$organization = Organization::factory()->create();
$importer = new ClockifyTimeEntriesImporter;
$importer->init($organization);
$csv = <<<'CSV'
"Project","Client","Description","Task","User","Group","Email","Tags","Billable","Start Date","Start Time","End Date","End Time","Duration (h)","Duration (decimal)","Billable Rate (USD)","Billable Amount (USD)","Type"
"Break Project","Break Client","Lunch","Design","Peter Tester","","peter.test@email.test","Backend","Yes","03/04/2024","10:00:00 AM","03/04/2024","10:30:00 AM","00:30:00","0.50","0.00","0.00","Break"
CSV;
// Act
$importer->importData($csv, 'Europe/Vienna');
// Assert
$timeEntry = TimeEntry::query()->firstOrFail();
$this->assertSame(TimeEntryType::Break, $timeEntry->type);
$this->assertFalse($timeEntry->billable);
$this->assertNull($timeEntry->project_id);
$this->assertNull($timeEntry->task_id);
$this->assertNull($timeEntry->client_id);
$this->assertSame([], $timeEntry->tags);
// The break's project/tag/client must not have been created as orphans.
$this->assertSame(0, Project::query()->count());
$this->assertSame(0, Tag::query()->count());
$this->assertSame(0, Client::query()->count());
}
}

View File

@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Tests\Unit\Service\Import\Importers;
use App\Enums\TimeEntryType;
use App\Jobs\RecalculateSpentTimeForProject;
use App\Jobs\RecalculateSpentTimeForTask;
use App\Models\Organization;
use App\Models\TimeEntry;
use App\Service\Import\Importers\DefaultImporter;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\Importers\SolidtimeImporter;
@@ -75,6 +77,44 @@ class SolidtimeImporterTest extends ImporterTestAbstract
Queue::assertPushed(RecalculateSpentTimeForTask::class, 1);
}
public function test_import_of_test_file_with_type_column_imports_breaks(): void
{
// Arrange
$zipPath = $this->createTestZip('solidtime_import_test_2');
$timezone = 'Europe/Vienna';
$organization = Organization::factory()->create();
$importer = new SolidtimeImporter;
$importer->init($organization);
$data = file_get_contents($zipPath);
Queue::fake([
RecalculateSpentTimeForProject::class,
RecalculateSpentTimeForTask::class,
]);
// Act
$importer->importData($data, $timezone);
$report = $importer->getReport();
// Assert
$this->assertSame(3, $report->timeEntriesCreated);
$timeEntries = TimeEntry::all();
$this->assertCount(3, $timeEntries);
// Empty type value falls back to the default type (work)
$timeEntryWithoutType = $timeEntries->firstWhere('description', '');
$this->assertNotNull($timeEntryWithoutType);
$this->assertSame(TimeEntryType::Work, $timeEntryWithoutType->type);
$workEntry = $timeEntries->firstWhere('description', 'Working hard');
$this->assertNotNull($workEntry);
$this->assertSame(TimeEntryType::Work, $workEntry->type);
$breakEntry = $timeEntries->firstWhere('description', 'Lunch break');
$this->assertNotNull($breakEntry);
$this->assertSame(TimeEntryType::Break, $breakEntry->type);
$this->assertFalse($breakEntry->billable);
$this->assertNull($breakEntry->project_id);
$this->assertNull($breakEntry->task_id);
$this->assertSame([], $breakEntry->tags);
}
public function test_import_of_test_file_twice_succeeds(): void
{
// Arrange