where('trigger_key', 'status_changed')->firstOrFail(); Livewire::actingAs($admin)->test(Panel::class) ->call('setTab', 'templates') ->call('toggleNotificationEnabled', $statusChanged->id) ->assertOk(); expect($statusChanged->fresh()->enabled)->toBeFalse(); expect(method_exists(Panel::class, 'openEmailTemplateForm'))->toBeFalse() ->and(method_exists(Panel::class, 'submitEmailTemplateForm'))->toBeFalse() ->and(method_exists(Panel::class, 'removeEmailTemplate'))->toBeFalse() ->and(method_exists(Panel::class, 'setNotificationTemplate'))->toBeFalse(); }); test('admin can edit the subject and body of a trigger\'s fixed template', function () { $admin = adminUser(); // A bare migrated (unseeded) database has no email_templates rows yet, so // ticket_created's binding is still null at this point — give it one. $template = EmailTemplate::query()->create(['key' => 'tpl-created-test', 'name' => 'Nowe', 'trigger_label' => 'x', 'subject' => 'S', 'body' => 'B']); $ticketCreated = NotificationSetting::query()->where('trigger_key', 'ticket_created')->firstOrFail(); $ticketCreated->update(['email_template_id' => $template->id]); Livewire::actingAs($admin)->test(Panel::class) ->call('setTab', 'templates') ->call('editEmailTemplate', $ticketCreated->email_template_id) ->call('setTemplateSubject', 'Nowy temat #{numer}') ->call('setTemplateBody', 'Nowa treść {imie}') ->call('closeEmailTemplateEditor') ->assertSet('editingTemplateId', null) ->assertOk(); $template = EmailTemplate::query()->find($ticketCreated->email_template_id); expect($template->subject)->toBe('Nowy temat #{numer}') ->and($template->body)->toBe('Nowa treść {imie}'); }); test('a disabled trigger sends no notification, an enabled one sends the assigned template with a working ticket link', function () { Notification::fake(); seedStatusesAndPriorities(); $template = EmailTemplate::query()->create([ 'key' => 'tpl-new-test', 'name' => 'Nowe', 'trigger_label' => 'x', 'subject' => 'Zgloszenie #{numer}', 'body' => 'Podglad: {link}', ]); NotificationSetting::query()->where('trigger_key', 'ticket_created')->update(['email_template_id' => $template->id]); NotificationSetting::query()->where('trigger_key', 'status_changed')->update(['enabled' => false]); $ticket = app(TicketService::class)->create([ 'email' => 'client-notify@example.com', 'subject' => 'Problem testowy', 'body' => 'Opis problemu.', ], null); Notification::assertSentOnDemand( TicketNotification::class, fn ($notification, $channels, $notifiable) => $notifiable->routes['mail'] === 'client-notify@example.com' ); app(TicketService::class)->setStatus($ticket, 'in_progress'); Notification::assertSentOnDemandTimes(TicketNotification::class, 1); $mail = (new TicketNotification($ticket->fresh(), $template->id))->toMail((object) ['routes' => ['mail' => $ticket->email]]); expect($mail->subject)->toBe('Zgloszenie #'.$ticket->number) ->and($mail->viewData['html'])->toContain(route('client.ticket', $ticket)); });