From 454b99fa81b40a1d1806423effd8b37b441fb984 Mon Sep 17 00:00:00 2001
From: Jaden Diefenbaugh <blakcap@users.noreply.github.com>
Date: Tue, 18 Apr 2017 12:23:12 +0200
Subject: [PATCH] added & disabled textblock tests, enabled & fixed links tests

---
 .../static/reports/test/report-spec.js        | 101 ++++++++++++++----
 1 file changed, 83 insertions(+), 18 deletions(-)

diff --git a/beat/web/reports/static/reports/test/report-spec.js b/beat/web/reports/static/reports/test/report-spec.js
index adba33e71..aee6bb819 100644
--- a/beat/web/reports/static/reports/test/report-spec.js
+++ b/beat/web/reports/static/reports/test/report-spec.js
@@ -837,55 +837,120 @@ describe('reports app', function(){
 			});
 		});
 
-		describe('text block', function() {
-			const htmlContainer = element(by.css('#collapse-group1_text_0 > .panel-body > .row > .col-sm-10 > div'));
-			const editButton = element(by.css('#collapse-group1_text_0 > .panel-body > .row > .col-sm-2 > div > a'));
+		/*
+		 * the 'x' cancels tests from running
+		 * unfortunately there seems to be a selenium/protractor/webdriver bug
+		 * with looking into the codemirror editor (`ui-codemirror`)
+		 * none of the codemirror HTML elements are registering with
+		 * selenium/protractor as being visible
+		 */
+		xdescribe('text block', function() {
+			const getHtmlContainer = () => element(by.css('#collapse-group1_text_0 > .panel-body > .row > .col-sm-10 > div'));
+			const getEditButton = () => element(by.css('#collapse-group1_text_0')).element(by.partialLinkText('Edit'));
+
+			const text = '1. asdf';
 
 			describe('edit mode', function() {
+				it('turns on after clicking the edit button', function(){
+					getEditButton().click()
+					.then(() => {
+						browser.wait(until.presenceOf(element(by.css('.CodeMirror'))), 5000, 'Nope');
+						const editor = element.all(by.css('.CodeMirror'));
+						expect(editor.count()).toBeGreaterThan(0);
+					})
+					;
+				})
+
+				it('has cancel button', function() {
+					expect(element(by.css('#collapse-group1_text_0')).element(by.partialLinkText('Cancel'))
+					.isDisplayed()).toBeTruthy();
+				});
 
+				it('has save button', function() {
+					expect(element(by.css('#collapse-group1_text_0')).element(by.partialLinkText('Save'))
+					.isDisplayed()).toBeTruthy();
+				});
+
+				it('lets you edit the RST', function() {
+					const textArea = element(by.css('.CodeMirror textarea'));
+					expect(textArea.isDisplayed()).toBeTruthy();
+
+					textArea.sendKeys(text)
+					.then(() => expect(textArea.getAttribute('value')).toBe(text))
+					;
+				});
 			});
 
 			describe('cancelling edits', function() {
+				it('moves to view mode', function() {
+					element(by.css('#collapse-group1_text_0')).element(by.partialLinkText('Cancel'))
+					.click()
+					.then(() => expect(getEditButton().isDisplayed()).toBeTruthy())
+				});
 
+				it('didnt save the typed RST', function(){
+					expect(getHtmlContainer().getText()).toBe('');
+				});
 			});
 
 			describe('submitting edits', function() {
+				beforeAll(function(){
+					getEditButton().click()
+					.then(() => element(by.css('#collapse-group1_text_0 textarea')).sendKeys(text))
+					.then(() => element(by.css('#collapse-group1_text_0')).element(by.partialLinkText('Save')).click())
+					.then(() => browser.wait(until.presenceOf(element(by.css('#collapse-group1_text_0 ol.arabic.simple'))), 5000, 'HTML didnt render correctly'))
+					;
+				});
 
+				it('renders the text correctly', function() {
+					expect(getHtmlContainer().isDisplayed()).toBeTruthy();
+
+					expect(getHtmlContainer().getText()).toBe(
+						`<ol class="arabic simple">
+						<li>asdf</li>
+						</ol>`
+					);
+				});
 			});
 		});
 	});
 
 	// need to save report before doing these
 	describe('links outside the report page', function(){
-		const firstRowCells = element(by.css('#collapse-group1-explist tbody > tr')).all(by.css('td'));
-		describe('experiment link', function() {
-			/*
-			const link = firstRowCells.get(1).element(by.css('a'));
+		beforeAll(function(){
+			const saveButton = element(by.css('#save-button'));
 
-			afterAll(function(){
-				return browser.navigate().back();
-			});
+			return browser.executeScript('arguments[0].click();', saveButton.getWebElement());
+		});
+
+		afterEach(function(){
+			return browser.get('http://localhost:8000/reports/user/test/');
+		});
+
+		const firstRowCells = element(by.css('#collapse-group1-explist tbody > tr')).all(by.css('td'));
+		const link1 = firstRowCells.get(1).element(by.css('a'));
+		const link2 = firstRowCells.get(2).element(by.css('a'));
 
+		describe('experiment link', function() {
 			it('links to a valid experiment', function() {
-				link.click()
+				Promise.all([link1.getText(), link1.click()])
 				.then(([expName]) => expect(browser.getTitle()).toBe(`BEAT - ${expName}`))
+				;
 			});
-			*/
 		});
 
 		describe('database~protocol link', function() {
-			/*
-			const link = firstRowCells.get(2).element(by.css('a'));
-
 			afterAll(function(){
 				return browser.navigate().back();
 			});
 
 			it('links to a valid database~protocol', function() {
-				Promise.all([link.getText(), link.click()])
-				.then(([dbProtName]) => expect(browser.getTitle()).toBe(`BEAT - ${dbProtName.split('@')[0]}`))
+				Promise.all([link2.getText(), link2.click()])
+				.then(([dbProtName]) => {
+					expect(browser.getTitle()).toBe(`BEAT - ${dbProtName.split('@')[0]}`)
+				})
+				;
 			});
-			*/
 		});
 	});
 });
-- 
GitLab