2
0
Эх сурвалжийг харах

Added form_type setting tests

Two tests were created to see if RegisterPanel.form_type is set
to correctly to legacy or xform when receiving server registration
form.
Guillermo Bonvehí 10 жил өмнө
parent
commit
b08776a1ab
1 өөрчлөгдсөн 70 нэмэгдсэн , 0 устгасан
  1. 70 0
      spec/register.js

+ 70 - 0
spec/register.js

@@ -160,5 +160,75 @@
             expect(registerview.$('input[type=button]').length).toBe(1);
         }, converse));
 
+        it("will set form_type to legacy", $.proxy(function () {
+            var cbview = this.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = this.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(this.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            this.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Please choose a username, password and provide your email address').up()
+                    .c('username').up()
+                    .c('password').up()
+                    .c('email');
+            this.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('legacy');
+        }, converse));
+
+        it("will set form_type to xform", $.proxy(function () {
+            var cbview = this.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = this.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(this.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            this.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Using xform data').up()
+                    .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
+                        .c('instructions').t('xform instructions').up()
+                        .c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
+                        .c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
+                        .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up()
+            this.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('xform');
+        }, converse));
+
     }, converse, mock, test_utils));
 }));