Add track update methods
This commit is contained in:
parent
76f3855c87
commit
869d34dae1
@ -52,6 +52,11 @@ export default class uTrack extends uPositionSet {
|
|||||||
this.listItem(id, name);
|
this.listItem(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setName(name) {
|
||||||
|
this.name = name;
|
||||||
|
this.listText = name;
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
this.maxId = 0;
|
this.maxId = 0;
|
||||||
@ -214,4 +219,28 @@ export default class uTrack extends uPositionSet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete() {
|
||||||
|
return uTrack.update({
|
||||||
|
action: 'delete',
|
||||||
|
trackid: this.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
saveMeta() {
|
||||||
|
return uTrack.update({
|
||||||
|
action: 'update',
|
||||||
|
trackid: this.id,
|
||||||
|
trackname: this.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save track data
|
||||||
|
* @param {Object} data
|
||||||
|
* @return {Promise<void, Error>}
|
||||||
|
*/
|
||||||
|
static update(data) {
|
||||||
|
return uAjax.post('utils/handletrack.php', data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,16 @@ describe('Track tests', () => {
|
|||||||
expect(track.listText).toBe(name);
|
expect(track.listText).toBe(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set track name', () => {
|
||||||
|
// given
|
||||||
|
const newName = 'newName';
|
||||||
|
// when
|
||||||
|
track.setName(newName);
|
||||||
|
// then
|
||||||
|
expect(track.name).toBe(newName);
|
||||||
|
expect(track.listText).toBe(newName);
|
||||||
|
});
|
||||||
|
|
||||||
it('should clear positions data', () => {
|
it('should clear positions data', () => {
|
||||||
// given
|
// given
|
||||||
track.positions.push(new uPosition());
|
track.positions.push(new uPosition());
|
||||||
@ -408,6 +418,32 @@ describe('Track tests', () => {
|
|||||||
expect(uUtils.openUrl).toHaveBeenCalledWith(`utils/export.php?type=${type}&userid=${track.user.id}&trackid=${track.id}`);
|
expect(uUtils.openUrl).toHaveBeenCalledWith(`utils/export.php?type=${type}&userid=${track.user.id}&trackid=${track.id}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should delete track', (done) => {
|
||||||
|
// given
|
||||||
|
spyOnProperty(XMLHttpRequest.prototype, 'responseText').and.returnValue(JSON.stringify([]));
|
||||||
|
// when
|
||||||
|
track.delete()
|
||||||
|
.then(() => {
|
||||||
|
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('POST', 'utils/handletrack.php', true);
|
||||||
|
expect(XMLHttpRequest.prototype.send).toHaveBeenCalledWith(`action=delete&trackid=${track.id}`);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((e) => done.fail(`reject callback called (${e})`));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should save track meta', (done) => {
|
||||||
|
// given
|
||||||
|
spyOnProperty(XMLHttpRequest.prototype, 'responseText').and.returnValue(JSON.stringify([]));
|
||||||
|
// when
|
||||||
|
track.saveMeta()
|
||||||
|
.then(() => {
|
||||||
|
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('POST', 'utils/handletrack.php', true);
|
||||||
|
expect(XMLHttpRequest.prototype.send).toHaveBeenCalledWith(`action=update&trackid=${track.id}&trackname=${track.name}`);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((e) => done.fail(`reject callback called (${e})`));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user