From f33208126b72f7f7b2f6074b1f71952a25a41a0b Mon Sep 17 00:00:00 2001
From: Lehtinen Teemu <lehtint6@t31300-lr146.org.aalto.fi>
Date: Tue, 10 Dec 2019 12:17:53 +0200
Subject: [PATCH] Refactor names

---
 content/inspector.json => content.json |  0
 index.js                               | 28 ++++----
 package.json                           |  4 +-
 tests/content-tests.js                 | 97 ++++++++++++++++++--------
 4 files changed, 84 insertions(+), 45 deletions(-)
 rename content/inspector.json => content.json (100%)

diff --git a/content/inspector.json b/content.json
similarity index 100%
rename from content/inspector.json
rename to content.json
diff --git a/index.js b/index.js
index 37f7f93..b316f30 100644
--- a/index.js
+++ b/index.js
@@ -4,12 +4,12 @@
 var nj = require('nunjucks');
 var fs = require('fs');
 
-var WEBDEVIwdap = function () {};
+var AcosMod = function () {};
 
 var baseDir = __dirname;
-var content = JSON.parse(fs.readFileSync(baseDir + '/content/inspector.json', 'utf8'));
+var content = JSON.parse(fs.readFileSync(baseDir + '/content.json', 'utf8'));
 
-WEBDEVIwdap.initialize = function (req, params, handlers, cb) {
+AcosMod.initialize = function (req, params, handlers, cb) {
   var templateDir = baseDir + '/templates/';
   nj.configure(templateDir, { autoescape: false });
   var config = content[params.name];
@@ -18,7 +18,7 @@ WEBDEVIwdap.initialize = function (req, params, handlers, cb) {
     config.html = nj.render(config.template, config);
   }
   var templateParam = {
-    id: 'acos-webdev-iwdap-' + params.name,
+    id: 'acos-webdev-inspector-' + params.name,
     config: JSON.stringify(config),
     acceptTest: config.acceptTest,
     pointsCalculator: config.pointsCalculator
@@ -28,18 +28,18 @@ WEBDEVIwdap.initialize = function (req, params, handlers, cb) {
   cb();
 };
 
-WEBDEVIwdap.register = function (handlers, app, conf) {
-  handlers.contentPackages['webdev-iwdap'] = WEBDEVIwdap;
-  handlers.contentTypes.webdev.installedContentPackages.push(WEBDEVIwdap);
+AcosMod.register = function (handlers, app, conf) {
+  handlers.contentPackages['webdev-inspector'] = AcosMod;
+  handlers.contentTypes.webdev.installedContentPackages.push(AcosMod);
 };
 
-WEBDEVIwdap.namespace = 'webdev-iwdap';
-WEBDEVIwdap.contentTypeNamespace = 'webdev';
-WEBDEVIwdap.packageType = 'content';
+AcosMod.namespace = 'webdev-inspector';
+AcosMod.contentTypeNamespace = 'webdev';
+AcosMod.packageType = 'content';
 
-WEBDEVIwdap.meta = {
-  'name': 'webdev-iwdap',
-  'shortDescription': 'Exercise package for web development.',
+AcosMod.meta = {
+  'name': 'webdev-inspector',
+  'shortDescription': 'Exercise package using web browser inspector tool.',
   'description': '',
   'author': 'Lassi Haaranen & Teemu Lehtinen',
   'license': 'MIT',
@@ -49,4 +49,4 @@ WEBDEVIwdap.meta = {
   'contents': content
 };
 
-module.exports = WEBDEVIwdap;
+module.exports = AcosMod;
diff --git a/package.json b/package.json
index 621dda6..63916f8 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
-  "name": "acos-webdev-iwdap",
+  "name": "acos-webdev-inspector",
   "version": "0.1.0",
-  "description": "Webdev content package for introduction to web",
+  "description": "Exercise package using web browser inspector tool",
   "main": "index.js",
   "scripts": {},
   "keywords": [],
diff --git a/tests/content-tests.js b/tests/content-tests.js
index 5c15346..d66c388 100644
--- a/tests/content-tests.js
+++ b/tests/content-tests.js
@@ -1,38 +1,77 @@
-describe('acos-webdev-iwdap', function () {
+let chai = require('chai');
+chai.should();
+
+describe('Content module acos-webdev-inspector', () => {
+
+  describe('Frontpage block', () => {
+
+    it('should exist once and have teaser links', () => {
+      browser.url('/');
+
+      let matches = browser.$$('.contentPackage')
+        .filter(div => div.$('.packageTitle').getText() == 'webdev-inspector');
+      matches.should.have.lengthOf(1);
+
+      let items = matches[0].$$('.teaserContent a');
+      items.should.not.have.lengthOf(0);
+    });
 
-  it('should be displayed on the frontpage', function () {
-    return browser
-      .url('http://localhost:3000')
-      .getText('.container').then(function (text) {
-        text.should.contain('webdev-iwdap');
-      });
   });
 
-  it('hidden_button and delete_element should show up on the frontpage', function () {
-    return browser
-      .url('http://localhost:3000')
-      .getText('.container').then(function (text) {
-        text.should.contain('hidden_button');
-        text.should.contain('delete_element');
+  describe('Exercise hidden_button', () => {
+
+    it('exercise page should open', () => {
+      browser.url('/html/webdev/webdev-inspector/hidden_button');
+    });
+
+    it('should start with zero grade', () => {
+      let points = browser.$$('.guide-column .points');
+      points.should.have.lengthOf(1);
+      points[0].getText().should.equal('0 / 10 p.');
+    });
+
+    it('should include hidden button', () => {
+      let buttons = browser.$$('.exercise button');
+      buttons.should.have.lengthOf(1);
+      buttons[0].isDisplayed().should.be.false;
+    });
+
+    it('button should be set visible and then clicked', () => {
+      browser.execute(() => {
+        document.querySelector('.exercise button').removeAttribute('style')
       });
-  });
+      let button = browser.$('.exercise button');
+      button.isDisplayed().should.be.true;
+      button.click();
+      browser.waitUntil(() => $$('.explosion').length == 0, 4000, 'expected explosion effect pass');
+    });
 
-  it('hidden_button should grade correct attempts', function () {
-    return browser
-      .url('/html/webdev/webdev-iwdap/hidden_button')
-      .isVisible('#acos-webdev-iwdap-hidden_button .exercise button').then(function (vis) {
-        vis.should.be.equal(false);
-      })
-      .getText('#acos-webdev-iwdap-hidden_button .points').then(function (text) {
-        text.should.contain('0 / 10')
-      })
-      .click('#acos-webdev-iwdap-hidden_button .exercise button')
-      .getText('#acos-webdev-iwdap-hidden_button .points').then(function (text) {
-        text.should.contain('10 / 10')
-      })
-      .getAttribute('#acos-webdev-iwdap-hidden_button', 'class').then(function (classes) {
-          classes.should.contain('green');
+    it('should now display full grade', () => {
+      let points = browser.$$('.guide-column .points');
+      points.should.have.lengthOf(1);
+      points[0].getText().should.equal('10 / 10 p.');
+      points[0].getAttribute('class').should.contain('green');
+    });
+
+    it('reset button should exist and be clicked', () => {
+      let buttons = browser.$$('.guide-column .reset-button');
+      buttons.should.have.lengthOf(1);
+      buttons[0].click();
+      browser.execute(() => {
+        document.querySelector('.exercise'); // Just to force some js execution.
       });
+    });
+
+    it('state should have now reset to initial', () => {
+      let buttons = browser.$$('.exercise button');
+      buttons.should.have.lengthOf(1);
+      buttons[0].isDisplayed().should.be.false;
+      let points = browser.$$('.guide-column .points');
+      points.should.have.lengthOf(1);
+      points[0].getText().should.equal('0 / 10 p.');
+      points[0].getAttribute('class').should.not.contain('green');
+    });
+
   });
 
 });
-- 
GitLab