-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add students edit view - Finished Students Update View - Add test - Renamed StudentsUpdateCtrl to StudentsEditCtrl - Update styles - Improve responsive style - Clone show style - Align texts - Style buttons - Add angular-messages dependency for form errors - Add form errors view and style - Add form error messages to all required fields - Add toy update and cancel form functions - Add form validations trigger on submission - Add redirect after successful update - Add return to previous window location when cancel - Add new test cases
- Loading branch information
1 parent
218be46
commit 2af1fc0
Showing
20 changed files
with
559 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
define(['paw'], function(paw) { | ||
paw.controller('StudentsEditCtrl', [ | ||
'$routeParams', | ||
'$log', | ||
'$window', | ||
'$location', | ||
function($routeParams, $log, $window, $location) { | ||
|
||
var _this = this; | ||
|
||
var docket = $routeParams.docket; | ||
|
||
this.student = { | ||
docket: '55019', | ||
firstName: 'Matías', | ||
lastName: 'Mercado', | ||
email: 'mmercado@itba.edu.ar', | ||
genre: 'Masculino', | ||
dni: '38917403', | ||
birthday: '1995-05-04', | ||
address: { | ||
country: 'Argentina', | ||
city: 'Buenos Aires', | ||
neighborhood: 'Almagro', | ||
number: '682', | ||
street: 'Corrientes', | ||
floor: '2', | ||
door: 'A', | ||
telephone: '1544683390', | ||
zipCode: '1100' | ||
} | ||
}; | ||
|
||
this.editedStudent = angular.copy(this.student); | ||
|
||
this.cancel = function() { | ||
$window.history.back(); | ||
}; | ||
|
||
this.update = function(editedStudent) { | ||
$log.info('POST /students/' + docket + ' ' + JSON.stringify(editedStudent)); | ||
$location.path('/students/' + docket); | ||
}; | ||
}]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// disable max-nested-callbacks linter for this test | ||
// it is good to have a good separation of contexts inside tests | ||
|
||
/* eslint-disable max-nested-callbacks */ | ||
|
||
'use strict'; | ||
|
||
define(['paw', | ||
'angular-mocks', | ||
'controllers/students/StudentsEditCtrl'], | ||
function() { | ||
describe('Students Update Ctrl', function() { | ||
beforeEach(module('paw')); | ||
|
||
// Hardcoded data until Service call is tested | ||
var expectedStudent = { | ||
docket: '55019', | ||
firstName: 'Matías', | ||
lastName: 'Mercado', | ||
email: 'mmercado@itba.edu.ar', | ||
genre: 'Masculino', | ||
dni: '38917403', | ||
birthday: '1995-05-04', | ||
address: { | ||
country: 'Argentina', | ||
city: 'Buenos Aires', | ||
neighborhood: 'Almagro', | ||
number: '682', | ||
street: 'Corrientes', | ||
floor: '2', | ||
door: 'A', | ||
telephone: '1544683390', | ||
zipCode: '1100' | ||
} | ||
}; | ||
var docket = 123; | ||
|
||
var $controller, $rootScope, $log, $window, $location, controller; | ||
|
||
var expectedDocket = { | ||
docket: docket | ||
}; | ||
|
||
beforeEach(inject( | ||
function(_$controller_, _$rootScope_, _$log_, _$window_, _$location_) { | ||
$controller = _$controller_; | ||
$rootScope = _$rootScope_; | ||
$log = _$log_; | ||
spyOn($log, 'info'); | ||
$window = _$window_; | ||
spyOn($window.history, 'back'); | ||
$location = _$location_; | ||
spyOn($location, 'path'); | ||
controller = $controller('StudentsEditCtrl', { | ||
$routeParams: expectedDocket, | ||
$log: $log, | ||
$window: $window, | ||
$location: $location | ||
}); | ||
})); | ||
|
||
it('correctly fetch the student', function() { | ||
expect(controller.student).toEqual(expectedStudent); | ||
}); | ||
|
||
it('creates a copy of the fetched student', function() { | ||
expect(controller.editedStudent).toEqual(expectedStudent); | ||
}); | ||
|
||
describe('when calling the cancel function', function() { | ||
beforeEach(function() { | ||
controller.cancel(); | ||
}); | ||
|
||
it('is expected to go back on window history', function() { | ||
expect($window.history.back).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('when calling the update function', function() { | ||
var editedStudent, expectedLog; | ||
beforeEach(function() { | ||
editedStudent = expectedStudent; | ||
editedStudent.firstName = 'Other name'; | ||
controller.update(editedStudent); | ||
|
||
expectedLog = 'POST /students/' + docket + ' ' + JSON.stringify(editedStudent); | ||
}); | ||
|
||
it('is expected to correctly log the post', function() { | ||
expect($log.info).toHaveBeenCalledWith(expectedLog); | ||
}); | ||
|
||
it('is expected to redirect to student show view', function() { | ||
expect($location.path).toHaveBeenCalledWith('/students/' + docket); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
@import 'modules/variables/importer'; | ||
|
||
.form-errors { | ||
color: $persian-red; | ||
margin-top: -10px; | ||
} | ||
|
||
input.ng-invalid.ng-touched { | ||
border-color: $persian-red; | ||
} | ||
|
||
.form-input-field { | ||
display: block; | ||
width: 100%; | ||
height: 35px; | ||
padding: 6px 12px; | ||
margin: 0 0 15px; | ||
background-color: $white; | ||
background-image: none; | ||
border: 1px solid $silver; | ||
border-radius: 0; | ||
transition: border-color ease-in-out 0.15s; | ||
|
||
|
||
&:focus { | ||
border-color: $mine-shaft; | ||
outline: none; | ||
} | ||
} | ||
|
||
.required-fields { | ||
padding: 0 5px 15px; | ||
} | ||
|
||
.buttons-container { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
flex-wrap: wrap; | ||
|
||
.btn { | ||
min-width: 150px; | ||
width: 40%; | ||
max-width: 300px; | ||
height: 35px; | ||
margin: 5px; | ||
} | ||
} |
Oops, something went wrong.