-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from lmottasin/checklist
[2.x] Add checklist render option
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ul> | ||
@foreach($data['items'] as $item) | ||
<li> | ||
<input type="checkbox" {{ $item['checked'] ? 'checked' : '' }} disabled> | ||
<span>{!! $item['text'] !!}</span> | ||
</li> | ||
@endforeach | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace AlAminFirdows\LaravelEditorJs\Tests\Feature\Blocks; | ||
|
||
use AlAminFirdows\LaravelEditorJs\Tests\TestCase; | ||
|
||
class ChecklistTest extends TestCase | ||
{ | ||
protected function getBlockData() | ||
{ | ||
return [ | ||
"type" => "checklist", | ||
"data" => [ | ||
"items" => [ | ||
[ | ||
"text" => "<a href=\"https://githuh.com/lmottasin\">LINK</a>", | ||
"checked" => true | ||
], | ||
[ | ||
"text" => "<b>BOLD</b>", | ||
"checked" => false | ||
], | ||
[ | ||
"text" => "<i>ITALIC</i>", | ||
"checked" => false | ||
], | ||
[ | ||
"text" => "PLAIN TEXT", | ||
"checked" => false | ||
] | ||
] | ||
] | ||
]; | ||
|
||
} | ||
|
||
protected function getBlockHtml() | ||
{ | ||
return '<ul> <li> <input type="checkbox" checked disabled> <span><a href="https://githuh.com/lmottasin" target="_blank" rel="noreferrer noopener">LINK</a></span> </li> <li> <input type="checkbox" disabled> <span><b>BOLD</b></span> </li> <li> <input type="checkbox" disabled> <span><i>ITALIC</i></span> </li> <li> <input type="checkbox" disabled> <span>PLAIN TEXT</span> </li> </ul>'; | ||
} | ||
|
||
/** @test */ | ||
public function render_checklist_block_test(): void | ||
{ | ||
//This replaces any sequence of whitespace (including tabs and newlines) with a single space, | ||
// normalizing the formatting in both the expected and actual HTML strings. | ||
|
||
$expectedHtml = preg_replace('/\s+/', ' ', $this->getBlockHtml()); | ||
$actualHtml = preg_replace('/\s+/', ' ', $this->renderBlocks($this->getEditorData([$this->getBlockData()]))); | ||
|
||
$this->assertEquals($expectedHtml, $actualHtml); | ||
} | ||
} |