Skip to content

Commit

Permalink
Merge pull request #9235 from camptocamp/fix-child-notification
Browse files Browse the repository at this point in the history
Fix child notification
  • Loading branch information
sbrunner authored Oct 10, 2023
2 parents 6d55e5c + e265d02 commit 6ea4650
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/layertree/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function LayertreeController($scope, $rootScope, $attrs) {
/**
* Return the current state.
*
* @returns {string} 'on', 'off', 'indeterminate'.
* @returns {string} 'on', 'off', 'indeterminate', or '' if the children are not initialized.
*/
LayertreeController.prototype.getState = function () {
return this.state_;
Expand Down Expand Up @@ -302,7 +302,7 @@ LayertreeController.prototype.refreshState = function (opt_onChild, opt_broadcas
/**
* Return the current state, calculate on all its children recursively.
*
* @returns {string} 'on', 'off' or 'indeterminate'.
* @returns {string} 'on', 'off', 'indeterminate', or '' if the children are not initialized.
*/
LayertreeController.prototype.getCalculateState = function () {
const group = /** @type {import('gmf/themes').GmfGroup} */ (this.node);
Expand All @@ -314,7 +314,7 @@ LayertreeController.prototype.getCalculateState = function () {
/** @type {string} */
let previousChildState;
this.children.some((child) => {
childState = child.getCalculateState();
childState = child.getState();
if (previousChildState) {
if (previousChildState !== childState) {
childState = 'indeterminate';
Expand Down
20 changes: 15 additions & 5 deletions test/spec/directives/layertree.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2016-2022 Camptocamp SA
// Copyright (c) 2016-2023 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -149,11 +149,21 @@ describe('ngeo.layertree.component', () => {

it('Get calculate state', () => {
const treeNode0 = roottreeCtrl.children[0];
const treeLeaf01 = treeNode0.children[1];
treeLeaf01.state_ = 'on';
expect(roottreeCtrl.getCalculateState()).toBe('indeterminate');
const treeLeaf01 = treeNode0.children[0];
const treeLeaf02 = treeNode0.children[1];
expect(treeNode0.getState()).toBe('off');
expect(treeLeaf01.getState()).toBe('off');
expect(treeLeaf02.getState()).toBe('off');
expect(roottreeCtrl.getState()).toBe('off');
treeLeaf02.state_ = 'on';
expect(treeNode0.getCalculateState()).toBe('indeterminate');
expect(treeLeaf01.getCalculateState()).toBe('on');
expect(roottreeCtrl.getCalculateState()).toBe('off');
treeNode0.refreshState();
expect(treeNode0.getState()).toBe('indeterminate');
expect(treeLeaf01.getState()).toBe('off');
expect(treeLeaf02.getState()).toBe('on');
expect(roottreeCtrl.getState()).toBe('indeterminate');
expect(roottreeCtrl.getCalculateState()).toBe('indeterminate');
});

it('Get first parent tree', () => {
Expand Down

0 comments on commit 6ea4650

Please sign in to comment.