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) { module.exports = function(Self) {
Self.remoteMethodCtx('getStarredModules', { Self.remoteMethodCtx('getStarredModules', {
description: 'returns the receved modules adding the starred property.', description: 'returns the starred modules for the current user',
returns: { returns: {
type: 'object', type: 'object',
root: true root: true

View File

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

View File

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

View File

@ -46,16 +46,30 @@ describe('Salix Component vnHome', () => {
describe('toggleStarredModule()', () => { describe('toggleStarredModule()', () => {
it(`should set the received module as starred if it wasn't starred`, () => { 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'}]; controller._modules = [{module: 'client', name: 'Clients'}];
$httpBackend.whenRoute('GET', 'starredModules/getStarredModules').respond(expectedResponse); $httpBackend.whenRoute('GET', 'starredModules/getStarredModules').respond(expectedResponse);
$httpBackend.expectGET('starredModules/getStarredModules').respond(expectedResponse); $httpBackend.expectPOST('starredModules/toggleStarredModule').respond(expectedResponse);
controller.getStarredModules(); controller.toggleStarredModule(controller._modules[0], event);
$httpBackend.flush(); $httpBackend.flush();
expect(controller._modules.length).toEqual(1); 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);
}); });
}); });
}); });