Dan Brown

Added basic system tests for markdown editor, Added extra test helpers

Added test helpers for checking if an element exists / does not exist on a page.
Also fixed markdown editor bugs found while creating tests.
...@@ -57,6 +57,9 @@ ...@@ -57,6 +57,9 @@
57 padding: 0 $-m 0; 57 padding: 0 $-m 0;
58 margin-left: -1px; 58 margin-left: -1px;
59 overflow-y: scroll; 59 overflow-y: scroll;
60 + .page-content {
61 + margin: 0 auto;
62 + }
60 } 63 }
61 } 64 }
62 .editor-toolbar { 65 .editor-toolbar {
......
...@@ -68,7 +68,9 @@ ...@@ -68,7 +68,9 @@
68 <div class="editor-toolbar"> 68 <div class="editor-toolbar">
69 <div class="">Preview</div> 69 <div class="">Preview</div>
70 </div> 70 </div>
71 - <div class="markdown-display page-content" ng-bind-html="displayContent"></div> 71 + <div class="markdown-display">
72 + <div class="page-content" ng-bind-html="displayContent"></div>
73 + </div>
72 </div> 74 </div>
73 75
74 </div> 76 </div>
......
1 +<?php
2 +
3 +
4 +class MarkdownTest extends TestCase
5 +{
6 + protected $page;
7 +
8 + public function setUp()
9 + {
10 + parent::setUp();
11 + $this->page = \BookStack\Page::first();
12 + }
13 +
14 + protected function setMarkdownEditor()
15 + {
16 + $this->setSettings(['app-editor' => 'markdown']);
17 + }
18 +
19 + public function test_default_editor_is_wysiwyg()
20 + {
21 + $this->assertEquals(setting('app-editor'), 'wysiwyg');
22 + $this->asAdmin()->visit($this->page->getUrl() . '/edit')
23 + ->pageHasElement('#html-editor');
24 + }
25 +
26 + public function test_markdown_setting_shows_markdown_editor()
27 + {
28 + $this->setMarkdownEditor();
29 + $this->asAdmin()->visit($this->page->getUrl() . '/edit')
30 + ->pageNotHasElement('#html-editor')
31 + ->pageHasElement('#markdown-editor');
32 + }
33 +
34 + public function test_markdown_content_given_to_editor()
35 + {
36 + $this->setMarkdownEditor();
37 + $mdContent = '# hello. This is a test';
38 + $this->page->markdown = $mdContent;
39 + $this->page->save();
40 + $this->asAdmin()->visit($this->page->getUrl() . '/edit')
41 + ->seeInField('markdown', $mdContent);
42 + }
43 +
44 + public function test_html_content_given_to_editor_if_no_markdown()
45 + {
46 + $this->setMarkdownEditor();
47 + $this->asAdmin()->visit($this->page->getUrl() . '/edit')
48 + ->seeInField('markdown', $this->page->html);
49 + }
50 +
51 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -170,4 +170,28 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase ...@@ -170,4 +170,28 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
170 $this->visit($link->link()->getUri()); 170 $this->visit($link->link()->getUri());
171 return $this; 171 return $this;
172 } 172 }
173 +
174 + /**
175 + * Check if the page contains the given element.
176 + * @param string $selector
177 + * @return bool
178 + */
179 + protected function pageHasElement($selector)
180 + {
181 + $elements = $this->crawler->filter($selector);
182 + $this->assertTrue(count($elements) > 0, "The page does not contain an element matching " . $selector);
183 + return $this;
184 + }
185 +
186 + /**
187 + * Check if the page contains the given element.
188 + * @param string $selector
189 + * @return bool
190 + */
191 + protected function pageNotHasElement($selector)
192 + {
193 + $elements = $this->crawler->filter($selector);
194 + $this->assertFalse(count($elements) > 0, "The page contains " . count($elements) . " elements matching " . $selector);
195 + return $this;
196 + }
173 } 197 }
......