From 5e05fdd1ed378b8c736f30022ff62daca86f3c93 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 8 Jan 2014 15:47:40 -0800 Subject: [PATCH] test(compile): Convert docs/content/cookbook/form.ngdoc scenerio to protractor --- docs/content/cookbook/form.ngdoc | 55 ++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/docs/content/cookbook/form.ngdoc b/docs/content/cookbook/form.ngdoc index aaa49d2f0d06..4416635864a6 100644 --- a/docs/content/cookbook/form.ngdoc +++ b/docs/content/cookbook/form.ngdoc @@ -63,40 +63,53 @@ allow a user to enter data. - + it('should show debug', function() { - expect(binding('user')).toMatch(/John Smith/); + expect(element(by.binding('user')).getText()).toMatch(/John Smith/); }); it('should add contact', function() { - using('.example').element('a:contains(add)').click(); - using('.example div:last').input('contact.value').enter('you@example.org'); - expect(binding('user')).toMatch(/\(234\) 555\-1212/); - expect(binding('user')).toMatch(/you@example.org/); + var addBtn = $('.example').findElement(by.linkText('add')); + var firstRow = $('.example').findElement(by.repeater('user.contacts').row(0)); + var contactInput = firstRow.findElement(by.model('contact.value')); + var userData = element(by.binding('user')); + + addBtn.click() + + contactInput.sendKeys('you@example.org'); + + expect(userData.getText()).toMatch(/\(234\) 555\-1212/); + expect(userData.getText()).toMatch(/you@example.org/); }); it('should remove contact', function() { - using('.example').element('a:contains(X)').click(); - expect(binding('user')).not().toMatch(/\(234\) 555\-1212/); + var removeBtn = $('.example').findElement(by.linkText('X')); + var userData = element(by.binding('user')); + + removeBtn.click() + + expect(userData.getText()).not.toMatch(/\(234\) 555\-1212/); }); it('should validate zip', function() { - expect(using('.example'). - element(':input[ng\\:model="user.address.zip"]'). - prop('className')).not().toMatch(/ng-invalid/); - using('.example').input('user.address.zip').enter('abc'); - expect(using('.example'). - element(':input[ng\\:model="user.address.zip"]'). - prop('className')).toMatch(/ng-invalid/); + var zipInput = $('.example').findElement(by.model('user.address.zip')); + + expect(zipInput.getAttribute('class')).not.toMatch(/ng-invalid/); + + zipInput.sendKeys('abc'); + + expect(zipInput.getAttribute('class')).toMatch(/ng-invalid/); }); it('should validate state', function() { - expect(using('.example').element(':input[ng\\:model="user.address.state"]').prop('className')) - .not().toMatch(/ng-invalid/); - using('.example').input('user.address.state').enter('XXX'); - expect(using('.example').element(':input[ng\\:model="user.address.state"]').prop('className')) - .toMatch(/ng-invalid/); + var stateInput = $('.example').findElement(by.model('user.address.state')); + + expect(stateInput.getAttribute('class')).not.toMatch(/ng-invalid/); + + stateInput.sendKeys('XXX'); + + expect(stateInput.getAttribute('class')).toMatch(/ng-invalid/); }); - +