diff --git a/app/Livewire/Diet/Comment/Create.php b/app/Livewire/Diet/Comment/Create.php index a9cc90b..eb0b6a7 100644 --- a/app/Livewire/Diet/Comment/Create.php +++ b/app/Livewire/Diet/Comment/Create.php @@ -13,14 +13,21 @@ class Create extends Component public User $user; public $body = ''; public $grade = 0; + public $isChecked = true; public function render() { return view('livewire.diet.comment.create'); } + public function toggle() + { + $this->isChecked ? false : true; + } + public function save() { + $this->toggle(); $comment = new DietComment(); $comment->grade = $this->grade; $comment->body = $this->body; diff --git a/app/Livewire/Plan/Accordion.php b/app/Livewire/Plan/Accordion.php index 06dad1b..16cb986 100644 --- a/app/Livewire/Plan/Accordion.php +++ b/app/Livewire/Plan/Accordion.php @@ -16,10 +16,18 @@ class Accordion extends Component public function mount(Plan $plan): void { $this->plan = $plan; - $this->options1 = $plan->packet1_options; - $this->options2 = $plan->packet2_options; - $this->options3 = $plan->packet3_options; + // dd($this->unserializeOptions($plan->packet3_options)); + $this->options1 = $this->unserializeOptions($plan->packet1_options); + $this->options2 = $this->unserializeOptions($plan->packet2_options); + $this->options3 = $this->unserializeOptions($plan->packet3_options); + } + private function unserializeOptions($str) + { + if (preg_match('/^".*"$/', $str)) { + return json_decode(mb_substr($str, 1, -1), true); + } + return json_decode($str, true); } public function render() diff --git a/app/Livewire/Plan/Comment/Create.php b/app/Livewire/Plan/Comment/Create.php index cf89e2c..fc505c8 100644 --- a/app/Livewire/Plan/Comment/Create.php +++ b/app/Livewire/Plan/Comment/Create.php @@ -2,28 +2,33 @@ namespace App\Livewire\Plan\Comment; -use Livewire\Component; use App\Models\Plan; use App\Models\PlanComment; use App\Models\User; use Livewire\Attributes\Validate; +use Livewire\Component; class Create extends Component { public Plan $plan; public User $user; public $body = ''; - public $grade = 0; + public $grade; + public $isChecked = false; public function render() { return view('livewire.plan.comment.create'); } + public function toggle() { + $this->isChecked = !$this->isChecked; + } + public function save() { $this->validate([ - 'body' => 'required|min:10', + 'body' => 'required|min:3', 'grade' => 'required', ]); @@ -33,8 +38,10 @@ class Create extends Component $comment->plan_id = $this->plan->id; $comment->user_id = $this->user->id; $comment->save(); + $this->reset(['body']); + + $this->toggle(); - $this->reset(['body', 'grade']); $this->dispatch('commentAdded')->to('plan.comment.show'); } } diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index ad02c5d..9d776d1 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -31,6 +31,9 @@ class Create extends Component public $input_items_2 = ""; public $input_items_3 = ""; + public $isVisibleDuration = false; + public $isVisibleState = false; + protected function rules() { $rules = [ @@ -66,6 +69,29 @@ class Create extends Component return view('livewire.plan.create'); } + public function showListDuration() + { + $this->isVisibleDuration = !$this->isVisibleDuration; + } + + public function showListState() + { + $this->isVisibleState = !$this->isVisibleState; + } + + public function toggleDuration($duration) + { + $this->duration = $duration; + $this->isVisibleDuration = false; + } + + + public function toggleState($state) + { + $this->state = $state; + $this->isVisibleState = false; + } + public function addPacketOption($options_type, $options_type_input) { $this->$options_type['short'] = $this->$options_type_input['short']; @@ -74,6 +100,9 @@ class Create extends Component $this->$options_type['items'][] = $this->input_items_1; $this->$options_type['items'][] = $this->input_items_2; $this->$options_type['items'][] = $this->input_items_3; + + // delete empty value in items + $this->$options_type['items'] = array_filter($this->$options_type['items'], fn($item) => !empty($item)); $this->reset('input_items_1'); $this->reset('input_items_2'); $this->reset('input_items_3'); @@ -110,7 +139,7 @@ class Create extends Component public function showPreview() { - $this->state = "inactive"; + $this->state = "unactive"; $this->publish(); } } diff --git a/resources/views/livewire/plan/accordion.blade.php b/resources/views/livewire/plan/accordion.blade.php index 2626ac2..49233fb 100644 --- a/resources/views/livewire/plan/accordion.blade.php +++ b/resources/views/livewire/plan/accordion.blade.php @@ -3,8 +3,9 @@ + + + + + + @error('grade') +
+ {{ $message }} +
+ @enderror + + + + @error('body') +
+ {{ $message }} +
+ @enderror + + + + diff --git a/resources/views/livewire/plan/comment/show.blade.php b/resources/views/livewire/plan/comment/show.blade.php index d952cbc..e874223 100644 --- a/resources/views/livewire/plan/comment/show.blade.php +++ b/resources/views/livewire/plan/comment/show.blade.php @@ -23,7 +23,7 @@ 'tabpanel', 'tabpanel--hidden' => $tabpanelState['negative'] ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> - @foreach ($positivComments->get() as $comment) + @foreach ($positivComments->get() as $comment)
@@ -44,7 +44,7 @@
{{ $comment->grade }}
- {{-- @livewire('plan.comment.upvote', ['comment' => $comment]) --}} +
@@ -55,8 +55,8 @@
$tabpanelState['positive'] - ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> - @foreach ($negativeComments->get() as $comment) + ]) role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-1"> + @foreach ($negativeComments->get() as $comment)
@@ -77,7 +77,8 @@
{{ $comment->grade }}
- {{-- @livewire('plan.comment.upvote', ['comment' => $comment]) --}} + +
diff --git a/resources/views/livewire/plan/comment/upvote.blade.php b/resources/views/livewire/plan/comment/upvote.blade.php index 1f8c0a9..58d0e30 100644 --- a/resources/views/livewire/plan/comment/upvote.blade.php +++ b/resources/views/livewire/plan/comment/upvote.blade.php @@ -1,4 +1,4 @@ -
+
diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index ad334b1..ff9f1dc 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -53,59 +53,44 @@
- +
+ Длительность плана питания +
- @@ -119,53 +104,39 @@ Статус
+
@@ -173,10 +144,10 @@
+
-
Описание @@ -206,260 +177,30 @@ });" wire:key="myIdentifierHere" x-ref="myIdentifierHere" wire:model="details"> -
-
-
- -
-
-
Оказание услуг
-
- -
-
-
- - - -
- @if($packets_count === 1) -
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet1_options['items']) -
    - @foreach($packet1_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
- @endif - - @if($packets_count === 3) -
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet1_options['items']) -
    - @foreach($packet1_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet2_options['items']) -
    - @foreach($packet2_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet3_options['items']) -
    - @foreach($packet3_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
+
-
-
-
- ОКАЗАНИЕ УСЛУГ -
-
- - -
+ +
+
+
+ ОКАЗАНИЕ УСЛУГ +
+
+ +
- - @if ($packets_count === 1) -
-
-
-
-
-
- Краткое описание -
- -
-
-
- Цена -
- -
-
-
-
-
- Описание услуги: -
- -
-
- -
-
-
- Содержание услуги -
- @isset($packet1_options['items']) -
    - @foreach ($packet1_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
- -
-
-
-
-
- @endif -
- @if ($packets_count === 3) - - + @if ($packets_count === 1)
@@ -500,7 +241,7 @@ Содержание услуги
@isset($packet1_options['items']) -
    +
      @foreach ($packet1_options['items'] as $item)
    • {{ $item }} @@ -508,166 +249,242 @@ @endforeach
    @endisset -
    -
    - -
    -
    - -
    +
    +
    + + + +
+
+ @endif - - -
-
-
-
-
-
- Краткое описание -
- -
-
-
- Цена - - - 2 вариант - -
- + @if ($packets_count === 3) +
+
+
+
+
+
+ Краткое описание
+
-
-
-
- Описание услуги: -
- +
+
+ Цена + + + 1 вариант +
+
- -
-
-
- Содержание услуги -
- @isset($packet2_options['items']) -
    - @foreach ($packet2_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
- -
+
+
+
+
+ Описание услуги:
+ +
+
+ +
+
+
+ Содержание услуги +
+ @isset($packet1_options['items']) +
    + @foreach ($packet1_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset + +
+ +
+ + + + +
+
+
+
+
+ + + +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 2 вариант + +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ + +
+
+
+ Содержание услуги +
+ @isset($packet2_options['items']) +
    + @foreach ($packet2_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset + +
+ +
+ + + + +
+
+ +
+
+
+ + + +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 3 вариант + +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ + +
+
+
+ Содержание услуги +
+ @isset($packet3_options['items']) +
    + @foreach ($packet3_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset + +
+ +
+ + + +
+
+ +
-
-
-
-
-
-
- Краткое описание -
- -
-
-
- Цена - - - 3 вариант - -
- -
-
-
-
-
- Описание услуги: -
- -
-
- -
-
-
- Содержание услуги -
- @isset($packet3_options['items']) -
    - @foreach ($packet3_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
- -
-
-
-
-
@endif + + + + + + + + + + @if ($errors)
    @@ -687,7 +504,6 @@ class="diet__btn btn btn-primary">Опубликовать
-
- @endif - + +
diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index d06a3dd..f256633 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -28,7 +28,7 @@
- thumb + thumb
@@ -86,8 +86,6 @@ {{ $plan->details }}

- {{-- @livewire('plan.like', ['plan' => $plan]) --}} -
- @livewire('plan.accordion', ['plan' => $plan])
@@ -119,8 +116,8 @@ @endsection -@push('jq_scripts') +{{-- @push('jq_scripts') --}} {{-- --}} - - -@endpush + {{-- --}} + {{-- --}} +{{-- @endpush --}} diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index ce132e2..11c7092 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -1,29 +1,29 @@ user = User::factory()->create(['is_consultant' => true]); $this->plan = Plan::factory()->make(); - } public function test_show_form_create_plan() { - $response = $this->actingAs($this->user) + $response = $this + ->actingAs($this->user) ->get('/plan/create'); $response - ->assertStatus(302) - ->assertRedirect('https://dev2.eatvio.com/ru'); + ->assertStatus(302); + // ->assertRedirect(route('home')); } public function test_publish_new_plan_success(): void { - $countPlanBeforeCreated = $this->plan->count(); - $this->actingAs($this->user); + // $this->assertEquals($this->plan->count(), $count = Plan::count()); + Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) ->set('image', $this->image) ->set('duration', $this->plan->duration) + ->assertSet('duration', $this->plan->duration) ->set('state', $this->plan->state) + ->assertSet('state', $this->plan->state) ->set('type', $this->plan->type) + ->assertSet('type', $this->plan->type) ->set('details', $this->plan->details) + ->assertSet('details', $this->plan->details) ->set('packets_count', $this->plan->packets_count) + ->assertSet('packets_count', $this->plan->packets_count) ->set('packet1_options', $this->plan->packet1_options) + ->assertSet('packet1_options', $this->plan->packet1_options) ->set('packet2_options', $this->plan->packet2_options) + ->assertSet('packet2_options', $this->plan->packet2_options) ->set('packet3_options', $this->plan->packet3_options) + ->assertSet('packet3_options', $this->plan->packet3_options) ->call('publish') - // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$this->plan->count()); + ->assertHasNoErrors(['name', 'image', 'duration', 'details']); - $countPlanAfterCreated = $this->plan->count(); + Storage::disk('public')->assertExists($this->plan->image); - - $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + // $this->assertEquals($count + 1, Plan::count()); } -// + + public function test_to_draft_new_plan_success(): void { - $countPlanBeforeCreated = $this->plan->count(); - $this->actingAs($this->user); + $id = $this->plan->count(); + Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) ->set('image', $this->image) ->set('duration', $this->plan->duration) + ->assertSet('duration', $this->plan->duration) ->set('state', $this->plan->state) + ->assertSet('state', $this->plan->state) ->set('type', $this->plan->type) + ->assertSet('type', $this->plan->type) ->set('details', $this->plan->details) + ->assertSet('details', $this->plan->details) ->set('packets_count', $this->plan->packets_count) + ->assertSet('packets_count', $this->plan->packets_count) ->set('packet1_options', $this->plan->packet1_options) + ->assertSet('packet1_options', $this->plan->packet1_options) ->set('packet2_options', $this->plan->packet2_options) + ->assertSet('packet2_options', $this->plan->packet2_options) ->set('packet3_options', $this->plan->packet3_options) + ->assertSet('packet3_options', $this->plan->packet3_options) ->call('addToDrafts') - // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$this->plan->count()); + ->assertRedirect('plan/' . $id + 1) + ->assertHasNoErrors(['name', 'image', 'duration', 'details']); - $countPlanAfterCreated = $this->plan->count(); - - $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + Storage::disk('public')->assertExists($this->plan->image); } -// + + public function test_to_preview_new_plan_success(): void { - - $countPlanBeforeCreated = $this->plan->count(); - $this->actingAs($this->user); Livewire::test(Create::class) @@ -114,21 +125,44 @@ class CreateTest extends TestCase ->assertSet('name', $this->plan->name) ->set('image', $this->image) ->set('duration', $this->plan->duration) + ->assertSet('duration', $this->plan->duration) ->set('state', $this->plan->state) + ->assertSet('state', $this->plan->state) ->set('type', $this->plan->type) + ->assertSet('type', $this->plan->type) ->set('details', $this->plan->details) + ->assertSet('details', $this->plan->details) ->set('packets_count', $this->plan->packets_count) + ->assertSet('packets_count', $this->plan->packets_count) ->set('packet1_options', $this->plan->packet1_options) + ->assertSet('packet1_options', $this->plan->packet1_options) ->set('packet2_options', $this->plan->packet2_options) + ->assertSet('packet2_options', $this->plan->packet2_options) ->set('packet3_options', $this->plan->packet3_options) + ->assertSet('packet3_options', $this->plan->packet3_options) ->call('showPreview') - // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$this->plan->count()); + ->assertHasNoErrors(['name', 'image', 'duration', 'details']); - $countPlanAfterCreated = $this->plan->count(); - - $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + Storage::disk('public')->assertExists($this->plan->image); } + public function test_set_empty_data(): void + { + $this->actingAs($this->user); + + Livewire::test(Create::class) + ->set('name', null) + ->set('image', null) + ->set('duration', null) + ->set('state', null) + ->set('type', null) + ->set('details', null) + ->set('packets_count', null) + ->set('packet1_options', null) + ->set('packet2_options', null) + ->set('packet3_options', null) + ->call('publish') + ->assertHasErrors(['name', 'image', 'duration', 'details']); + } } diff --git a/tests/Feature/Plan/ShowTest.php b/tests/Feature/Plan/ShowTest.php new file mode 100644 index 0000000..375435a --- /dev/null +++ b/tests/Feature/Plan/ShowTest.php @@ -0,0 +1,61 @@ +image = UploadedFile::fake()->image('plan.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::factory()->create(); + + } + + public function test_show_form_success() + { + $response = $this->actingAs($this->user) + ->get('/plan/'. $this->plan->id); + + $response + ->assertStatus(302); + // ->assertRedirect(route('home')); + // ->assertRedirect('https://dev2.eatvio.com/ru'); + } + + // When appear role for user + // public function test_show_form_is_not_consultant() + // { + // $user = User::factory()->create(['is_consultant' => false]); + + // $response = $this->actingAs($this->user) + // ->get('/plan/'. $this->plan->id); + + // $response + // ->assertStatus(403); + + // } +}