Added Notification page test..

This commit is contained in:
Cüneyt Şentürk 2021-06-30 17:13:08 +03:00
parent 72acc3e3ee
commit 84b76d6a1e
4 changed files with 183 additions and 110 deletions

View File

@ -68,19 +68,24 @@ class Notifications extends Controller
$notifications = $this->getNotifications($path); $notifications = $this->getNotifications($path);
foreach ($notifications as $notification) { if ($notifications) {
if ($notification->id == $id) { foreach ($notifications as $notification) {
setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name); if ($notification->id == $id) {
setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message); setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name);
setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now()); setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message);
setting()->set('notifications.'. $path . '.' . $id . '.status', '0'); setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now());
setting()->set('notifications.'. $path . '.' . $id . '.status', '0');
setting()->save(); setting()->save();
break; break;
}
} }
} }
return response()->json([ return response()->json([
'message' => trans('messages.success.disabled', [
'type' => Str::lower(trans_choice('general.notifications', 2))
]),
'success' => true, 'success' => true,
'error' => false, 'error' => false,
'data' => null, 'data' => null,

View File

@ -17,150 +17,150 @@ class DashboardsTest extends FeatureTestCase
->assertSeeText(trans_choice('general.dashboards', 1)); ->assertSeeText(trans_choice('general.dashboards', 1));
} }
public function testItShouldSeeDashboardListPage() public function testItShouldSeeDashboardListPage()
{ {
$this->loginAs() $this->loginAs()
->get(route('dashboards.index')) ->get(route('dashboards.index'))
->assertOk() ->assertOk()
->assertSeeText(trans_choice('general.dashboards', 2)); ->assertSeeText(trans_choice('general.dashboards', 2));
} }
public function testItShouldSeeDashboardCreatePage() public function testItShouldSeeDashboardCreatePage()
{ {
$this->loginAs() $this->loginAs()
->get(route('dashboards.create')) ->get(route('dashboards.create'))
->assertOk() ->assertOk()
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)])); ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)]));
} }
public function testItShouldCreateDashboard() public function testItShouldCreateDashboard()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$this->loginAs() $this->loginAs()
->post(route('dashboards.store'), $request) ->post(route('dashboards.store'), $request)
->assertOk(); ->assertOk();
$this->assertFlashLevel('success'); $this->assertFlashLevel('success');
$this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request));
} }
public function testItShouldSeeDashboardUpdatePage() public function testItShouldSeeDashboardUpdatePage()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$dashboard = $this->dispatch(new CreateDashboard($request)); $dashboard = $this->dispatch(new CreateDashboard($request));
$this->loginAs() $this->loginAs()
->get(route('dashboards.edit', $dashboard->id)) ->get(route('dashboards.edit', $dashboard->id))
->assertOk() ->assertOk()
->assertSee($dashboard->name); ->assertSee($dashboard->name);
} }
public function testItShouldUpdateDashboard() public function testItShouldUpdateDashboard()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$dashboard = $this->dispatch(new CreateDashboard($request)); $dashboard = $this->dispatch(new CreateDashboard($request));
$request['name'] = $this->faker->text(15); $request['name'] = $this->faker->text(15);
$this->loginAs() $this->loginAs()
->patch(route('dashboards.update', $dashboard->id), $request) ->patch(route('dashboards.update', $dashboard->id), $request)
->assertOk() ->assertOk()
->assertSee($request['name']); ->assertSee($request['name']);
$this->assertFlashLevel('success'); $this->assertFlashLevel('success');
$this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request));
} }
public function testItShouldDeleteDashboard() public function testItShouldDeleteDashboard()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$tmp = $this->dispatch(new CreateDashboard($this->getRequest())); $tmp = $this->dispatch(new CreateDashboard($this->getRequest()));
$dashboard = $this->dispatch(new CreateDashboard($request)); $dashboard = $this->dispatch(new CreateDashboard($request));
$this->loginAs() $this->loginAs()
->delete(route('dashboards.destroy', $dashboard->id)) ->delete(route('dashboards.destroy', $dashboard->id))
->assertOk(); ->assertOk();
$this->assertFlashLevel('success'); $this->assertFlashLevel('success');
$this->assertSoftDeleted('dashboards', $this->getAssertRequest($request)); $this->assertSoftDeleted('dashboards', $this->getAssertRequest($request));
} }
public function testItShouldSeeWidgetCreate() public function testItShouldSeeWidgetCreate()
{ {
$classes = Widget::factory()->classes; $classes = Widget::factory()->classes;
$class = $classes[rand(0, 9)]; $class = $classes[rand(0, 9)];
$this->loginAs() $this->loginAs()
->get(route('widgets.index')) ->get(route('widgets.index'))
->assertOk() ->assertOk()
->assertSeeText((new $class())->getDefaultName()); ->assertSeeText((new $class())->getDefaultName());
} }
public function testItShouldSeeWidgetEdit() public function testItShouldSeeWidgetEdit()
{ {
$widget = Widget::create($this->getWidget()); $widget = Widget::create($this->getWidget());
$this->loginAs() $this->loginAs()
->get(route('widgets.edit', $widget->id)) ->get(route('widgets.edit', $widget->id))
->assertOk() ->assertOk()
->assertSee($widget->name); ->assertSee($widget->name);
} }
public function testItShouldCreateWidget() public function testItShouldCreateWidget()
{ {
$request = $this->getWidget(); $request = $this->getWidget();
$this->loginAs() $this->loginAs()
->post(route('widgets.store'), $request) ->post(route('widgets.store'), $request)
->assertOk(); ->assertOk();
$this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); $this->assertDatabaseHas('widgets', $this->getAssertRequest($request));
} }
public function testItShouldUpdateWidget() public function testItShouldUpdateWidget()
{ {
$request = $this->getWidget(); $request = $this->getWidget();
$widget = Widget::create($request); $widget = Widget::create($request);
$request['name'] = $this->faker->name; $request['name'] = $this->faker->name;
$this->loginAs() $this->loginAs()
->patch(route('widgets.update', $widget->id), $request) ->patch(route('widgets.update', $widget->id), $request)
->assertOk(); ->assertOk();
$this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); $this->assertDatabaseHas('widgets', $this->getAssertRequest($request));
} }
public function testItShouldDeleteWidget() public function testItShouldDeleteWidget()
{ {
$request = $this->getWidget(); $request = $this->getWidget();
$widget = Widget::create($request); $widget = Widget::create($request);
$this->loginAs() $this->loginAs()
->delete(route('widgets.destroy', $widget->id)) ->delete(route('widgets.destroy', $widget->id))
->assertOk(); ->assertOk();
$this->assertSoftDeleted('widgets', $this->getAssertRequest($request)); $this->assertSoftDeleted('widgets', $this->getAssertRequest($request));
} }
public function getRequest() public function getRequest()
{ {
return Dashboard::factory()->enabled()->users()->raw(); return Dashboard::factory()->enabled()->users()->raw();
} }
public function getWidget() public function getWidget()
{ {
return Widget::factory()->raw(); return Widget::factory()->raw();
} }
public function getAssertRequest($request) public function getAssertRequest($request)
{ {

View File

@ -0,0 +1,67 @@
<?php
namespace Tests\Feature\Common;
use App\Jobs\Auth\NotifyUser;
use App\Notifications\Common\ImportCompleted;
use Cache;
use Date;
use Illuminate\Support\Str;
use Tests\Feature\FeatureTestCase;
class NotificationsTest extends FeatureTestCase
{
public function testItShouldSeeNotificationListPage()
{
$this->loginAs()
->get(route('notifications.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.items', 2));
}
public function testItShouldSeeReadAllAction()
{
$this->loginAs()
->get(route('notifications.read-all'))
->assertStatus(302);
$this->assertFlashLevel('success');
}
public function testItShouldSeeDisableAction()
{
$this->loginAs()
->post(route('notifications.disable'), ['path' => 'double-entry', 'id' => 1])
->assertOk()
->assertSeeText(trans('messages.success.disabled', [
'type' => Str::lower(trans_choice('general.notifications', 2))
]));
}
public function testItShouldSeeNewApps()
{
$notificatinos = $this->getNewApps();
$this->loginAs()
->get(route('notifications.index'))
->assertOk()
->assertSeeText('Double-Entry');
}
protected function getNewApps()
{
$new_apps[] = (object) [
"name" => "Double-Entry",
"alias" => "double-entry",
"message" => "<a href=\"https:\/\/akaunting.com\/apps\/double-entry?utm_source=Notifications&utm_medium=App&utm_campaign=Double-Entry\" target=\"_blank\">Double-Entry<\/a> app is published. You can check it out!",
"path" =>"new-apps",
"started_at" => "2021-06-26 00:00:00",
"ended_at" => "2021-07-11 00:00:00",
"status" => 2,
];
$key = 'apps.notifications';
Cache::put($key, ['new-apps' => $new_apps], Date::now()->addHour(6));
}
}

View File

@ -3,6 +3,7 @@
namespace Tests; namespace Tests;
use App\Traits\Jobs; use App\Traits\Jobs;
use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;