Skip to content

Commit f7a280e

Browse files
committed
No need to have methods like ElementService.rotateElement when they belong to the class ElementService. Instead ElementService.rotate could be enough.
1 parent b569457 commit f7a280e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/application/ElementService.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ElementService {
2222
* @param {string} id - The unique identifier of the element to delete.
2323
* @returns {Element[]} The updated list of elements.
2424
*/
25-
static deleteElement(elements, id) {
25+
static delete(elements, id) {
2626
return elements.filter(element => element.id !== id);
2727
}
2828

@@ -32,7 +32,7 @@ export class ElementService {
3232
* @param {Element} element - The element to move.
3333
* @param {Position} newReferencePosition - The new position for the reference terminal.
3434
*/
35-
static moveElement(element, newReferencePosition) {
35+
static move(element, newReferencePosition) {
3636
const refTerminal = element.terminals[0]; // Reference terminal
3737
const deltaX = newReferencePosition.x - refTerminal.x;
3838
const deltaY = newReferencePosition.y - refTerminal.y;
@@ -48,7 +48,7 @@ export class ElementService {
4848
* @param {Element} element - The element to rotate.
4949
* @param {number} newOrientation - The new orientation (0, 90, 180, or 270 degrees).
5050
*/
51-
static rotateElement(element, newOrientation) {
51+
static rotate(element, newOrientation) {
5252
if (![0, 90, 180, 270].includes(newOrientation)) {
5353
throw new Error("Orientation must be one of 0, 90, 180, or 270 degrees.");
5454
}

tests/domain/ElementService.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Element Service Tests', () => {
3333
const element = new MockElement('E3', terminals, null, properties);
3434

3535
let elements = [element];
36-
elements = ElementService.deleteElement(elements, 'E3');
36+
elements = ElementService.delete(elements, 'E3');
3737

3838
expect(elements).to.be.an('array').that.is.empty;
3939
});
@@ -44,7 +44,7 @@ describe('Element Service Tests', () => {
4444
const element = new MockElement('E4', terminals, null, properties);
4545

4646
let elements = [element];
47-
elements = ElementService.deleteElement(elements, 'NonExistentID');
47+
elements = ElementService.delete(elements, 'NonExistentID');
4848

4949
expect(elements).to.have.lengthOf(1);
5050
expect(elements[0].id).to.equal('E4');
@@ -56,7 +56,7 @@ describe('Element Service Tests', () => {
5656
const terminals = [new Position(10, 20), new Position(30, 40)];
5757
const element = new MockElement('E5', terminals, null, new Properties());
5858

59-
ElementService.moveElement(element, new Position(20, 30));
59+
ElementService.move(element, new Position(20, 30));
6060

6161
expect(element.terminals).to.deep.equal([
6262
new Position(20, 30),
@@ -68,7 +68,7 @@ describe('Element Service Tests', () => {
6868
const terminals = [new Position(10, 20), new Position(30, 40)];
6969
const element = new MockElement('E6', terminals, null, new Properties());
7070

71-
ElementService.moveElement(element, new Position(10, 20));
71+
ElementService.move(element, new Position(10, 20));
7272

7373
expect(element.terminals).to.deep.equal(terminals);
7474
});
@@ -79,7 +79,7 @@ describe('Element Service Tests', () => {
7979
const terminals = [new Position(10, 10), new Position(20, 10)];
8080
const element = new MockElement('E7', terminals, null, new Properties());
8181

82-
ElementService.rotateElement(element, 90);
82+
ElementService.rotate(element, 90);
8383

8484
expect(element.terminals).to.deep.equal([
8585
new Position(10, 10), // Reference terminal remains unchanged
@@ -91,7 +91,7 @@ describe('Element Service Tests', () => {
9191
const terminals = [new Position(10, 10), new Position(20, 10)];
9292
const element = new MockElement('E8', terminals, null, new Properties());
9393

94-
ElementService.rotateElement(element, 180);
94+
ElementService.rotate(element, 180);
9595

9696
expect(element.terminals).to.deep.equal([
9797
new Position(10, 10), // Reference terminal remains unchanged
@@ -103,7 +103,7 @@ describe('Element Service Tests', () => {
103103
const terminals = [new Position(10, 10), new Position(20, 10)];
104104
const element = new MockElement('E9', terminals, null, new Properties());
105105

106-
expect(() => ElementService.rotateElement(element, 45)).to.throw(
106+
expect(() => ElementService.rotate(element, 45)).to.throw(
107107
"Orientation must be one of 0, 90, 180, or 270 degrees."
108108
);
109109
});

0 commit comments

Comments
 (0)