]> BookStack Code Mirror - bookstack/commitdiff
Added basic system tests for markdown editor, Added extra test helpers 84/head
authorDan Brown <redacted>
Tue, 29 Mar 2016 19:13:23 +0000 (20:13 +0100)
committerDan Brown <redacted>
Tue, 29 Mar 2016 19:13:23 +0000 (20:13 +0100)
Added test helpers for checking if an element exists / does not exist on a page.
Also fixed markdown editor bugs found while creating tests.

resources/assets/sass/_forms.scss
resources/views/pages/form.blade.php
tests/Entity/MarkdownTest.php [new file with mode: 0644]
tests/TestCase.php

index 4da0c39ad5d73121b8e3426745a347ba3354f03f..4a505c5f857b755761de1a99ccbb86fa09b7ee0e 100644 (file)
@@ -57,6 +57,9 @@
     padding: 0 $-m 0;
     margin-left: -1px;
     overflow-y: scroll;
     padding: 0 $-m 0;
     margin-left: -1px;
     overflow-y: scroll;
+    .page-content {
+      margin: 0 auto;
+    }
   }
 }
 .editor-toolbar {
   }
 }
 .editor-toolbar {
index fe3d28cbcf0fb003e90d1c3ffb27b1d319cbea10..7ce9dbfe5923a956634eaba2c1fcd24858f792c6 100644 (file)
@@ -68,7 +68,9 @@
                     <div class="editor-toolbar">
                         <div class="">Preview</div>
                     </div>
                     <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>
                 </div>
 
             </div>
diff --git a/tests/Entity/MarkdownTest.php b/tests/Entity/MarkdownTest.php
new file mode 100644 (file)
index 0000000..eaf4d62
--- /dev/null
@@ -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 file
index 567dc93eca876bc7426bfee781e80f35c1526ca5..f46d73e04e275d51ba2c9f923965fb6fe41b0568 100644 (file)
@@ -170,4 +170,28 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
         $this->visit($link->link()->getUri());
         return $this;
     }
         $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;
+    }
 }
 }