goog.require('ngeo.BackgroundLayerMgr');

describe('ngeo.BackgroundLayerMgr', () => {
  let ngeoBackgroundLayerMgr;
  let map;

  beforeEach(() => {
    inject(($injector) => {
      ngeoBackgroundLayerMgr = $injector.get('ngeoBackgroundLayerMgr');
    });

    map = new ol.Map({});
  });

  describe('#set', () => {

    it('sets the background layer #1', () => {
      const layer = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, layer);
      expect(map.getLayers().item(0)).toBe(layer);
    });

    it('sets the background layer #2', () => {
      map.addLayer(new ol.layer.Tile());
      const layer = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, layer);
      expect(map.getLayers().getLength()).toBe(2);
      expect(map.getLayers().item(0)).toBe(layer);
    });

    it('sets the background layer #3', () => {
      const layer1 = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, layer1);
      const layer2 = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, layer2);
      expect(map.getLayers().getLength()).toBe(1);
      expect(map.getLayers().item(0)).toBe(layer2);
    });

    it('unsets the background layer', () => {
      const layer = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, layer);
      ngeoBackgroundLayerMgr.set(map, null);
      expect(map.getLayers().getLength()).toBe(0);
    });

  });

  describe('#get', () => {

    it('returns `null` if no background layer', () => {
      const layer = ngeoBackgroundLayerMgr.get(map);
      expect(layer).toBe(null);
    });

    it('returns the current background layer', () => {
      const expectedLayer = new ol.layer.Tile();
      ngeoBackgroundLayerMgr.set(map, expectedLayer);
      const layer = ngeoBackgroundLayerMgr.get(map);
      expect(layer).toBe(expectedLayer);
    });
  });

});

@@ -33,16 +33,50 @@
 erMgr');
+%0Agoog.require('ngeo.LayerHelper');
 %0A%0Adescri
@@ -149,19 +149,92 @@
 ;%0A  let 
-map
+ngeoLayerHelper;%0A  let map;%0A  const BACKGROUNDLAYERGROUP_NAME = 'background'
 ;%0A%0A  bef
@@ -349,16 +349,74 @@
 rMgr');%0A
+      ngeoLayerHelper = $injector.get('ngeoLayerHelper');%0A
     %7D);%0A
@@ -603,32 +603,119 @@
 et(map, layer);%0A
+      const bgGroup = ngeoLayerHelper.getGroupFromMap(map, BACKGROUNDLAYERGROUP_NAME);%0A
       expect(map
@@ -703,34 +703,38 @@
 );%0A      expect(
-ma
+bgGrou
 p.getLayers().it
@@ -813,49 +813,8 @@
 %3E %7B%0A
-      map.addLayer(new ol.layer.Tile());%0A
     
@@ -898,33 +898,181 @@
 yer);%0A      
-expect(ma
+const bgGroup = ngeoLayerHelper.getGroupFromMap(map, BACKGROUNDLAYERGROUP_NAME);%0A      bgGroup.getLayers().setAt(1, new ol.layer.Tile());%0A      expect(bgGrou
 p.getLayers(
@@ -1100,34 +1100,38 @@
 );%0A      expect(
-ma
+bgGrou
 p.getLayers().it
@@ -1380,24 +1380,111 @@
 p, layer2);%0A
+      const bgGroup = ngeoLayerHelper.getGroupFromMap(map, BACKGROUNDLAYERGROUP_NAME);%0A
       expect
@@ -1476,34 +1476,38 @@
 );%0A      expect(
-ma
+bgGrou
 p.getLayers().ge
@@ -1543,30 +1543,541 @@
 ect(
-map.getLayers().item(0
+bgGroup.getLayers().item(0)).toBe(layer2);%0A    %7D);%0A%0A    it('sets the opacity background layer', () =%3E %7B%0A      const layer1 = new ol.layer.Tile();%0A      ngeoBackgroundLayerMgr.set(map, layer1);%0A      const layer2 = new ol.layer.Tile();%0A      ngeoBackgroundLayerMgr.setOpacityBgLayer(map, layer2);%0A      const bgGroup = ngeoLayerHelper.getGroupFromMap(map, BACKGROUNDLAYERGROUP_NAME);%0A      expect(bgGroup.getLayers().getLength()).toBe(2);%0A      expect(bgGroup.getLayers().item(0)).toBe(layer1);%0A      expect(bgGroup.getLayers().item(1
 )).t
@@ -2272,24 +2272,111 @@
 map, null);%0A
+      const bgGroup = ngeoLayerHelper.getGroupFromMap(map, BACKGROUNDLAYERGROUP_NAME);%0A
       expect
@@ -2376,18 +2376,22 @@
  expect(
-ma
+bgGrou
 p.getLay

Update tests