/* test/views/user.js -- test user pages, run it with mocha
 * Copyright 2014 Sergei Ianovich
 *
 * Licensed under AGPL-3.0 or later, see LICENSE
 * Process Control Service Web Interface
 */

var expect = require('expect.js');
var Browser = require('zombie');

var browser = new Browser({ site: global.url });
function t(key, options) {
  return global.i18n.t(key, options);
}

var User = require('../../models/user');
var attrs = { name: 'Example User1"', email: "user-1@example.com",
      password: 'password', confirmation: 'password' }

var update = {};

describe('User#show page', function(){
  var user;

  before(function (done) {
    user = new User(attrs);
    user.save(function () {
      browser
      .visit('/signin')
      .then(function () {
        browser
        .fill(t('user.email'), attrs.email)
        .fill(t('user.password'), attrs.password)
        .pressButton(t('session.sign_in'))
        .then(function () {
          browser.visit('/users/' + user._id.toString()).then(done, done);
        }, done);
      }, done);
    });
  });

  it('should display user', function(){
    expect(browser.statusCode).to.be(200);
    expect(browser.query("input[value='"+user.name+"']")).to.be.true;
    expect(browser.query('input[value="'+user.email+'"]')).to.be.true;
  })

  describe('edit with valid data', function () {
    before(function (done) {
      update.name = 'New Name';
      update.email = 'new@example.com';
      browser
      .fill(t('user.name'), update.name)
      .fill(t('user.email'), update.email)
      .pressButton(t('user.update'))
      .then(done, done);
    })

    it('should show updated date', function (done) {
      expect(browser.statusCode).to.be(200);
      expect(browser.query("input[value='"+update.name+"']")).to.be.true;
      expect(browser.query('input[value="'+update.email+'"]')).to.be.true;
      User.findById(user._id, function (err, user) {
        user.name.should.equal(update.name);
        user.email.should.equal(update.email);
        done();
      });
    })
  })
});

// vim:ts=2 sts=2 sw=2 et:

@@ -269,44 +269,8 @@
 wser
- = new Browser(%7B site: global.url %7D)
 ;%0Afu
@@ -535,18 +535,8 @@
 User
-#show page
 ', f
@@ -559,32 +559,36 @@
  user;%0A%0A  before
+Each
 (function (done)
@@ -586,68 +586,212 @@
 on (
-done) %7B%0A    user = new User(attrs);%0A    user.save(function (
+) %7B%0A    browser = new Browser(%7B site: global.url %7D);%0A  %7D)%0A%0A  before(function () %7B%0A    user = new User(attrs);%0A    user.save();%0A  %7D);%0A%0A  describe('profile page', function () %7B%0A    beforeEach(function (done
 ) %7B%0A
@@ -1150,25 +1150,20 @@
 ;%0A    %7D)
-;
+%0A
 %0A  
-%7D);%0A%0A
   it('sh
@@ -1194,16 +1194,20 @@
 tion
+ 
 ()
+ 
 %7B%0A    
+  
 expe
@@ -1237,24 +1237,26 @@
 to.be(200);%0A
+  
     expect(b
@@ -1313,24 +1313,26 @@
 e.true;%0A    
+  
 expect(brows
@@ -1386,22 +1386,26 @@
 e.true;%0A
+  
   %7D)%0A%0A
+  
   descri
@@ -1437,32 +1437,34 @@
 , function () %7B%0A
+  
     before(funct
@@ -1478,24 +1478,26 @@
 ne) %7B%0A      
+  
 update.name 
@@ -1510,16 +1510,18 @@
  Name';%0A
+  
       up
@@ -1554,32 +1554,34 @@
 com';%0A      
+  
 browser%0A
       .fill(
@@ -1564,24 +1564,26 @@
     browser%0A
+  
       .fill(
@@ -1613,24 +1613,26 @@
 name)%0A      
+  
 .fill(t('use
@@ -1652,24 +1652,26 @@
 date.email)%0A
+  
       .press
@@ -1697,24 +1697,26 @@
 te'))%0A      
+  
 .then(done, 
@@ -1716,34 +1716,35 @@
 (done, done)
-;
 %0A
+  
     %7D)%0A%0A
     it('shou
@@ -1723,32 +1723,34 @@
 done)%0A      %7D)%0A%0A
+  
     it('should s
@@ -1784,32 +1784,34 @@
  (done) %7B%0A      
+ 
+ 
 expect(browser.s
@@ -1825,32 +1825,34 @@
 de).to.be(200);%0A
+  
       expect(bro
@@ -1907,32 +1907,34 @@
 .be.true;%0A      
+ 
+ 
 expect(browser.q
@@ -1992,16 +1992,18 @@
 ;%0A      
+  
 User.fin
@@ -2045,24 +2045,26 @@
 ) %7B%0A        
+ 
+ 
 user.name.sh
@@ -2084,24 +2084,26 @@
 date.name);%0A
+  
         user
@@ -2145,16 +2145,18 @@
         
+ 
+ 
 done();%0A
@@ -2161,20 +2161,31 @@
 ;%0A      
+  
 %7D);%0A
+      %7D)%0A
     %7D)%0A 

reset browser before each integration test