NOW MANAGED ON CODEBERG
Added basic system tests for markdown editor, Added extra test helpers
Dan Browndc2978824ee9
diff --git a/resources/assets/sass/_forms.scss b/resources/assets/sass/_forms.scssindex 4da0c39ad..4a505c5f8 100644--- a/resources/assets/sass/_forms.scss+++ b/resources/assets/sass/_forms.scss@@ -57,6 +57,9 @@padding: 0 $-m 0;margin-left: -1px;overflow-y: scroll;+ .page-content {+ margin: 0 auto;+ }}}.editor-toolbar {diff --git a/resources/views/pages/form.blade.php b/resources/views/pages/form.blade.phpindex fe3d28cbc..7ce9dbfe5 100644--- a/resources/views/pages/form.blade.php+++ b/resources/views/pages/form.blade.php@@ -68,7 +68,9 @@<div class="editor-toolbar"><div class="">Preview</div></div>- <div class="markdown-display page-content" ng-bind-html="displayContent"></div>+ <div class="markdown-display">+ <div class="page-content" ng-bind-html="displayContent"></div>+ </div></div></div>diff --git a/tests/Entity/MarkdownTest.php b/tests/Entity/MarkdownTest.phpnew file mode 100644index 000000000..eaf4d62c3--- /dev/null+++ b/tests/Entity/MarkdownTest.php@@ -0,0 +1,51 @@+<?php+++class MarkdownTest extends TestCase+{+ protected $page;++ public function setUp()+ {+ parent::setUp();+ $this->page = \BookStack\Page::first();+ }++ protected function setMarkdownEditor()+ {+ $this->setSettings(['app-editor' => 'markdown']);+ }++ public function test_default_editor_is_wysiwyg()+ {+ $this->assertEquals(setting('app-editor'), 'wysiwyg');+ $this->asAdmin()->visit($this->page->getUrl() . '/edit')+ ->pageHasElement('#html-editor');+ }++ public function test_markdown_setting_shows_markdown_editor()+ {+ $this->setMarkdownEditor();+ $this->asAdmin()->visit($this->page->getUrl() . '/edit')+ ->pageNotHasElement('#html-editor')+ ->pageHasElement('#markdown-editor');+ }++ public function test_markdown_content_given_to_editor()+ {+ $this->setMarkdownEditor();+ $mdContent = '# hello. This is a test';+ $this->page->markdown = $mdContent;+ $this->page->save();+ $this->asAdmin()->visit($this->page->getUrl() . '/edit')+ ->seeInField('markdown', $mdContent);+ }++ public function test_html_content_given_to_editor_if_no_markdown()+ {+ $this->setMarkdownEditor();+ $this->asAdmin()->visit($this->page->getUrl() . '/edit')+ ->seeInField('markdown', $this->page->html);+ }++}\ No newline at end of filediff --git a/tests/TestCase.php b/tests/TestCase.phpindex 567dc93ec..f46d73e04 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -170,4 +170,28 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase$this->visit($link->link()->getUri());return $this;}++ /**+ * Check if the page contains the given element.+ * @param string $selector+ * @return bool+ */+ protected function pageHasElement($selector)+ {+ $elements = $this->crawler->filter($selector);+ $this->assertTrue(count($elements) > 0, "The page does not contain an element matching " . $selector);+ return $this;+ }++ /**+ * Check if the page contains the given element.+ * @param string $selector+ * @return bool+ */+ protected function pageNotHasElement($selector)+ {+ $elements = $this->crawler->filter($selector);+ $this->assertFalse(count($elements) > 0, "The page contains " . count($elements) . " elements matching " . $selector);+ return $this;+ }}