Use spy resolveTo
This commit is contained in:
parent
30971e8c38
commit
f1afe267c2
@ -40,6 +40,7 @@ export default class uAlert {
|
|||||||
this.hasButton = typeof options.hasButton !== 'undefined' ? options.hasButton : this.autoClose === 0
|
this.hasButton = typeof options.hasButton !== 'undefined' ? options.hasButton : this.autoClose === 0
|
||||||
this.fixedPosition = options.fixed || false;
|
this.fixedPosition = options.fixed || false;
|
||||||
const html = `<div class="alert"><span>${message}</span></div>`;
|
const html = `<div class="alert"><span>${message}</span></div>`;
|
||||||
|
/** @var HTMLElement */
|
||||||
this.box = uUtils.nodeFromHtml(html);
|
this.box = uUtils.nodeFromHtml(html);
|
||||||
if (options.id) {
|
if (options.id) {
|
||||||
this.box.id = options.id;
|
this.box.id = options.id;
|
||||||
|
@ -52,7 +52,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
|
|
||||||
it('should timeout initialization of map engine', (done) => {
|
it('should timeout initialization of map engine', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.resolve());
|
spyOn(uUtils, 'loadScript').and.resolveTo();
|
||||||
// when
|
// when
|
||||||
api.init()
|
api.init()
|
||||||
.then(() => done.fail('resolve callback called'))
|
.then(() => done.fail('resolve callback called'))
|
||||||
@ -64,7 +64,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
|
|
||||||
it('should fail loading script', (done) => {
|
it('should fail loading script', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.reject(Error('script loading error')));
|
spyOn(uUtils, 'loadScript').and.rejectWith(Error('script loading error'));
|
||||||
// when
|
// when
|
||||||
api.init()
|
api.init()
|
||||||
.then(() => done.fail('resolve callback called'))
|
.then(() => done.fail('resolve callback called'))
|
||||||
@ -76,7 +76,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
|
|
||||||
it('should load and initialize api scripts', (done) => {
|
it('should load and initialize api scripts', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.resolve());
|
spyOn(uUtils, 'loadScript').and.resolveTo();
|
||||||
spyOn(api, 'initMap');
|
spyOn(api, 'initMap');
|
||||||
config.googleKey = 'key1234567890';
|
config.googleKey = 'key1234567890';
|
||||||
// when
|
// when
|
||||||
@ -109,7 +109,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
it('should initialize map engine without Google API key', (done) => {
|
it('should initialize map engine without Google API key', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(google.maps, 'Map').and.callThrough();
|
spyOn(google.maps, 'Map').and.callThrough();
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.resolve());
|
spyOn(uUtils, 'loadScript').and.resolveTo();
|
||||||
// when
|
// when
|
||||||
api.init()
|
api.init()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -124,7 +124,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
|
|
||||||
it('should fail with authorization error', (done) => {
|
it('should fail with authorization error', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.resolve());
|
spyOn(uUtils, 'loadScript').and.resolveTo();
|
||||||
lang._.and.returnValue('authfailure');
|
lang._.and.returnValue('authfailure');
|
||||||
// when
|
// when
|
||||||
api.init()
|
api.init()
|
||||||
@ -140,7 +140,7 @@ describe('Google Maps map API tests', () => {
|
|||||||
it('should show alert if authorization error occurs after initialization', (done) => {
|
it('should show alert if authorization error occurs after initialization', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(google.maps, 'Map').and.callThrough();
|
spyOn(google.maps, 'Map').and.callThrough();
|
||||||
spyOn(uUtils, 'loadScript').and.returnValue(Promise.resolve());
|
spyOn(uUtils, 'loadScript').and.resolveTo();
|
||||||
lang._.and.returnValue('authfailure');
|
lang._.and.returnValue('authfailure');
|
||||||
// when
|
// when
|
||||||
api.init()
|
api.init()
|
||||||
|
@ -135,7 +135,7 @@ describe('ConfigDialogModel tests', () => {
|
|||||||
it('should save config on positive button clicked', (done) => {
|
it('should save config on positive button clicked', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(cm, 'validate').and.returnValue(true);
|
spyOn(cm, 'validate').and.returnValue(true);
|
||||||
spyOn(config, 'save').and.returnValue(Promise.resolve());
|
spyOn(config, 'save').and.resolveTo();
|
||||||
cm.init();
|
cm.init();
|
||||||
const button = cm.dialog.element.querySelector("[data-bind='onSave']");
|
const button = cm.dialog.element.querySelector("[data-bind='onSave']");
|
||||||
// when
|
// when
|
||||||
@ -152,7 +152,7 @@ describe('ConfigDialogModel tests', () => {
|
|||||||
it('should set priority layer on save', (done) => {
|
it('should set priority layer on save', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(cm, 'validate').and.returnValue(true);
|
spyOn(cm, 'validate').and.returnValue(true);
|
||||||
spyOn(config, 'save').and.returnValue(Promise.resolve());
|
spyOn(config, 'save').and.resolveTo();
|
||||||
cm.init();
|
cm.init();
|
||||||
cm.model.layerId = '1';
|
cm.model.layerId = '1';
|
||||||
const button = cm.dialog.element.querySelector("[data-bind='onSave']");
|
const button = cm.dialog.element.querySelector("[data-bind='onSave']");
|
||||||
|
@ -243,7 +243,7 @@ describe('Position tests', () => {
|
|||||||
|
|
||||||
it('should delete image on server', (done) => {
|
it('should delete image on server', (done) => {
|
||||||
// given
|
// given
|
||||||
spyOn(uPosition, 'update').and.returnValue(Promise.resolve());
|
spyOn(uPosition, 'update').and.resolveTo();
|
||||||
const position = uPosition.fromJson(jsonPosition);
|
const position = uPosition.fromJson(jsonPosition);
|
||||||
// when
|
// when
|
||||||
position.imageDelete()
|
position.imageDelete()
|
||||||
@ -259,7 +259,7 @@ describe('Position tests', () => {
|
|||||||
// given
|
// given
|
||||||
const newImage = 'new_image.jpg';
|
const newImage = 'new_image.jpg';
|
||||||
const imageFile = 'imageFile';
|
const imageFile = 'imageFile';
|
||||||
spyOn(uPosition, 'update').and.returnValue(Promise.resolve({ image: newImage }));
|
spyOn(uPosition, 'update').and.resolveTo({ image: newImage });
|
||||||
const position = uPosition.fromJson(jsonPosition);
|
const position = uPosition.fromJson(jsonPosition);
|
||||||
// when
|
// when
|
||||||
position.imageAdd(imageFile);
|
position.imageAdd(imageFile);
|
||||||
|
@ -41,8 +41,8 @@ describe('PositionDialogModel tests', () => {
|
|||||||
track.positions[positionIndex].comment = comment;
|
track.positions[positionIndex].comment = comment;
|
||||||
state.currentTrack = track;
|
state.currentTrack = track;
|
||||||
dm = new PositionDialogModel(state, positionIndex);
|
dm = new PositionDialogModel(state, positionIndex);
|
||||||
spyOn(track.positions[positionIndex], 'save').and.returnValue(Promise.resolve());
|
spyOn(track.positions[positionIndex], 'save').and.resolveTo();
|
||||||
spyOn(track.positions[positionIndex], 'delete').and.returnValue(Promise.resolve());
|
spyOn(track.positions[positionIndex], 'delete').and.resolveTo();
|
||||||
spyOn(uObserve, 'forceUpdate');
|
spyOn(uObserve, 'forceUpdate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ describe('TrackDialogModel tests', () => {
|
|||||||
mockVM = { state: new uState(), onTrackDeleted: {} };
|
mockVM = { state: new uState(), onTrackDeleted: {} };
|
||||||
dm = new TrackDialogModel(mockVM);
|
dm = new TrackDialogModel(mockVM);
|
||||||
dm.track = TrackFactory.getTrack();
|
dm.track = TrackFactory.getTrack();
|
||||||
spyOn(dm.track, 'delete').and.returnValue(Promise.resolve());
|
spyOn(dm.track, 'delete').and.resolveTo();
|
||||||
spyOn(dm.track, 'saveMeta').and.returnValue(Promise.resolve());
|
spyOn(dm.track, 'saveMeta').and.resolveTo();
|
||||||
spyOn(dm.track, 'setName');
|
spyOn(dm.track, 'setName');
|
||||||
spyOn(uAlert, 'error');
|
spyOn(uAlert, 'error');
|
||||||
});
|
});
|
||||||
|
@ -45,12 +45,12 @@ describe('UserDialogModel tests', () => {
|
|||||||
dialogType = 'add';
|
dialogType = 'add';
|
||||||
dm = new UserDialogModel(mockVM, dialogType);
|
dm = new UserDialogModel(mockVM, dialogType);
|
||||||
dm.user = new uUser(1, 'testUser');
|
dm.user = new uUser(1, 'testUser');
|
||||||
spyOn(dm.user, 'delete').and.returnValue(Promise.resolve());
|
spyOn(dm.user, 'delete').and.resolveTo();
|
||||||
spyOn(dm.user, 'setPassword').and.returnValue(Promise.resolve());
|
spyOn(dm.user, 'setPassword').and.resolveTo();
|
||||||
spyOn(dm.user, 'modify').and.callThrough();
|
spyOn(dm.user, 'modify').and.callThrough();
|
||||||
spyOn(uUser, 'update').and.returnValue(Promise.resolve());
|
spyOn(uUser, 'update').and.resolveTo();
|
||||||
spyOn(auth.user, 'setPassword').and.returnValue(Promise.resolve());
|
spyOn(auth.user, 'setPassword').and.resolveTo();
|
||||||
spyOn(uUser, 'add').and.returnValue(Promise.resolve(newUser));
|
spyOn(uUser, 'add').and.resolveTo(newUser);
|
||||||
spyOn(config, 'validPassStrength').and.returnValue(true);
|
spyOn(config, 'validPassStrength').and.returnValue(true);
|
||||||
spyOn(uAlert, 'error');
|
spyOn(uAlert, 'error');
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user