Browse Source

Merge pull request #2879 from mcottret/fix/fix-layer-is-visible

Fix retrieval of layers' visibility always returning `true`. Fixes #2863
pull/2881/head
Artur Arseniev 6 years ago
committed by GitHub
parent
commit
a87ed73418
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/dom_components/view/ComponentView.js
  2. 11
      src/navigator/view/ItemView.js
  3. 36
      test/specs/navigator/view/ItemView.js

2
src/dom_components/view/ComponentView.js

@ -4,7 +4,7 @@ import Components from '../model/Components';
import ComponentsView from './ComponentsView';
import Selectors from 'selector_manager/model/Selectors';
import { replaceWith } from 'utils/dom';
import { setViewEl, getElRect } from 'utils/mixins';
import { setViewEl } from 'utils/mixins';
export default Backbone.View.extend({
className() {

11
src/navigator/view/ItemView.js

@ -108,7 +108,7 @@ export default Backbone.View.extend({
const model = this.model;
const hClass = `${pfx}layer-hidden`;
const hideIcon = 'fa-eye-slash';
const hidden = model.getStyle().display == 'none';
const hidden = model.getStyle().display === 'none';
const method = hidden ? 'addClass' : 'removeClass';
this.$el[method](hClass);
this.getVisibilityEl()[method](hideIcon);
@ -297,13 +297,12 @@ export default Backbone.View.extend({
/**
* Check if component is visible
*
* @return bool
* @return boolean
* */
isVisible() {
var css = this.model.get('style'),
pr = css.display;
if (pr && pr == 'none') return;
return 1;
const { display } = this.model.getStyle();
return !(display && display === 'none');
},
/**

36
test/specs/navigator/view/ItemView.js

@ -0,0 +1,36 @@
import ItemView from '../../../../src/navigator/view/ItemView';
describe('ItemView', () => {
let itemView, fakeModel, fakeModelStyle;
beforeEach(() => {
fakeModelStyle = {};
fakeModel = {
get: jest.fn(),
set: jest.fn(),
getStyle: jest.fn(() => fakeModelStyle)
};
itemView = new ItemView({
model: fakeModel,
config: {
em: {
get: jest.fn(() => ({ stylePrefix: '' }))
}
}
});
});
describe('.isVisible', () => {
it("should return `false` if the model's `style` object has a `display` property set to `none`, `true` otherwise", () => {
expect(itemView.isVisible()).toEqual(true);
fakeModelStyle.display = '';
expect(itemView.isVisible()).toEqual(true);
fakeModelStyle.display = 'none';
expect(itemView.isVisible()).toEqual(false);
fakeModelStyle.display = 'block';
expect(itemView.isVisible()).toEqual(true);
});
});
});
Loading…
Cancel
Save