фикс для новостей
This commit is contained in:
@@ -19,15 +19,19 @@ const form = useForm({
|
||||
});
|
||||
|
||||
function submit() {
|
||||
const hasImage = props.allowImage && Boolean(form.image);
|
||||
const options = {
|
||||
preserveScroll: true,
|
||||
forceFormData: props.allowImage,
|
||||
forceFormData: hasImage,
|
||||
errorBag: props.item ? `news-edit-${props.item.id}` : 'news-create',
|
||||
onSuccess: () => {
|
||||
if (!props.item) form.reset();
|
||||
},
|
||||
};
|
||||
|
||||
if (props.item && props.allowImage) {
|
||||
form.transform((data) => data);
|
||||
|
||||
if (props.item && hasImage) {
|
||||
form.transform((data) => ({ ...data, _method: 'patch' })).post(props.action, options);
|
||||
} else if (props.item) {
|
||||
form.patch(props.action, options);
|
||||
|
||||
@@ -42,6 +42,42 @@ class AdminNewsFeatureTest extends TestCase
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_admin_can_create_and_update_news_without_an_image(): void
|
||||
{
|
||||
$admin = $this->admin();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post(route('admin.news.store'), [
|
||||
'title' => 'Новая глава MoonWell',
|
||||
'body' => 'Подробности новой главы.',
|
||||
'sort_order' => 10,
|
||||
'is_published' => true,
|
||||
])
|
||||
->assertSessionHas('status', 'Новость добавлена.');
|
||||
|
||||
$newsItem = News::query()->firstOrFail();
|
||||
|
||||
$this->assertSame('Новая глава MoonWell', $newsItem->title);
|
||||
$this->assertTrue($newsItem->is_published);
|
||||
$this->assertSame('ADMIN', $newsItem->created_by_username);
|
||||
|
||||
$this->actingAs($admin)
|
||||
->patch(route('admin.news.update', $newsItem), [
|
||||
'title' => 'Новая глава уже доступна',
|
||||
'body' => 'Обновлённые подробности.',
|
||||
'sort_order' => 5,
|
||||
'is_published' => false,
|
||||
])
|
||||
->assertSessionHas('status', 'Новость обновлена.');
|
||||
|
||||
$this->assertDatabaseHas('news', [
|
||||
'id' => $newsItem->id,
|
||||
'title' => 'Новая глава уже доступна',
|
||||
'sort_order' => 5,
|
||||
'is_published' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
private function admin(int $gmLevel = 3): GameAccountUser
|
||||
{
|
||||
return new GameAccountUser(
|
||||
|
||||
Reference in New Issue
Block a user