Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport master] Fix child notification #9236

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading