Commit 0219e2a3 authored by Laurent's avatar Laurent

add some tests

parent 6c2cbe13
......@@ -39,14 +39,7 @@ export class LibraryController extends Controller {
public constructor(account: Account) {
super();
this._account = account;
// (new Manager())
// .connect(account)
// .then( () => {
// Database.current().save(this._account);
// });
this._account = account;
this._portal = new Portal();
this._loadLoansAndHolds();
......@@ -58,6 +51,14 @@ export class LibraryController extends Controller {
this.set('show_novelties', this._portal.canFetchNovelties(this._account));
this.set('busy', 'off');
this.set('card', this._account.getCard());
this.set('sip_loan', false);
(new Manager())
.connect(Database.current(), this._account)
.then( (portal) => {
this.set('sip_loan', portal.sip_loan_feature);
});
}
......
......@@ -45,6 +45,11 @@ export class Manager {
.setFeatures(datas.features);
db.save(portal);
return portal;
})
.catch( () => {
portal.setFeatures([]);
db.save(portal);
return portal;
});
}
......
......@@ -53,6 +53,19 @@ export class ManagerConnectAnnecy extends HTTPScenario {
export class ManagerConnectAnnecyNotFound extends HTTPScenario {
public constructor(base_url: string) {
super();
this
.expect({ url: base_url + '/api/portal/library.annecy.fr',
headers: { "Content-Type": "application/json" } },
{ content: '',
statusCode: 404 });
}
}
describe('Manager', () => {
let manager: Manager;
let db: Database;
......@@ -90,6 +103,18 @@ describe('Manager', () => {
expect(updated.getId()).to.equals(portal.getId());
});
})
it('with no existing description it should stub it', () => {
return manager
.setHTTP(new ManagerConnectAnnecyNotFound('http://mbam.org'))
.connect(db, annecy).then( (portal) => {
expect(portal.getLabel()).to.equals('');
expect(portal.getURL()).to.equals('http://library.annecy.fr');
expect(portal.getKey()).to.equals('library.annecy.fr');
expect(portal.sip_loan_feature).to.be.false;
});
})
});
......
......@@ -9,6 +9,11 @@
<Label text="{{ '&#xf2c2; ' + L('show_card') }}" class="fa" />
</StackLayout>
<StackLayout tap="{{ }}" visibility="{{ sip_loan ? 'visible' : 'collapsed' }}" >
<Label text="{{ '&#xf2c2; ' + L('sip_loan') }}" class="fa" />
</StackLayout>
<StackLayout tap="{{ showNoveltiesAction }}" visibility="{{ show_novelties ? 'visible' : 'collapsed' }}" >
<Label text="{{ '&#xf06d; ' + L('novelties') }}" class="fa" />
</StackLayout>
......
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