Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Karma/Protractor config files
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/**/*.coffee'
],
multiCapabilities: [
{
// 'browserName': 'Safari'
// }, {
'browserName': 'chrome'
}, {
'browserName': 'firefox'
// }, {
// 'browserName': 'Opera'
}
],
maxSessions: 1,
baseUrl: 'http://localhost:8081/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lingui Prototype</title>
<link rel="stylesheet" href="../build/lib/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="../build/lib/bootstrap/css/bootstrap-theme.min.css" />
</head>
<body ng-app="linguiApp" class="container">
<div class="col-md-8">
<div ng-controller="MessagesController as messages" class="list-group">
<a ng-repeat="message in messages.results" ng-click="showMessage(message)"
class="message list-group-item" href="#">
[[ message.source.source ]]
[[ message.translation ]]
</a>
</div>
</div>
<div ng-controller="TranslationController as translation" class="col-md-4">
[[ activeMessage.source.translation ]]
<form class="form-horizontal">
<input ng-model="activeMessage.translation" />
<button ng-click="save()" class="btn btn-primary">Save</button>
</form>
</div>
<script type="text/javascript" src="../build/lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../build/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../build/lib/angular.js"></script>
<script type="text/javascript" src="../build/lib/angular-resource.js"></script>
<script type="text/javascript" src="../build/lib/angular-mocks.js"></script>
<script type="text/javascript" src="../build/js/services/api.js"></script>
<script type="text/javascript">
angular.module('apiService').value('apiRoot', 'http://lingui.lan:8000/api\\/')
</script>
<script type="text/javascript" src="../build/js/services/lingui.js"></script>
<script type="text/javascript" src="../build/js/apps/lingui.js"></script>
<script type="text/javascript" src="../build/js/controllers/messages.js"></script>
<script type="text/javascript" src="../build/js/controllers/translation.js"></script>
</body>
</html>
describe 'Test list view', ->
beforeEach () ->
browser.get 'list/index.html'
it 'should load messages from API on page load.', ->
browser.driver.isElementPresent(By.css '.message')
.then ->
count = element.all(By.css '.message').count()
expect count
.toEqual 2
module.exports = function(config) {
'use strict';
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'bower_components/angular-ui-select/dist/select.min.js',
'coffee/**/*.coffee',
'tests/unit/**/*.coffee'
],
// list of files / patterns to exclude
exclude: [],
reporters: ['spec'],
preprocessors: {
'**/*.coffee': ['coffee']
},
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome', 'Firefox', 'Opera', 'Safari', 'PhantomJS'],
// Continuous Integration mode
singleRun: false
});
};
'use strict'
describe 'linguiApp testing suite', ->
$httpBackend = null
beforeEach ->
module 'linguiApp'
angular.mock.module 'apiService', ($provide) ->
$provide.constant 'apiRoot', '/api'
inject (_$httpBackend_) ->
$httpBackend = _$httpBackend_
$httpBackend.whenGET '/api'
.respond
message: '/message'
$httpBackend.whenGET '/message'
.respond {
results: [
{ source: 'Hello world' },
{ source: 'Another message' },
]
}
describe 'Api Service', ->
api = null
beforeEach ->
inject ($injector) ->
api = $injector.get('api')
it 'should return root urls', ->
$httpBackend.flush()
expect api.root.message
.toBeDefined()
describe 'Lingui service', ->
lingui = null
beforeEach ->
inject ($injector) ->
lingui = $injector.get('lingui')
it 'should have empty filter', ->
expect lingui.filterParams
.toEqual {}
it 'should have undefined active message', ->
expect lingui.message
.toBeNull()
it 'should have empty message cache', ->
expect lingui.messageCache
.toEqual {}
it 'should assign active message and save it to cache', ->
message = {id: 1, source: 'Hello world'}
lingui.setActiveMessage message
expect lingui.message
.toEqual message
expect lingui.messageCache[message.id]
.toBe message
it 'should update message in cache when message is saved', ->
message = {id: 1, source: 'Hello world'}
lingui.setActiveMessage message
savedMessage = lingui.messageCache[message.id]
newMessage = {id: 1, source: 'Goodbye world'}
lingui.messageSaved newMessage
expect savedMessage
.toEqual newMessage
describe 'Messages Controller', ->
$scope = lingui = null
beforeEach ->
inject ($rootScope, $controller, $injector) ->
lingui = $injector.get('lingui')
$scope = $rootScope.$new()
$controller 'MessagesController',
$scope: $scope
it 'should set active message in parent scope', ->
message = {id: 1, source: 'Hello world'}
$scope.showMessage message
expect lingui.message
.toEqual message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.