Skip to content

Commit

Permalink
fix sonar issues (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
eballo authored Jun 21, 2024
1 parent 4c3bdcf commit c514e53
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 134 deletions.
3 changes: 1 addition & 2 deletions src/app/catalunya-map-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

const MAP_CONFIG = {

url_json : process.env.SERVER_HOST,
url_json: process.env.SERVER_HOST,

responsive: true, // enable/disable responsive functionality
useText: true, // enable/disable list text comarques
Expand Down
2 changes: 1 addition & 1 deletion src/app/catalunya-map-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $(document).ready(function () {
$("#map").fadeIn(1000);
$("#legend").fadeIn(1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("Error - url: " + url);
}
});
Expand Down
63 changes: 36 additions & 27 deletions src/app/catalunya-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import {stringToBoolean} from "./catalunya-map-config";

;


class CatMap {

Expand Down Expand Up @@ -226,38 +226,47 @@ class CatMap {
if (this.debug) {
console.log('onClick enabled');
}
if (this.config.newWindow) {
if (this.debug) {
console.log('newWindow enabled');
}
window.open(comarcaLink);
} else {
if (this.debug) {
console.log('newWindow disabled');
}
window.location = comarcaLink;
}
this.on_click_enabled(comarcaLink);
} else {
if (this.debug) {
console.log('onClick disabled');
}
if (this.config.button) {
if (this.debug) {
console.log('Button functionality enabled');
}
$('#veure-contingut').show().click(function () {
$(this).toggleClass("veure-clic");
window.location = comarcaLink;
return false;
});
this.on_click_disabled(comarcaLink, comarcaName, capitalComarca, contentText);
}
}

} else {
if (this.debug) {
console.log('Button functionality disabled');
}
on_click_disabled(comarcaLink, comarcaName, capitalComarca, contentText) {

if (this.config.button) {
if (this.debug) {
console.log('Button functionality enabled');
}
$('#veure-contingut').show().click(function () {
$(this).toggleClass("veure-clic");
window.location = comarcaLink;
return false;
});

} else {
if (this.debug) {
console.log('Button functionality disabled');
}
}
$('#comarcaName').html('<h1>' + comarcaName + '</h1><h2>' + capitalComarca + '</h2>');
$('#contentText').html(contentText);
}

on_click_enabled(comarcaLink) {
if (this.config.newWindow) {
if (this.debug) {
console.log('newWindow enabled');
}
window.open(comarcaLink);
} else {
if (this.debug) {
console.log('newWindow disabled');
}
$('#comarcaName').html('<h1>' + comarcaName + '</h1><h2>' + capitalComarca + '</h2>');
$('#contentText').html(contentText);
window.location = comarcaLink;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/catalunya-map-main.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/tests/catalunya-map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('CatMap', () => {
consoleLogMock.mockRestore();
});

describe("CreateArrayComarcas", ()=>{
describe("CreateArrayComarcas", () => {
test('createArrayComarcas - debug enabled', () => {
mapInstance.createArrayComarcas()
expect(Object.keys(mapInstance.mcat).length).toBe(2)
Expand All @@ -84,7 +84,7 @@ describe('CatMap', () => {
});
})

describe('showValues',()=>{
describe('showValues', () => {
test('showValues - debug enabled', () => {
mapInstance.showValues();

Expand Down Expand Up @@ -170,7 +170,7 @@ describe('CatMap', () => {
touchstart: jest.fn(),
};

for (let i=0; i<3; ++i) {
for (let i = 0; i < 3; ++i) {
mockObject[i] = {
hover: jest.fn(),
click: jest.fn(),
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('CatMap', () => {
touchstart: jest.fn(),
};

for (let i=0; i<3; ++i) {
for (let i = 0; i < 3; ++i) {
mockObject[i] = {
hover: jest.fn(),
click: jest.fn(),
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('CatMap', () => {
touchstart: jest.fn(),
};

for (let i=0; i<3; ++i) {
for (let i = 0; i < 3; ++i) {
mockObject[i] = {
hover: jest.fn(),
click: jest.fn(),
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('CatMap', () => {
touchstart: jest.fn(),
};

for (let i=0; i<3; ++i) {
for (let i = 0; i < 3; ++i) {
mockObject[i] = {
hover: jest.fn(),
click: jest.fn(),
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('CatMap', () => {
test('should return correct positions for comarca and capital labels', () => {
// Mocking necessary parameters for testing
const comarca = 'comarca1';
const bbox = { x: 100, y: 200, width: 50, height: 30 };
const bbox = {x: 100, y: 200, width: 50, height: 30};

// Executing the method to be tested
const result = mapInstance.get_comarca_and_capital_positions_label(comarca, bbox);
Expand All @@ -322,7 +322,7 @@ describe('CatMap', () => {
test('should return correct positions for comarca and capital labels when extra_x and extra_y are not provided', () => {
// Mocking necessary parameters for testing
const comarca = 'comarca2';
const bbox = { x: 150, y: 250, width: 40, height: 25 };
const bbox = {x: 150, y: 250, width: 40, height: 25};

// Executing the method to be tested
const result = mapInstance.get_comarca_and_capital_positions_label(comarca, bbox);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mocks/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const $ = jest.fn().mockImplementation(selector => {
data: jest.fn(),
val: jest.fn(),
hide: jest.fn(),
show: jest.fn().mockImplementation(()=>{
show: jest.fn().mockImplementation(() => {
return {
click: jest.fn()
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mocks/scale-raphael.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mockSvgElement = () => ({
show: jest.fn(),
toFront: jest.fn(),
toBack: jest.fn(),
node: { id: '' }
node: {id: ''}
});

const ScaleRaphael = jest.fn().mockImplementation((containerId, width, height) => {
Expand Down
19 changes: 14 additions & 5 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">

<head>
<title>Interactive Map of Catalunya SVG/VML and RaphaëlJs - Demo V11.0</title>
Expand Down Expand Up @@ -69,6 +69,7 @@ <h1>Mapa Interactiu de Catalunya</h1>
</div>
<div id="debugInfo"></div>
<h4 class="page-header"> :: Catalunya Medieval Project - <a href="http://www.catalunyamedieval.es/" target="_blank"
rel="noopener noreferrer"
title="Catalunya Medieval">www.catalunyamedieval.es</a> ::
</h4>
<div class="row">
Expand All @@ -77,7 +78,9 @@ <h4 class="page-header"> :: Catalunya Medieval Project - <a href="http://www.cat
<div class="caption">
<h3>CAT</h3>
<p>Mapa interactiu de Catalunya creat a partir d'un SVG/VML i fent ús de la llibreria <a
href="http://raphaeljs.com" target="_blank">RaphaëlJs</a>.</p>
href="http://raphaeljs.com"
rel="noopener noreferrer"
target="_blank">RaphaëlJs</a>.</p>
</div>
</div>
</div>
Expand All @@ -86,7 +89,9 @@ <h3>CAT</h3>
<div class="caption">
<h3>EN</h3>
<p>Interactive vectorial map of Catalonia based on a SVG/VML and the library <a
href="http://raphaeljs.com" target="_blank">RaphaëlJs</a>.</p>
href="http://raphaeljs.com"
rel="noopener noreferrer"
target="_blank">RaphaëlJs</a>.</p>
</div>
</div>
</div>
Expand All @@ -95,7 +100,9 @@ <h3>EN</h3>
<div class="caption">
<h3>ES</h3>
<p>Mapa interactivo de Cataluña creado a partir de un SVG/VML y usando la libreria <a
href="http://raphaeljs.com" target="_blank">RaphaëlJs</a>.</p>
href="http://raphaeljs.com"
rel="noopener noreferrer"
target="_blank">RaphaëlJs</a>.</p>
</div>
</div>
</div>
Expand All @@ -104,7 +111,9 @@ <h3>ES</h3>
<div class="caption">
<h3>NL</h3>
<p>Interactieve vectoriële kaart van Catalonië op basis van een SVG/VML en de bibliotheek <a
href="http://raphaeljs.com" target="_blank">RaphaëlJs</a>.</p>
href="http://raphaeljs.com"
rel="noopener noreferrer"
target="_blank">RaphaëlJs</a>.</p>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit c514e53

Please sign in to comment.