Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions tests/Feature/ExampleTest.php

This file was deleted.

56 changes: 56 additions & 0 deletions tests/Feature/HomeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class HomeTest extends TestCase
{
#[Test]
public function screen_one_renders_without_json_param(): void
{
$this->get('/')
->assertOk()
->assertInertia(fn ($page) =>
$page->component('Home')
->where('screen', 1)
);
}

#[Test]
public function screen_two_renders_with_json_param(): void
{
Http::fake([
'example.test/feed' => Http::response(
json_decode(file_get_contents(base_path('tests/Fixtures/meetings.json')), true),
200
),
]);

$this->get('/?json=https://example.test/feed')
->assertOk()
->assertInertia(fn ($page) =>
$page->component('Home')
->where('screen', 2)
->has('availableRegions')
);
}

#[Test]
public function screen_one_with_error_when_json_fetch_fails(): void
{
Http::fake([
'broken.test/feed' => Http::response(null, 500),
]);

$this->get('/?json=https://broken.test/feed')
->assertOk()
->assertInertia(fn ($page) =>
$page->component('Home')
->where('screen', 1)
->has('error')
);
}
}
84 changes: 84 additions & 0 deletions tests/Feature/PdfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class PdfTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

Http::fake([
'example.test/feed' => Http::response(
json_decode(file_get_contents(base_path('tests/Fixtures/meetings.json')), true),
200
),
]);
}

#[Test]
public function default_pdf_generation_returns_a_pdf(): void
{
$response = $this->get('/pdf?json=https://example.test/feed');

$response->assertOk();
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
$this->assertStringStartsWith('%PDF-', $response->getContent());
}

#[Test]
#[DataProvider('groupingStrategies')]
public function pdf_generates_for_each_grouping_strategy(string $strategy): void
{
$response = $this->get('/pdf?json=https://example.test/feed&group_by=' . $strategy);

$response->assertOk();
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
}

public static function groupingStrategies(): array
{
return [
'day-region' => ['day-region'],
'region-day' => ['region-day'],
'day' => ['day'],
];
}

#[Test]
public function pdf_generates_with_cjk_language(): void
{
$response = $this->get('/pdf?json=https://example.test/feed&language=ja');

$response->assertOk();
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
}

#[Test]
public function pdf_generates_from_google_sheets_url(): void
{
Http::fake([
'sheets.googleapis.com/*' => Http::response([
'values' => [
['slug', 'name', 'day', 'time', 'types', 'address'],
['sheets-sun', 'Sunday Sheets Meeting', 'Sunday', '10:00', 'open, discussion', '100 Peachtree St, Atlanta, GA'],
['sheets-mon', 'Monday Sheets Meeting', 'Monday', '19:30', 'closed, men', '200 Peachtree St, Atlanta, GA'],
['sheets-wed', 'Wednesday Sheets Meeting', 'Wednesday', '07:00', 'open, big book', '300 Peachtree St, Atlanta, GA'],
['sheets-sat', 'Saturday Sheets Meeting', 'Saturday', '12:00', 'open, beginners', '400 Peachtree St, Atlanta, GA'],
],
], 200),
]);

$userFacingUrl = 'https://docs.google.com/spreadsheets/d/12Ga8uwMG4WJ8pZ_SEU7vNETp_aQZ-2yNVsYDFqIwHyE/edit?gid=0#gid=0';

$response = $this->get('/pdf?json=' . urlencode($userFacingUrl));

$response->assertOk();
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
}
}
21 changes: 21 additions & 0 deletions tests/Feature/SmokeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class SmokeTest extends TestCase
{
#[Test]
public function artisan_about_boots_clean(): void
{
$this->artisan('about')->assertSuccessful();
}

#[Test]
public function package_discover_succeeds(): void
{
$this->artisan('package:discover')->assertSuccessful();
}
}
Loading