Input WYSIWYG: Aligned newline handling with old descriptions

To ensure consistenent behaviour before/after changes.
Added tests to cover.
This commit is contained in:
Dan Brown 2023-12-20 17:40:58 +00:00
parent a21ca44633
commit ed5d67e609
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
7 changed files with 37 additions and 4 deletions

View file

@ -15,7 +15,7 @@ trait HasHtmlDescription
*/
public function descriptionHtml(): string
{
$html = $this->description_html ?: '<p>' . e($this->description) . '</p>';
$html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
return HtmlContentFilter::removeScriptsFromHtmlString($html);
}
}

View file

@ -26,7 +26,7 @@
<main class="content-wrap card">
<h1 class="break-text">{{$book->name}}</h1>
<div refs="entity-search@contentView" class="book-content">
<p class="text-muted">{!! $book->descriptionHtml() !!}</p>
<div class="text-muted break-text">{!! $book->descriptionHtml() !!}</div>
@if(count($bookChildren) > 0)
<div class="entity-list book-contents">
@foreach($bookChildren as $childElement)

View file

@ -24,7 +24,7 @@
<main class="content-wrap card">
<h1 class="break-text">{{ $chapter->name }}</h1>
<div refs="entity-search@contentView" class="chapter-content">
<p class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</p>
<div class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</div>
@if(count($pages) > 0)
<div class="entity-list book-contents">
@foreach($pages as $page)

View file

@ -28,7 +28,7 @@
</div>
<div class="book-content">
<p class="text-muted">{!! $shelf->descriptionHtml() !!}</p>
<div class="text-muted break-text">{!! $shelf->descriptionHtml() !!}</div>
@if(count($sortedVisibleShelfBooks) > 0)
@if($view === 'list')
<div class="entity-list">

View file

@ -403,4 +403,15 @@ class BookShelfTest extends TestCase
$resp = $this->asEditor()->get($shelf->getUrl('/create-book'));
$this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel');
}
public function test_show_view_displays_description_if_no_description_html_set()
{
$shelf = $this->entities->shelf();
$shelf->description_html = '';
$shelf->description = "My great\ndescription\n\nwith newlines";
$shelf->save();
$resp = $this->asEditor()->get($shelf->getUrl());
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
}
}

View file

@ -278,6 +278,17 @@ class BookTest extends TestCase
$this->assertEquals($expected, $book->description_html);
}
public function test_show_view_displays_description_if_no_description_html_set()
{
$book = $this->entities->book();
$book->description_html = '';
$book->description = "My great\ndescription\n\nwith newlines";
$book->save();
$resp = $this->asEditor()->get($book->getUrl());
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
}
public function test_show_view_has_copy_button()
{
$book = $this->entities->book();

View file

@ -31,6 +31,17 @@ class ChapterTest extends TestCase
$resp->assertSee($chapter->description_html, false);
}
public function test_show_view_displays_description_if_no_description_html_set()
{
$chapter = $this->entities->chapter();
$chapter->description_html = '';
$chapter->description = "My great\ndescription\n\nwith newlines";
$chapter->save();
$resp = $this->asEditor()->get($chapter->getUrl());
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
}
public function test_delete()
{
$chapter = Chapter::query()->whereHas('pages')->first();