semantics and tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-06-02 10:31:53 +02:00
parent df4ebbd775
commit 3b7455ab24
3 changed files with 35 additions and 5 deletions

View File

@ -20,7 +20,7 @@
<vn-icon
vn-tooltip="Move left"
class="small-icon"
ng-click="$ctrl.moveModule(mod, $event, 'increase')"
ng-click="$ctrl.moveModule(mod, $event, 'left')"
icon="arrow_left">
</vn-icon>
<vn-icon
@ -32,7 +32,7 @@
<vn-icon
vn-tooltip="Move right"
class="small-icon"
ng-click="$ctrl.moveModule(mod, $event, 'decrease')"
ng-click="$ctrl.moveModule(mod, $event, 'right')"
icon="arrow_right">
</vn-icon>
</span>

View File

@ -77,12 +77,12 @@ export default class Controller extends Component {
return this.$sce.trustAsHtml(getName(mod));
}
moveModule(module, event, action) {
moveModule(module, event, direction) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
const params = {moduleName: module.name, action: action};
const params = {moduleName: module.name, direction: direction};
const query = `starredModules/setPosition`;
this.$http.post(query, params).then(res => {
if (res.data) {

View File

@ -59,7 +59,7 @@ describe('Salix Component vnHome', () => {
expect(controller._modules[0].starred).toBe(true);
});
it(`should set the received module as regular if it was starred`, () => {
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}];
@ -72,4 +72,34 @@ describe('Salix Component vnHome', () => {
expect(controller._modules[0].starred).toBe(false);
});
});
describe('moveModule()', () => {
it('should perform a query to setPosition and the apply the position to the moved and pushed modules', () => {
const starredModules = [
{id: 1, moduleFk: 'Clients', workerFk: 9},
{id: 2, moduleFk: 'Orders', workerFk: 9}
];
const movedModules = {
movingModule: {position: 2, moduleFk: 'Clients'},
pushedModule: {position: 1, moduleFk: 'Orders'}
};
const event = new Event('target');
controller._modules = [
{module: 'client', name: 'Clients', position: 1},
{module: 'orders', name: 'Orders', position: 2}
];
$httpBackend.whenRoute('GET', 'starredModules/getStarredModules').respond(starredModules);
$httpBackend.expectPOST('starredModules/setPosition').respond(movedModules);
expect(controller._modules[0].position).toEqual(1);
expect(controller._modules[1].position).toEqual(2);
controller.moveModule(controller._modules[0], event, 'right');
$httpBackend.flush();
expect(controller._modules[0].position).toEqual(2);
expect(controller._modules[1].position).toEqual(1);
});
});
});