mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 07:27:47 +00:00
refactor(#120): remove unnecessary js, improve cache handling
This commit is contained in:
parent
3cdc267809
commit
50853728bc
4 changed files with 324 additions and 274 deletions
|
|
@ -65,6 +65,46 @@ it('loads plugins from catalog URL', function (): void {
|
|||
$component->assertSee('testuser');
|
||||
$component->assertSee('A test plugin');
|
||||
$component->assertSee('MIT');
|
||||
$component->assertSee('Preview');
|
||||
});
|
||||
|
||||
it('hides preview button when screenshot_url is missing', function (): void {
|
||||
// Clear cache first to ensure fresh data
|
||||
Cache::forget('catalog_plugins');
|
||||
|
||||
// Mock the HTTP response for the catalog URL without screenshot_url
|
||||
$catalogData = [
|
||||
'test-plugin' => [
|
||||
'name' => 'Test Plugin Without Screenshot',
|
||||
'author' => ['name' => 'Test Author', 'github' => 'testuser'],
|
||||
'author_bio' => [
|
||||
'description' => 'A test plugin',
|
||||
],
|
||||
'license' => 'MIT',
|
||||
'trmnlp' => [
|
||||
'zip_url' => 'https://example.com/plugin.zip',
|
||||
],
|
||||
'byos' => [
|
||||
'byos_laravel' => [
|
||||
'compatibility' => true,
|
||||
],
|
||||
],
|
||||
'logo_url' => 'https://example.com/logo.png',
|
||||
'screenshot_url' => null,
|
||||
],
|
||||
];
|
||||
|
||||
$yamlContent = Yaml::dump($catalogData);
|
||||
|
||||
Http::fake([
|
||||
config('app.catalog_url') => Http::response($yamlContent, 200),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.index')
|
||||
->assertSee('Test Plugin Without Screenshot')
|
||||
->assertDontSeeHtml('variant="subtle" icon="eye"');
|
||||
});
|
||||
|
||||
it('shows error when plugin not found', function (): void {
|
||||
|
|
@ -114,3 +154,46 @@ it('shows error when zip_url is missing', function (): void {
|
|||
$component->assertHasErrors();
|
||||
|
||||
});
|
||||
|
||||
it('can preview a plugin', function (): void {
|
||||
// Clear cache first to ensure fresh data
|
||||
Cache::forget('catalog_plugins');
|
||||
|
||||
// Mock the HTTP response for the catalog URL
|
||||
$catalogData = [
|
||||
'test-plugin' => [
|
||||
'name' => 'Test Plugin',
|
||||
'author' => ['name' => 'Test Author', 'github' => 'testuser'],
|
||||
'author_bio' => [
|
||||
'description' => 'A test plugin description',
|
||||
],
|
||||
'license' => 'MIT',
|
||||
'trmnlp' => [
|
||||
'zip_url' => 'https://example.com/plugin.zip',
|
||||
],
|
||||
'byos' => [
|
||||
'byos_laravel' => [
|
||||
'compatibility' => true,
|
||||
],
|
||||
],
|
||||
'logo_url' => 'https://example.com/logo.png',
|
||||
'screenshot_url' => 'https://example.com/screenshot.png',
|
||||
],
|
||||
];
|
||||
|
||||
$yamlContent = Yaml::dump($catalogData);
|
||||
|
||||
Http::fake([
|
||||
config('app.catalog_url') => Http::response($yamlContent, 200),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.index')
|
||||
->assertSee('Test Plugin')
|
||||
->call('previewPlugin', 'test-plugin')
|
||||
->assertSet('previewingPlugin', 'test-plugin')
|
||||
->assertSet('previewData.name', 'Test Plugin')
|
||||
->assertSee('Preview Test Plugin')
|
||||
->assertSee('A test plugin description');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,9 +28,33 @@ it('loads newest TRMNL recipes on mount', function (): void {
|
|||
Volt::test('catalog.trmnl')
|
||||
->assertSee('Weather Chum')
|
||||
->assertSee('Install')
|
||||
->assertDontSeeHtml('variant="subtle" icon="eye"')
|
||||
->assertSee('Installs: 10');
|
||||
});
|
||||
|
||||
it('shows preview button when screenshot_url is provided', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/recipes.json*' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'id' => 123,
|
||||
'name' => 'Weather Chum',
|
||||
'icon_url' => 'https://example.com/icon.png',
|
||||
'screenshot_url' => 'https://example.com/screenshot.png',
|
||||
'author_bio' => null,
|
||||
'stats' => ['installs' => 10, 'forks' => 2],
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.trmnl')
|
||||
->assertSee('Weather Chum')
|
||||
->assertSee('Preview');
|
||||
});
|
||||
|
||||
it('searches TRMNL recipes when search term is provided', function (): void {
|
||||
Http::fake([
|
||||
// First call (mount -> newest)
|
||||
|
|
@ -152,3 +176,41 @@ it('shows error when plugin installation fails', function (): void {
|
|||
->call('installPlugin', '123')
|
||||
->assertSee('Error installing plugin'); // This will fail because the zip content is invalid
|
||||
});
|
||||
|
||||
it('previews a recipe with async fetch', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/recipes.json*' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'id' => 123,
|
||||
'name' => 'Weather Chum',
|
||||
'icon_url' => 'https://example.com/icon.png',
|
||||
'screenshot_url' => 'https://example.com/old.png',
|
||||
'author_bio' => null,
|
||||
'stats' => ['installs' => 10, 'forks' => 2],
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
'usetrmnl.com/recipes/123.json' => Http::response([
|
||||
'data' => [
|
||||
'id' => 123,
|
||||
'name' => 'Weather Chum Updated',
|
||||
'icon_url' => 'https://example.com/icon.png',
|
||||
'screenshot_url' => 'https://example.com/new.png',
|
||||
'author_bio' => ['description' => 'New bio'],
|
||||
'stats' => ['installs' => 11, 'forks' => 3],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.trmnl')
|
||||
->assertSee('Weather Chum')
|
||||
->call('previewRecipe', '123')
|
||||
->assertSet('previewingRecipe', '123')
|
||||
->assertSet('previewData.name', 'Weather Chum Updated')
|
||||
->assertSet('previewData.screenshot_url', 'https://example.com/new.png')
|
||||
->assertSee('Preview Weather Chum Updated')
|
||||
->assertSee('New bio');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue