Sfoglia il codice sorgente

Merge pull request #29 from AToMPM/add-more-tests

Add tests for logging in a user, and loading models.
BentleyJOakes 7 anni fa
parent
commit
1fb75bf499
4 ha cambiato i file con 137 aggiunte e 20 eliminazioni
  1. 20 0
      tests/01_startup_test.js
  2. 47 0
      tests/02_login_test.js
  3. 70 0
      tests/03_model_test.js
  4. 0 20
      tests/startup_test.js

+ 20 - 0
tests/01_startup_test.js

@@ -0,0 +1,20 @@
+module.exports = {
+
+    beforeEach : function (client) {
+        client.url('http://localhost:8124/atompm').pause(300);
+    },
+
+    'Test Startup' : function (client) {
+
+        client.getTitle(function(title) {
+            this.assert.ok(title.includes("AToMPM"), "Title is AToMPM");
+        });
+
+    },
+
+
+    after : function (client) {
+        client.end();
+    },
+
+};

+ 47 - 0
tests/02_login_test.js

@@ -0,0 +1,47 @@
+module.exports = {
+
+    beforeEach : function (client) {
+        client.url('http://localhost:8124/atompm').pause(300);
+    },
+
+    'Signup user' : function (client) {
+
+        client.execute(
+            function() {
+                UserManagement.validateCredentials('testuser', 'test');
+            }, [], null
+        );
+
+
+        var user_exists = false;
+        client.getText('div[id=div_login_error]', function (result) {
+            user_exists = result.value.includes('login failed');
+
+        });
+
+        if (user_exists == false) {
+            client.execute(
+                function() {
+                    UserManagement.signup('testuser', 'test');
+                }, [], null
+            );
+
+        }
+
+        client.execute(
+            function() {
+                UserManagement.login('testuser');
+            }, [], null
+        );
+
+        client.pause(500);
+        client.getTitle(function(title) {
+            this.assert.ok(title.includes("AToMPM - [Unnamed]"), "AToMPM is opened");
+        });
+    },
+
+    after : function (client) {
+        client.end();
+    },
+
+};

+ 70 - 0
tests/03_model_test.js

@@ -0,0 +1,70 @@
+
+function loadModel(client, fnames){
+
+    for (const name of fnames) {
+
+        console.log("Loading: " + name);
+        client.execute(
+            function (fname) {
+                _loadModel(fname);
+            }, [name], null
+        );
+
+        client.pause(1000);
+
+        client.getTitle(function(title) {
+            this.assert.ok(title.includes(name), "File: " + name + " is opened");
+        });
+    }
+
+}
+
+module.exports = {
+
+    beforeEach : function (client) {
+        client.url('http://localhost:8124/atompm').pause(300);
+
+
+    },
+
+    'Login' : function (client) {
+
+        client.execute(
+            function() {
+                UserManagement.login('testuser');
+            }, [], null
+        );
+
+        client.pause(300);
+
+        client.getTitle(function(title) {
+            this.assert.ok(title.includes("AToMPM - [Unnamed]"), "AToMPM is opened");
+        });
+    },
+
+    'Load model' : function (client) {
+
+        let filename = 'Formalisms/ClassicDEVS/ClassicDEVS.model';
+
+
+        loadModel(client, [filename]);
+
+    },
+
+    //fails due to issue #28
+    // 'Load two models' : function (client) {
+    //
+    //     let filenames = [
+    //         'Formalisms/ClassicDEVS/ClassicDEVS.model',
+    //         'Formalisms/Annotation/AnnotationMM.model'
+    //     ];
+    //
+    //     loadModel(client, filenames);
+    // },
+
+
+    after : function (client) {
+        client.end();
+    },
+
+};

+ 0 - 20
tests/startup_test.js

@@ -1,20 +0,0 @@
-module.exports = {
-
-  beforeEach : function (browser) {
-    browser.url('http://localhost:8124/atompm').pause(300);
-  },
-
-  'Test Startup' : function (client) {
-
-    client.getTitle(function(title) {
-      this.assert.ok(title.includes("AToMPM"), "Title is AToMPM");
-    });
-
-
-  },
-
-  after : function (browser) {
-    browser.end();
-  },
-
-};