-
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.
Showing
5 changed files
with
181 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
define(['paw'], function(paw) { | ||
paw.controller('CoursesIndexCtrl', ['$routeParams', function($routeParams) { | ||
var _this = this; | ||
this.filter = { | ||
courseId: $routeParams.courseId, | ||
courseName: $routeParams.courseName | ||
}; | ||
this.resetSearch = function() { | ||
this.filter = {}; | ||
}; | ||
this.courses = [ | ||
{ | ||
courseId: '72.03', | ||
credits: 3, | ||
name: 'Introducción a Informática', | ||
semester: 1 | ||
}, | ||
{ | ||
courseId: '94.21', | ||
credits: 6, | ||
name: 'Formacion General I', | ||
semester: 5 | ||
} | ||
]; | ||
}]); | ||
}); |
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
76 changes: 76 additions & 0 deletions
76
app/specs/controllers/courses/CoursesIndexController.spec.js
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,76 @@ | ||
// 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/courses/CoursesIndexCtrl'], | ||
function() { | ||
describe('Courses Index Ctrl', function() { | ||
beforeEach(module('paw')); | ||
|
||
// Hardcoded data until Service call is tested | ||
var expectedCourses = [ | ||
{ | ||
courseId: '72.03', | ||
credits: 3, | ||
name: 'Introducción a Informática', | ||
semester: 1 | ||
}, | ||
{ | ||
courseId: '94.21', | ||
credits: 6, | ||
name: 'Formacion General I', | ||
semester: 5 | ||
} | ||
]; | ||
|
||
var $controller, $rootScope, controller; | ||
|
||
var expectedParams = { | ||
courseId: '72.', | ||
courseName: 'Introducción a' | ||
}; | ||
|
||
beforeEach(inject( | ||
function(_$controller_, _$rootScope_) { | ||
$controller = _$controller_; | ||
$rootScope = _$rootScope_; | ||
controller = $controller('CoursesIndexCtrl', {$routeParams: expectedParams}); | ||
})); | ||
|
||
it('correctly fetch the courses', function() { | ||
expect(controller.courses).toEqual(expectedCourses); | ||
}); | ||
|
||
describe('when initializing the filter values', function() { | ||
it('correctly fetch the course id', function() { | ||
expect(controller.filter.courseId).toEqual(expectedParams.courseId); | ||
}); | ||
|
||
it('correctly fetch the course name', function() { | ||
expect(controller.filter.courseName).toEqual(expectedParams.courseName); | ||
}); | ||
}); | ||
|
||
describe('when reset button is clicked', function() { | ||
beforeEach(function() { | ||
controller.filter = {}; | ||
controller.filter.courseId = '72.'; | ||
controller.filter.courseName = 'Introducción a'; | ||
controller.resetSearch(); | ||
}); | ||
|
||
it('clears the course id search input', function() { | ||
expect(controller.filter).toEqual({}); | ||
}); | ||
|
||
it('clears the course name search input', function() { | ||
expect(controller.filter).toEqual({}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,65 @@ | ||
<div ng-controller='CoursesIndexCtrl as controller'> | ||
<div class='courses-index-container'> | ||
<!-- Page Heading --> | ||
<h1 translate='i18nCoursesPanelSection' class='page-header'></h1> | ||
<!-- /Page Heading --> | ||
|
||
<!-- Filter --> | ||
<div class='filter-container'> | ||
<div class='filter-fields'> | ||
<div class='own-input-group'> | ||
<span class='search-label' translate=i18nCourseId></span> | ||
<input type='text' class='form-input-field' ng-model='controller.filter.courseId' placeholder="{{ 'i18nCourseId' | translate }}..."/> | ||
</div> | ||
<div class='own-input-group'> | ||
<span class='search-label' translate='i18nCourseName'></span> | ||
<input type='text' class='form-input-field' ng-model='controller.filter.courseName' placeholder="{{ 'i18nCourseName' | translate }}..."/> | ||
</div> | ||
</div> | ||
<div class='filter-buttons'> | ||
<button class='btn btn-default' type='submit'> | ||
<span class='fa fa-search' aria-hidden='true'></span> | ||
<span translate='i18nSearchButton' translate ></span> | ||
</button> | ||
<button class='btn btn-default' ng-click='controller.resetSearch()' type='submit'> | ||
<span class='fa fa-repeat' aria-hidden='true'></span> | ||
<span translate='i18nResetButton'></span> | ||
</button> | ||
</div> | ||
</div> | ||
<!-- /Filter --> | ||
|
||
<!-- Content --> | ||
<div class='table-responsive'> | ||
<table class='table table-hover'> | ||
<thead> | ||
<tr> | ||
<th translate='i18nCourseId'></th> | ||
<th translate='i18nCourseName'></th> | ||
<th translate='i18nCredits'></th> | ||
<th translate='i18nSemester'></th> | ||
<th translate='i18nActions'></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr ng-hide='controller.courses.length > 0' class='bg-warning'> | ||
<td colspan='5' class='text-danger text-center' translate='i18nNoCoursesFound'></td> | ||
</tr> | ||
<tr ng-repeat='course in controller.courses'> | ||
<td>{{ course.courseId }}</td> | ||
<td>{{ course.name }}</td> | ||
<td>{{ course.credits }}</td> | ||
<td>{{ course.semester }}</td> | ||
<td class='actions-container'> | ||
<a class='btn btn-default' role='button'> | ||
<span class='fa fa-info-circle' aria-hidden='true'></span> | ||
<span translate='i18nCourseShow'></span> | ||
</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<!-- Content --> | ||
</div> | ||
</div> |