Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more view tests for the navigation menu #1603

Merged
merged 5 commits into from
Mar 10, 2024
Merged
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
45 changes: 45 additions & 0 deletions packages/framework/tests/Unit/Views/NavigationMenuViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Hyde\Framework\Testing\Unit\Views;

use Illuminate\Support\Str;
use Hyde\Facades\Filesystem;
use Hyde\Hyde;
use Hyde\Testing\TestCase;
use Hyde\Pages\MarkdownPage;

/**
* @see resources/views/layouts/navigation.blade.php
Expand Down Expand Up @@ -55,6 +57,49 @@ public function testComponentNotContains404HtmlLink()
$this->assertStringNotContainsString('href="404.html"', $this->render());
}

public function testNavigationMenuWithRootPages()
{
$foo = new MarkdownPage('foo');
$bar = new MarkdownPage('bar');

Hyde::routes()->add($foo->getRoute());
Hyde::routes()->add($bar->getRoute());

$this->mockRoute($foo->getRoute());
$this->mockPage($foo);

$contents = $foo->compile();

$this->assertStringContainsString('<a href="foo.html" aria-current="page" class="', $contents);
$this->assertStringContainsString('<a href="bar.html" class="', $contents);
}

public function testNavigationMenuWithDropdownPages()
{
config(['hyde.navigation.subdirectories' => 'dropdown']);

$foo = new MarkdownPage('foo');
$bar = new MarkdownPage('foo/bar');
$baz = new MarkdownPage('foo/baz');

Hyde::routes()->add($foo->getRoute());
Hyde::routes()->add($bar->getRoute());
Hyde::routes()->add($baz->getRoute());

$this->mockRoute($foo->getRoute());
$this->mockPage($foo);

$contents = $foo->compile();

$this->assertStringContainsString('dropdown-container', $contents);
$this->assertStringContainsString('dropdown-button', $contents);

$dropdown = Str::between($contents, '<ul class="dropdown-items', '</ul>');

$this->assertStringContainsString('<a href="foo/bar.html"', $dropdown);
$this->assertStringContainsString('<a href="foo/baz.html"', $dropdown);
}

public function testNavigationMenuLabelCanBeChangedInFrontMatter()
{
$this->file('_pages/foo.md', '---
Expand Down
Loading