layerUtil.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { WfsLayerConf } from '../../src/types';
  20. import {
  21. createLayer,
  22. createWfsLayer,
  23. createWmsLayer,
  24. createXyzLayer,
  25. } from '../../src/util/layerUtil';
  26. describe('layerUtil', () => {
  27. describe('createWmsLayer', () => {
  28. it('exists', () => {
  29. // function is trivial
  30. expect(createWmsLayer).toBeDefined();
  31. });
  32. });
  33. describe('createWfsLayer', () => {
  34. it('properly applies style', async () => {
  35. const colorToExpect = '#123456';
  36. const wfsLayerConf: WfsLayerConf = {
  37. title: 'osm:osm-fuel',
  38. url: 'https://ows-demo.terrestris.de/geoserver/osm/wfs',
  39. type: 'WFS',
  40. version: '2.0.2',
  41. typeName: 'osm:osm-fuel',
  42. style: {
  43. name: 'Default Style',
  44. rules: [
  45. {
  46. name: 'Default Rule',
  47. symbolizers: [
  48. {
  49. kind: 'Line',
  50. color: '#000000',
  51. width: 2,
  52. },
  53. {
  54. kind: 'Mark',
  55. wellKnownName: 'circle',
  56. color: colorToExpect,
  57. },
  58. {
  59. kind: 'Fill',
  60. color: '#000000',
  61. },
  62. ],
  63. },
  64. ],
  65. },
  66. };
  67. const wfsLayer = await createWfsLayer(wfsLayerConf);
  68. const style = wfsLayer!.getStyle();
  69. // @ts-ignore
  70. expect(style!.length).toEqual(3);
  71. // @ts-ignore upgrade `ol` package for better type of StyleLike type.
  72. const colorAtLayer = style![1].getImage().getFill().getColor();
  73. expect(colorToExpect).toEqual(colorAtLayer);
  74. });
  75. });
  76. describe('createXyzLayer', () => {
  77. it('exists', () => {
  78. // function is trivial
  79. expect(createXyzLayer).toBeDefined();
  80. });
  81. });
  82. describe('createLayer', () => {
  83. it('exists', () => {
  84. expect(createLayer).toBeDefined();
  85. });
  86. });
  87. });