Commit edf594db authored by laurent l's avatar laurent l

tns test works on ios

parent 463170df
declare var describe, expect, it, before, chai: any;
import {AccountsController} from '../controllers/accounts';
import {LibraryController} from '../controllers/library';
import {Account, Database, Manager, NullHTTPClient} from '../models/';
import {StubFrames} from './stub-frames';
import { AccountsController } from '../controllers/accounts';
import { LibraryController } from '../controllers/library';
import { Account, Database, Manager, NullHTTPClient } from '../models/';
import { StubFrames } from './stub-frames';
describe('AccountsController with one account in database', () => {
let db: Database;
let accounts_controller: AccountsController;
let navigate_spy;
let goback_spy;
let bibliofil: Account;
let db: Database;
let accounts_controller: AccountsController;
let navigate_spy;
let goback_spy;
let bibliofil: Account;
let manager: Manager;
before( () => {
bibliofil = new Account().setLabel('Bibliofil');
manager = new Manager('http://nowhere.com', new NullHTTPClient());
db = Database.open('testdb').clear();
db.save(bibliofil);
accounts_controller = new AccountsController(manager);
accounts_controller.frames = new StubFrames();
navigate_spy = chai.spy.on(accounts_controller.frames, 'navigate');
goback_spy = chai.spy.on(accounts_controller.frames, 'goBack');
});
it('should return this account in an ObservableArray', () => {
expect(accounts_controller.get('accounts').getItem(0).label).to.equals('Bibliofil');
});
describe('when clicking add account/add', () => {
before( () => {
accounts_controller.addAccountAction();
});
it('should navigate to account/add view when clicking addAccount', () => {
expect(navigate_spy).to.have.been.called.with({moduleName: "views/accounts/add_account",
bindingContext: accounts_controller,
backstackVisible: false});
});
it('should return Bokeh in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('Bokeh');
})
it('should return PMB in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('PMB');
})
it('should return OrphéeMedia in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('OrphéeMedia');
})
describe('then saving account for Orphee', () => {
let new_account;
before( () => {
let form = accounts_controller.get('account');
form.label = 'My library';
form.url = 'http://orpheemedia.com';
form.portals = ['Bokeh', 'OrphéeMedia', 'PMB'];
form.selectedPortalIndex = 1;
form.login = 'pacman';
form.password = 'secret';
accounts_controller.saveAccountAction();
new_account = db.findAll(Account)
.filter((account) => { return account.label == 'My library' })[0];
});
it('should create a new Account', () => {
expect(db.findAll(Account)).to.have.lengthOf(2);
});
it('should set account label to My library', () => {
new_account.label.should.equals('My library');
});
it('should set account url to http://orpheemedia.com', () => {
new_account.url.should.equals('http://orpheemedia.com');
});
it('should set credentials to {portal: "orpheemedia", login:"pacman", password:"secret"}', () => {
new_account.credentials.portal.should.equals("orpheemedia");
new_account.credentials.should.deep.equals({
portal: "orpheemedia",
login: "pacman",
password: "secret"
});
});
})
});
it('should open loans view when selecting first account', () => {
navigate_spy = chai.spy.on(accounts_controller.frames, 'navigate');
accounts_controller.openAccountAction({index:0});
let first_account = accounts_controller.get('accounts').getItem(0);
expect(navigate_spy).to.have.been.called.with({moduleName: "views/library/items",
bindingContext: new LibraryController(first_account, manager)});
});
before(() => {
bibliofil = new Account().setLabel('Bibliofil');
manager = new Manager('http://nowhere.com', new NullHTTPClient());
db = Database.open('testdb').clear();
db.save(bibliofil);
accounts_controller = new AccountsController(manager);
accounts_controller.frames = new StubFrames();
navigate_spy = chai.spy.on(accounts_controller.frames, 'navigate');
goback_spy = chai.spy.on(accounts_controller.frames, 'goBack');
});
it('should return this account in an ObservableArray', () => {
expect(accounts_controller.get('accounts').getItem(0).label).to.equals('Bibliofil');
});
describe('when clicking add account/add', () => {
before(() => {
accounts_controller.addAccountAction();
});
it('should navigate to account/add view when clicking addAccount', () => {
expect(navigate_spy).to.have.been.called.with({
moduleName: "views/accounts/add_account",
bindingContext: accounts_controller,
backstackVisible: false
});
});
it('should return Bokeh in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('Bokeh');
})
it('should return PMB in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('PMB');
})
it('should return OrphéeMedia in connectors list', () => {
expect(accounts_controller.get('account').portals).to.include('OrphéeMedia');
})
describe('then saving account for Orphee', () => {
let new_account;
before(() => {
let form = accounts_controller.get('account');
form.label = 'My library';
form.url = 'http://orpheemedia.com';
form.portals = ['Bokeh', 'OrphéeMedia', 'PMB'];
form.selectedPortalIndex = 1;
form.login = 'pacman';
form.password = 'secret';
accounts_controller.saveAccountAction();
new_account = db.findAll(Account)
.filter((account) => { return account.label == 'My library' })[0];
});
it('should create a new Account', () => {
expect(db.findAll(Account)).to.have.lengthOf(2);
});
it('should set account label to My library', () => {
new_account.label.should.equals('My library');
});
it('should set account url to http://orpheemedia.com', () => {
new_account.url.should.equals('http://orpheemedia.com');
});
it('should set credentials to {portal: "orpheemedia", login:"pacman", password:"secret"}', () => {
new_account.credentials.portal.should.equals("orpheemedia");
new_account.credentials.should.deep.equals({
portal: "orpheemedia",
login: "pacman",
password: "secret"
});
});
})
});
it('should open loans view when selecting first account', () => {
accounts_controller.openAccountAction({ index: 0 });
let first_account = accounts_controller.get('accounts').getItem(0);
expect(navigate_spy).to.have.been.called.with({
moduleName: "views/library/items",
bindingContext: new LibraryController(first_account, manager)
});
});
});
declare var describe, expect, it, beforeEach, chai: any;
import {LibraryController} from '../controllers/library';
import {AccountsController} from '../controllers/accounts';
import {Loan, Account, Database, Portal, Manager, NullHTTPClient} from '../models/';
import {StubFrames} from './stub-frames';
import {OrpheeMediaWithCasLoansSuccessful} from './portal/orpheemedia-fixtures';
import { LibraryController } from '../controllers/library';
import { AccountsController } from '../controllers/accounts';
import { Loan, Account, Database, Portal, Manager, NullHTTPClient } from '../models/';
import { StubFrames } from './stub-frames';
import { OrpheeMediaWithCasLoansSuccessful } from './portal/orpheemedia-fixtures';
describe('Loans for account bibliofil', () => {
......@@ -11,41 +11,44 @@ describe('Loans for account bibliofil', () => {
let bibliofil: Account;
let library_controller: LibraryController;
let manager: Manager;
beforeEach( () => {
beforeEach(() => {
manager = new Manager('http://nowhere.com', new NullHTTPClient());
db = Database.open('testdb').clear();
bibliofil = (new Account())
.setLabel('Bibliofil')
.setUrl('http://bibliofil.fr')
.setCredentials({login: 'marco',
password: 'polo',
portal: 'orpheemedia'});
.setCredentials({
login: 'marco',
password: 'polo',
portal: 'orpheemedia'
});
db.save(bibliofil);
db.save((new Loan())
.setTitle('Harry Potter')
.setDateDue('2017-05-12')
.setAccount(bibliofil));
.setTitle('Harry Potter')
.setDateDue('2017-05-12')
.setAccount(bibliofil));
db.save((new Loan())
.setTitle('Millenium')
.setDateDue('2017-05-14')
.setAccount(bibliofil));
.setTitle('Millenium')
.setDateDue('2017-05-14')
.setAccount(bibliofil));
let other_account = new Account();
db.save(other_account);
db.save((new Loan())
.setTitle('Pomme api')
.setDateDue('2017-05-12')
.setAccount(other_account));
.setTitle('Pomme api')
.setDateDue('2017-05-12')
.setAccount(other_account));
db.save((new Loan())
.setTitle('I have no account')
.setDateDue('2017-05-12'));
.setTitle('I have no account')
.setDateDue('2017-05-12'));
library_controller = new LibraryController(bibliofil, manager);
library_controller.frames = new StubFrames();
......@@ -55,24 +58,24 @@ describe('Loans for account bibliofil', () => {
it('loans should return two items', () => {
expect(library_controller.get('loans')).to.have.lengthOf(2);
});
describe('refresh action', () => {
let refresh_spy;
let refresh_promise;
it('adapter for orpheemedia should receive message to refresh loans', () => {
let portal: Portal = new Portal();
refresh_spy = chai
.spy.on(portal.findAdapterIdentifiedBy('orpheemedia')
.setHTTP(new OrpheeMediaWithCasLoansSuccessful('http://bibliofil.fr')),
'refresh');
library_controller.setPortal(portal);
return library_controller.refreshLoansAndHoldsAction().then( () => {
expect(refresh_spy).to.have.been.called.with(bibliofil);
describe('refresh action', () => {
let refresh_spy;
let refresh_promise;
it('adapter for orpheemedia should receive message to refresh loans', () => {
let portal: Portal = new Portal();
refresh_spy = chai
.spy.on(portal.findAdapterIdentifiedBy('orpheemedia')
.setHTTP(new OrpheeMediaWithCasLoansSuccessful('http://bibliofil.fr')),
'refresh');
library_controller.setPortal(portal);
return library_controller.refreshLoansAndHoldsAction().then(() => {
expect(refresh_spy).to.have.been.called.with(bibliofil);
});
});
});
});
});
});
module.exports = require("nativescript-unit-test-runner/lib/after-prepare");
module.exports = require("nativescript-unit-test-runner/./lib/after-prepare.js");
{
"description": "MyBibApp is a mobile application to access every library portal",
"license": "AGPL-3.0-only",
"readme": "README.md",
"repository": "git@git.afi-sa.fr:my-bib-app/my-bib-app.git",
"nativescript": {
"id": {
"android": "fr.afi_sa.MyBibApp",
"ios": "fr.afisa.MyBibApp"
"description": "MyBibApp is a mobile application to access every library portal",
"license": "AGPL-3.0-only",
"readme": "README.md",
"repository": "git@git.afi-sa.fr:my-bib-app/my-bib-app.git",
"nativescript": {
"id": {
"android": "fr.afi_sa.MyBibApp",
"ios": "fr.afisa.MyBibApp"
},
"tns-android": {
"version": "5.2.1"
},
"tns-ios": {
"version": "5.2.0"
}
},
"tns-android": {
"version": "5.2.1"
"dependencies": {
"cheerio": "^0.22.0",
"events": "^1.1.1",
"jstoxml": "^1.4.3",
"nativescript-android-utils": "^1.0.2",
"nativescript-appversion": "^1.4.1",
"nativescript-barcodescanner": "^2.7.7",
"nativescript-couchbase": "git+https://github.com/Afibre/nativescript-couchbase.git",
"nativescript-i18n": "^0.2.4",
"nativescript-intl": "^3.0.0",
"nativescript-local-notifications": "^2.0.0",
"nativescript-swiss-army-knife": "^3.1.1",
"nativescript-theme-core": "^1.0.4",
"nativescript-ui-autocomplete": "^3.5.0",
"nativescript-ui-core": "^2.0.1",
"nativescript-ui-listview": "^3.8.0",
"nativescript-ui-sidedrawer": "^5.1.0",
"nativescript-unit-test-runner": "^0.5.1",
"nativescript-zxing": "git+https://github.com/Afibre/nativescript-zxing.git",
"papaparse": "^4.3.7",
"tns-core-modules": "^5.2.2",
"tns-platform-declarations": "^3.4.0",
"url-parse": "^1.4.4",
"validator": "^7.0.0",
"xml-js": "^1.6.7"
},
"tns-ios": {
"version": "5.2.0"
"devDependencies": {
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"css-loader": "~0.28.7",
"karma": "^4.0.1",
"karma-chai": "^0.1.0",
"karma-chai-spies": "^0.1.4",
"karma-mocha": "^1.3.0",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"mocha": "^6.0.2",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-sass": "^1.6.0",
"nativescript-dev-typescript": "^0.9.0",
"nativescript-dev-webpack": "^0.20.3",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"sass-loader": "^7.1.0",
"typescript": "^3.3.4000"
},
"nativescript-i18n": {
"defaultLang": "en"
},
"scripts": {
"ns-bundle": "ns-bundle",
"publish-ios-bundle": "npm run ns-bundle --ios --publish-app",
"generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install",
"start-android-bundle": "npm run ns-bundle --android --run-app",
"start-ios-bundle": "npm run ns-bundle --ios --run-app",
"build-android-bundle": "npm run ns-bundle --android --build-app",
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
}
},
"dependencies": {
"cheerio": "^0.22.0",
"events": "^1.1.1",
"jstoxml": "^1.4.3",
"nativescript-android-utils": "^1.0.2",
"nativescript-appversion": "^1.4.1",
"nativescript-barcodescanner": "^2.7.7",
"nativescript-couchbase": "git+https://github.com/Afibre/nativescript-couchbase.git",
"nativescript-i18n": "^0.2.4",
"nativescript-intl": "^3.0.0",
"nativescript-local-notifications": "^2.0.0",
"nativescript-swiss-army-knife": "^3.1.1",
"nativescript-theme-core": "^1.0.4",
"nativescript-ui-autocomplete": "^3.5.0",
"nativescript-ui-core": "^2.0.1",
"nativescript-ui-listview": "^3.8.0",
"nativescript-ui-sidedrawer": "^5.1.0",
"nativescript-zxing": "git+https://github.com/Afibre/nativescript-zxing.git",
"papaparse": "^4.3.7",
"tns-core-modules": "^5.2.2",
"tns-platform-declarations": "^3.4.0",
"url-parse": "^1.4.4",
"validator": "^7.0.0",
"xml-js": "^1.6.7"
},
"devDependencies": {
"awesome-typescript-loader": "~3.1.3",
"babel-traverse": "6.22.1",
"babel-types": "6.22.0",
"babylon": "6.15.0",
"chai": "^3.5.0",
"chai-spies": "^0.7.1",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.0.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"karma": "^3.1.1",
"karma-chai": "^0.1.0",
"karma-chai-spies": "^0.1.4",
"karma-mocha": "^1.3.0",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"mocha": "^3.2.0",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-sass": "^1.6.0",
"nativescript-dev-typescript": "^0.5.1",
"nativescript-dev-webpack": "^0.10.1",
"nativescript-worker-loader": "~0.8.1",
"nativescript-unit-test-runner": "^0.3.4",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"typescript": "2.4.0",
"uglifyjs-webpack-plugin": "~1.1.6",
"webpack": "~3.2.0",
"webpack-bundle-analyzer": "^2.8.2",
"webpack-sources": "~1.0.1",
"sass-loader": "~6.0.6"
},
"nativescript-i18n": {
"defaultLang": "en"
},
"scripts": {
"ns-bundle": "ns-bundle",
"publish-ios-bundle": "npm run ns-bundle --ios --publish-app",
"generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install",
"start-android-bundle": "npm run ns-bundle --android --run-app",
"start-ios-bundle": "npm run ns-bundle --ios --run-app",
"build-android-bundle": "npm run ns-bundle --android --build-app",
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
}
}
......@@ -16,6 +16,9 @@
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
],
"~/*": [
"app/*"
]
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment