final amends on tests and model descriptions
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-03-01 22:21:04 +01:00
parent 021601fb26
commit fe7017f83c
4 changed files with 21 additions and 7 deletions

View File

@ -1,6 +1,6 @@
module.exports = function(Self) {
Self.remoteMethodCtx('getStarredModules', {
description: 'returns the receved modules adding the starred property.',
description: 'returns the starred modules for the current user',
returns: {
type: 'object',
root: true

View File

@ -1,6 +1,6 @@
module.exports = function(Self) {
Self.remoteMethodCtx('toggleStarredModule', {
description: 'returns the receved modules adding the starred property.',
description: 'creates or deletes a starred module for the current user',
returns: {
type: 'object',
root: true

View File

@ -48,12 +48,12 @@ export default class Controller extends Component {
const params = {moduleName: module.name};
const query = `starredModules/toggleStarredModule`;
this.$http.post(query, params).then(res => {
this.vnApp.showSuccess(this.$t('Data saved!'));
if (res.data)
module.starred = true;
else
module.starred = false;
this.vnApp.showSuccess(this.$t('Data saved!'));
this.countModules();
});
}

View File

@ -46,16 +46,30 @@ describe('Salix Component vnHome', () => {
describe('toggleStarredModule()', () => {
it(`should set the received module as starred if it wasn't starred`, () => {
const expectedResponse = [];
const expectedResponse = [{id: 1, moduleFk: 'Clients', workerFk: 9}];
const event = new Event('target');
controller._modules = [{module: 'client', name: 'Clients'}];
$httpBackend.whenRoute('GET', 'starredModules/getStarredModules').respond(expectedResponse);
$httpBackend.expectGET('starredModules/getStarredModules').respond(expectedResponse);
controller.getStarredModules();
$httpBackend.expectPOST('starredModules/toggleStarredModule').respond(expectedResponse);
controller.toggleStarredModule(controller._modules[0], event);
$httpBackend.flush();
expect(controller._modules.length).toEqual(1);
expect(controller._modules[0].starred).toBeUndefined();
expect(controller._modules[0].starred).toBe(true);
});
it(`should set the received module as regular if it was starred`, () => {
const event = new Event('target');
controller._modules = [{module: 'client', name: 'Clients', starred: true}];
$httpBackend.whenRoute('GET', 'starredModules/getStarredModules').respond([]);
$httpBackend.expectPOST('starredModules/toggleStarredModule').respond(undefined);
controller.toggleStarredModule(controller._modules[0], event);
$httpBackend.flush();
expect(controller._modules.length).toEqual(1);
expect(controller._modules[0].starred).toBe(false);
});
});
});