Merge pull request 'Collapse the lesson-type filter behind a Show Only button' (#120) from feature/lesson-type-filter-collapsed into main
CI / No Debug Code (push) Successful in 2s
CI / Tests (PHP 8.2) (push) Successful in 46s
CI / Tests (PHP 8.1) (push) Successful in 53s
CI / PHPStan (push) Successful in 2m56s
CI / Coding Standards (push) Successful in 2m58s
CI / Tests (PHP 8.3) (push) Successful in 2m42s
CI / Build Plugin Zip (push) Successful in 2m48s
Release / Build and Publish Release (push) Successful in 2m49s
Release / Open next-version bump PR (push) Successful in 4s
CI / No Debug Code (push) Successful in 2s
CI / Tests (PHP 8.2) (push) Successful in 46s
CI / Tests (PHP 8.1) (push) Successful in 53s
CI / PHPStan (push) Successful in 2m56s
CI / Coding Standards (push) Successful in 2m58s
CI / Tests (PHP 8.3) (push) Successful in 2m42s
CI / Build Plugin Zip (push) Successful in 2m48s
Release / Build and Publish Release (push) Successful in 2m49s
Release / Open next-version bump PR (push) Successful in 4s
Reviewed-on: #120
This commit was merged in pull request #120.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Unsupervised\Schedular\Tests\Unit;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use Unsupervised\Schedular\BlockPreview;
|
||||
use Unsupervised\Schedular\Booking\BookingPage;
|
||||
|
||||
class BlockPreviewTest extends TestCase
|
||||
{
|
||||
@@ -18,6 +19,25 @@ class BlockPreviewTest extends TestCase
|
||||
self::assertStringContainsString('class="us-slot"', $html);
|
||||
self::assertStringContainsString('class="us-book-btn" disabled', $html);
|
||||
self::assertStringContainsString('us-editor-note', $html);
|
||||
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||
}
|
||||
|
||||
public function testBookingOnlyPreviewLeavesOutTheUpcomingLessons(): void
|
||||
{
|
||||
$html = BlockPreview::booking(BookingPage::MODE_BOOKING);
|
||||
|
||||
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||
self::assertStringNotContainsString('us-my-lessons', $html);
|
||||
}
|
||||
|
||||
public function testUpcomingOnlyPreviewLeavesOutTheCalendar(): void
|
||||
{
|
||||
$html = BlockPreview::booking(BookingPage::MODE_UPCOMING);
|
||||
|
||||
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||
self::assertStringContainsString('Your upcoming lessons', $html);
|
||||
self::assertStringNotContainsString('us-slot-list', $html);
|
||||
self::assertStringNotContainsString('us-book-btn', $html);
|
||||
}
|
||||
|
||||
public function testGroupClassesPreviewMirrorsTheLiveMarkup(): void
|
||||
|
||||
@@ -124,7 +124,7 @@ class BlockRegistrarTest extends TestCase
|
||||
// The link-target and auto-redirect options must be declared
|
||||
// server-side or the block-renderer preview rejects them.
|
||||
self::assertSame(
|
||||
['loginPageId', 'autoRedirect'],
|
||||
['loginPageId', 'autoRedirect', 'lessonTypeId', 'showTypeFilter', 'displayMode'],
|
||||
array_keys($registered['us-scheduler/booking']['attributes'])
|
||||
);
|
||||
self::assertSame(
|
||||
|
||||
@@ -17,6 +17,26 @@ class BookingPageTest extends TestCase
|
||||
$this->page = new BookingPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the page as a logged-in, approved student — the path that
|
||||
* includes the template and its data attributes.
|
||||
*
|
||||
* @param array<int|string, mixed> $atts
|
||||
*/
|
||||
private function renderForStudent(array $atts): string
|
||||
{
|
||||
Functions\when('is_user_logged_in')->justReturn(true);
|
||||
Functions\when('get_current_user_id')->justReturn(3);
|
||||
Functions\when('get_user_meta')->justReturn('');
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Functions\when('wp_enqueue_style')->justReturn(null);
|
||||
Functions\when('wp_enqueue_script')->justReturn(null);
|
||||
Functions\when('wp_create_nonce')->justReturn('nonce123');
|
||||
Functions\when('absint')->alias(static fn ($value) => abs((int) $value));
|
||||
|
||||
return $this->page->render($atts);
|
||||
}
|
||||
|
||||
public function testLoggedOutVisitorIsLinkedToTheWordPressLoginByDefault(): void
|
||||
{
|
||||
Functions\when('is_user_logged_in')->justReturn(false);
|
||||
@@ -59,6 +79,85 @@ class BookingPageTest extends TestCase
|
||||
self::assertStringContainsString('href="https://example.com/login/"', $html);
|
||||
}
|
||||
|
||||
public function testDefaultEmbedShowsBothHalvesWithTheFilterAndNoPinnedType(): void
|
||||
{
|
||||
$html = $this->renderForStudent([]);
|
||||
|
||||
self::assertStringContainsString('id="us-booking-app"', $html);
|
||||
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||
self::assertStringNotContainsString('data-lesson-type', $html);
|
||||
self::assertStringNotContainsString('data-type-filter', $html);
|
||||
}
|
||||
|
||||
public function testBlockLessonTypeAttributePinsASingleType(): void
|
||||
{
|
||||
self::assertStringContainsString(
|
||||
'data-lesson-type="12"',
|
||||
$this->renderForStudent(['lessonTypeId' => 12])
|
||||
);
|
||||
}
|
||||
|
||||
public function testShortcodeLessonTypeAttributePinsASingleType(): void
|
||||
{
|
||||
self::assertStringContainsString(
|
||||
'data-lesson-type="7"',
|
||||
$this->renderForStudent(['lesson_type' => '7'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testGarbageLessonTypeAttributeIsIgnored(): void
|
||||
{
|
||||
self::assertStringNotContainsString(
|
||||
'data-lesson-type',
|
||||
$this->renderForStudent(['lesson_type' => 'banana'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterCanBeTurnedOffByBlockAndShortcodeAlike(): void
|
||||
{
|
||||
self::assertStringContainsString(
|
||||
'data-type-filter="0"',
|
||||
$this->renderForStudent(['showTypeFilter' => false])
|
||||
);
|
||||
|
||||
// "no" is truthy to PHP, so the shortcode wording is matched explicitly.
|
||||
self::assertStringContainsString(
|
||||
'data-type-filter="0"',
|
||||
$this->renderForStudent(['show_filter' => 'no'])
|
||||
);
|
||||
|
||||
self::assertStringNotContainsString(
|
||||
'data-type-filter',
|
||||
$this->renderForStudent(['show_filter' => 'yes'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testBookingOnlyEmbedLeavesOutTheUpcomingLessons(): void
|
||||
{
|
||||
$html = $this->renderForStudent(['displayMode' => 'booking']);
|
||||
|
||||
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||
self::assertStringNotContainsString('us-my-lessons', $html);
|
||||
}
|
||||
|
||||
public function testUpcomingOnlyEmbedLeavesOutTheBookingCalendar(): void
|
||||
{
|
||||
$html = $this->renderForStudent(['show' => 'upcoming']);
|
||||
|
||||
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||
self::assertStringNotContainsString('us-slot-list', $html);
|
||||
self::assertStringNotContainsString('us-booking-confirmation', $html);
|
||||
}
|
||||
|
||||
public function testUnknownDisplayModeShowsTheWholePage(): void
|
||||
{
|
||||
$html = $this->renderForStudent(['displayMode' => 'sideways']);
|
||||
|
||||
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||
}
|
||||
|
||||
public function testLoginUrlFallsBackToWordPressLoginWhenThePageIsGone(): void
|
||||
{
|
||||
// The chosen page was deleted: get_permalink() returns false for it
|
||||
|
||||
Reference in New Issue
Block a user