pageRepo = app()->make(PageRepo::class);
}
public function test_get_page_nav_sets_correct_properties()
{
$content = '
Hello
There
Donkey
';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap);
$this->assertArraySubset([
'nodeName' => 'h1',
'link' => '#testa',
'text' => 'Hello',
'level' => 1,
], $navMap[0]);
$this->assertArraySubset([
'nodeName' => 'h2',
'link' => '#testb',
'text' => 'There',
'level' => 2,
], $navMap[1]);
$this->assertArraySubset([
'nodeName' => 'h3',
'link' => '#testc',
'text' => 'Donkey',
'level' => 3,
], $navMap[2]);
}
public function test_get_page_nav_does_not_show_empty_titles()
{
$content = 'Hello
';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(1, $navMap);
$this->assertArraySubset([
'nodeName' => 'h1',
'link' => '#testa',
'text' => 'Hello'
], $navMap[0]);
}
public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
{
$content = 'Hello
There
Donkey
';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap);
$this->assertArraySubset([
'nodeName' => 'h4',
'level' => 1,
], $navMap[0]);
$this->assertArraySubset([
'nodeName' => 'h5',
'level' => 2,
], $navMap[1]);
$this->assertArraySubset([
'nodeName' => 'h6',
'level' => 3,
], $navMap[2]);
}
}