trypost/tests/Feature/Automation/DetailTabsTest.php
Paulo Castellano 3e43da29e0 Add Workflow/Invocations/Metrics/Settings tabs to automations
Split the automation detail screen into four route-based tabs behind a
shared AutomationHeader:

- Workflow: the existing editor canvas.
- Invocations: a paginated, filterable run log with expandable per-node
  detail, a refresh control, and a loading state.
- Metrics: KPI cards, a runs-over-time @unovis chart with locale-aware
  date labels, and a posts-by-platform breakdown over a date range.
- Settings: rename, an activate/pause switch, and a danger-zone delete.

Invocations and Metrics report only real executions via a new
productionRuns scope, so manual test runs (dry or with real data) never
leak into the log or the charts. The now-unused excludingDryRuns scope
is removed.

Generated copy now flows the most-restrictive platform context through
the humanizer too, and the editor guide documents every available
expression grouped by source node.
2026-06-12 19:19:46 -03:00

95 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\UserWorkspace\Role;
use App\Models\Automation;
use App\Models\AutomationRun;
use App\Models\User;
use App\Models\Workspace;
beforeEach(function () {
$this->workspace = Workspace::factory()->create();
$this->user = User::factory()->create(['current_workspace_id' => $this->workspace->id]);
$this->workspace->members()->attach($this->user->id, ['role' => Role::Admin->value]);
$this->user->refresh();
$this->automation = Automation::factory()->for($this->workspace)->create();
});
it('redirects the bare automation URL to the workflow tab', function () {
$this->actingAs($this->user)
->get(route('app.automations.show', $this->automation->id))
->assertRedirect(route('app.automations.workflow', $this->automation->id));
});
it('renders the workflow editor on the workflow tab', function () {
$this->actingAs($this->user)
->get(route('app.automations.workflow', $this->automation->id))
->assertOk()
->assertInertia(fn ($page) => $page->component('automations/Form'));
});
it('renders the settings tab', function () {
$this->actingAs($this->user)
->get(route('app.automations.settings', $this->automation->id))
->assertOk()
->assertInertia(fn ($page) => $page->component('automations/Settings'));
});
it('renames the automation from settings without wiping the graph', function () {
$automation = Automation::factory()->for($this->workspace)->withScheduleTrigger()->create();
$originalNodes = $automation->nodes;
$this->actingAs($this->user)
->put(route('app.automations.update', $automation->id), ['name' => 'Renamed flow'])
->assertRedirect();
$automation->refresh();
expect($automation->name)->toBe('Renamed flow');
expect($automation->nodes)->toBe($originalNodes);
});
it('renders the invocations tab with a scroll-paginated list', function () {
AutomationRun::factory()->for($this->automation)->create();
$this->actingAs($this->user)
->get(route('app.automations.invocations', $this->automation->id))
->assertOk()
->assertInertia(fn ($page) => $page
->component('automations/Invocations')
->has('invocations.data', 1)
);
});
it('renders the metrics tab with aggregated totals over a default 7-day window', function () {
$this->actingAs($this->user)
->get(route('app.automations.metrics', $this->automation->id))
->assertOk()
->assertInertia(fn ($page) => $page
->component('automations/Metrics')
->has('filters.start')
->has('filters.end')
->has('metrics.totals')
->has('metrics.timeseries', 7)
);
});
it('honours an explicit date range and orders a reversed range', function () {
$this->actingAs($this->user)
->get(route('app.automations.metrics', $this->automation->id).'?start=2026-06-01&end=2026-06-10')
->assertOk()
->assertInertia(fn ($page) => $page
->where('filters.start', '2026-06-01')
->where('filters.end', '2026-06-10')
->has('metrics.timeseries', 10)
);
// start after end → the controller swaps them rather than erroring.
$this->actingAs($this->user)
->get(route('app.automations.metrics', $this->automation->id).'?start=2026-06-10&end=2026-06-01')
->assertOk()
->assertInertia(fn ($page) => $page
->where('filters.start', '2026-06-01')
->where('filters.end', '2026-06-10')
);
});