Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Sep 19, 2023
1 parent 6a9b01c commit f467bc2
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 76 deletions.
2 changes: 1 addition & 1 deletion public/css/moonshine.css

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions public/js/moonshine.js

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
"file": "fonts/Gilroy-Medium.woff2",
"src": "resources/fonts/Gilroy-Medium.woff2"
},
"resources/fonts/Gilroy-Regular.woff2": {
"file": "fonts/Gilroy-Regular.woff2",
"src": "resources/fonts/Gilroy-Regular.woff2"
},
"resources/fonts/Gilroy-SemiBold.woff2": {
"file": "fonts/Gilroy-SemiBold.woff2",
"src": "resources/fonts/Gilroy-SemiBold.woff2"
},
"resources/images/logo-small.svg": {
"file": "assets/logo-small.svg",
"src": "resources/images/logo-small.svg"
Expand All @@ -27,16 +19,24 @@
"file": "assets/logo.svg",
"src": "resources/images/logo.svg"
},
"resources/js/app.css": {
"file": "css/moonshine.css",
"src": "resources/js/app.css"
"resources/fonts/Gilroy-SemiBold.woff2": {
"file": "fonts/Gilroy-SemiBold.woff2",
"src": "resources/fonts/Gilroy-SemiBold.woff2"
},
"resources/fonts/Gilroy-Regular.woff2": {
"file": "fonts/Gilroy-Regular.woff2",
"src": "resources/fonts/Gilroy-Regular.woff2"
},
"resources/js/app.js": {
"css": [
"css/moonshine.css"
],
"file": "js/moonshine.js",
"src": "resources/js/app.js",
"isEntry": true,
"src": "resources/js/app.js"
"css": [
"css/moonshine.css"
]
},
"resources/js/app.css": {
"file": "css/moonshine.css",
"src": "resources/js/app.css"
}
}
26 changes: 24 additions & 2 deletions resources/js/alpine/sortable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import Sortable from 'sortablejs'

export default () => ({
export default (url = null, group = null) => ({
init() {
Sortable.create(this.$el, this.$el.dataset)
let options = {
group: group
? {
name: group,
} : null,
...this.$el.dataset,
onSort: async function(evt) {
if(url) {
let formData = new FormData()

formData.append('id', evt.item.dataset?.id)
formData.append('parent', evt.to.dataset?.id)
formData.append('index', evt.newIndex)
formData.append('data', this.toArray())

await axios.post(url, formData)
}
}
}

Sortable.create(this.$el, options)
},
})



4 changes: 4 additions & 0 deletions resources/views/fields/json.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div x-id="['json']" :id="$id('json')">
{{ $element->value(withOld: false)
->editable()
->when(
!$element->isAsRelation(),
fn($table) => $table->sortable()
)
->when(
$element->isCreatable(),
fn($table) => $table->creatable()
Expand Down
33 changes: 18 additions & 15 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
namespace MoonShine\Commands;

use Illuminate\Contracts\Filesystem\FileNotFoundException;

use function Laravel\Prompts\{confirm, intro, outro, spin, warning};

use Illuminate\Support\Facades\File;
use MoonShine\MoonShine;

use MoonShine\Providers\MoonShineServiceProvider;

use function Laravel\Prompts\{confirm, intro, outro, spin, warning};

class InstallCommand extends MoonShineCommand
{
protected $signature = 'moonshine:install';
protected $signature = 'moonshine:install {--u|without-user} {--m|without-migrations}';

protected $description = 'Install the moonshine package';

Expand All @@ -34,7 +33,7 @@ public function handle(): void
$this->initMigrations();
}, 'Installation completed');

if (confirm('Create super user ?')) {
if (!$this->option('without-user') && confirm('Create super user ?')) {
$this->call(MakeUserCommand::class);
}

Expand Down Expand Up @@ -77,16 +76,18 @@ protected function initServiceProvider(): void
$this->comment('Publishing MoonShine Service Provider...');
$this->call('vendor:publish', ['--tag' => 'moonshine-provider']);

$this->copyStub(
'MoonShineServiceProvider',
app_path('Providers/MoonShineServiceProvider.php')
);
if (! File::exists(app_path('Providers/MoonShineServiceProvider.php'))) {
$this->copyStub(
'MoonShineServiceProvider',
app_path('Providers/MoonShineServiceProvider.php')
);

if (! app()->runningUnitTests()) {
$this->registerServiceProvider();
}
if (! app()->runningUnitTests()) {
$this->registerServiceProvider();
}

$this->components->task('Service Provider created');
$this->components->task('Service Provider created');
}
}

protected function registerServiceProvider(): void
Expand Down Expand Up @@ -130,7 +131,9 @@ protected function initDashboard(): void

protected function initMigrations(): void
{
if (config('moonshine.use_migrations', true) && confirm('Install migrations?')) {
$confirm = $this->option('without-migrations') || confirm('Install migrations?');

if (config('moonshine.use_migrations', true) && $confirm) {
$this->call('migrate');

$this->components->task('Tables migrated');
Expand Down
6 changes: 3 additions & 3 deletions src/Components/ResourcePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use MoonShine\Resources\Resource;
use MoonShine\Contracts\Resources\ResourceContract;
use MoonShine\Traits\HasResource;
use Throwable;

/**
* @method static static make(Resource $resource, ?Closure $query = null)
* @method static static make(ResourceContract $resource, ?Closure $query = null)
*/
final class ResourcePreview extends MoonshineComponent
{
Expand All @@ -21,7 +21,7 @@ final class ResourcePreview extends MoonshineComponent
protected ?Closure $query = null;

public function __construct(
Resource $resource,
ResourceContract $resource,
?Closure $query = null,
) {
$this->setResource($resource);
Expand Down
6 changes: 6 additions & 0 deletions src/Fields/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ protected function resolveOnApply(): ?Closure
$applyValues = [];

foreach ($requestValues as $index => $values) {
if ($this->isAsRelation()) {
$values = $this->asRelationResource()
?->getModel()
?->forceFill($values) ?? $values;
}

foreach ($this->getFields() as $field) {
$field->setRequestKeyPrefix(
str("{$this->column()}.$index")->when(
Expand Down
3 changes: 1 addition & 2 deletions src/MoonShine.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use MoonShine\Pages\Page;
use MoonShine\Pages\Pages;
use MoonShine\Resources\MoonShineProfileResource;
use MoonShine\Resources\Resource;
use Throwable;

class MoonShine
Expand Down Expand Up @@ -77,7 +76,7 @@ public static function resources(array $data): void
self::$resources = collect($data);
}

public static function addResource(Resource $resource): void
public static function addResource(ResourceContract $resource): void
{
if (is_null(self::$resources)) {
self::$resources = collect([$resource]);
Expand Down
6 changes: 3 additions & 3 deletions src/MoonShineRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace MoonShine;

use MoonShine\Contracts\Resources\ResourceContract;
use MoonShine\Pages\Page;
use MoonShine\Pages\Pages;
use MoonShine\Resources\Resource;
use Symfony\Component\HttpFoundation\RedirectResponse;

final class MoonShineRouter
Expand All @@ -23,7 +23,7 @@ public static function to(string $name, array $params = []): string
}

public static function to_page(
string|Resource|null $resource,
string|ResourceContract|null $resource,
string|Page|null $page = null,
array $params = [],
bool $redirect = false
Expand All @@ -34,7 +34,7 @@ public static function to_page(
)->url();
}

$resource = $resource instanceof Resource
$resource = $resource instanceof ResourceContract
? $resource
: new $resource();

Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/MoonShineNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class MoonShineNotification
{
/**
* @param array{'link': string, 'label': string} $button
* @param array<int> $ids
* @param array<int|string> $ids
*/
public static function send(
string $message,
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace MoonShine\Pages;

use Illuminate\Support\Collection;
use MoonShine\Resources\Resource;
use MoonShine\Contracts\Resources\ResourceContract;

/**
* @template TKey of array-key
Expand All @@ -14,7 +14,7 @@
*/
final class Pages extends Collection
{
public function setResource(Resource $resource): Pages
public function setResource(ResourceContract $resource): Pages
{
return $this->each(fn (Page $page): Page => $page->setResource($resource));
}
Expand Down
6 changes: 0 additions & 6 deletions src/Providers/MoonShineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ public function boot(): void
),
]);

$this->publishes([
MoonShine::path('/stubs/MoonShineServiceProvider.stub') => app_path(
'Providers/MoonShineServiceProvider.php'
),
], 'moonshine-provider');

if ($this->app->runningInConsole()) {
$this->commands($this->commands);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Resource/ResourceModelQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getItemOrFail(): Model
/**
* Get an array of custom form actions
*
* @return array<int, QueryTag>
* @return array<QueryTag>
*/
public function queryTags(): array
{
Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use MoonShine\Commands\InstallCommand;
use MoonShine\Menu\MenuItem;
use MoonShine\Models\MoonshineUser;
use MoonShine\Models\MoonshineUserRole;
Expand Down Expand Up @@ -54,7 +55,10 @@ protected function getEnvironmentSetUp($app): void

protected function performApplication(): static
{
$this->artisan('moonshine:install');
$this->artisan(InstallCommand::class, [
'--without-user' => true,
'--without-migrations' => true
]);

$this->artisan('config:clear');
$this->artisan('view:clear');
Expand Down

0 comments on commit f467bc2

Please sign in to comment.