Skip to content

Commit

Permalink
Fix ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PacMM79 committed Nov 18, 2024
1 parent 1bb190e commit 9da5da7
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 153 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DesktopNavComponent } from './desktop-nav.component';
import { NavService } from 'src/app/services/nav.service';
import { TranslateModule } from '@ngx-translate/core';
import { RouterModule, ActivatedRoute } from '@angular/router';
import { type ComponentFixture, TestBed } from '@angular/core/testing'
import { DesktopNavComponent } from './desktop-nav.component'
import { NavService } from 'src/app/services/nav.service'
import { TranslateModule } from '@ngx-translate/core'
import { RouterModule, ActivatedRoute } from '@angular/router'

// Mock de NavService
class MockNavService {
public selectWidth = '69px';
public selectWidth = '69px'

openLoginModal = jest.fn(); // Simula la función openLoginModal
openLoginModal = jest.fn() // Simula la función openLoginModal
changeLanguage = jest.fn((language: string) => {
this.selectWidth = language === 'ca' ? '69px' : '57px';
});
this.selectWidth = language === 'ca' ? '69px' : '57px'
})
}

// Mock de ActivatedRoute para pruebas
Expand All @@ -21,12 +21,12 @@ const mockActivatedRoute = {
get: jest.fn().mockReturnValue(null)
}
}
};
}

describe('DesktopNavComponent', () => {
let component: DesktopNavComponent;
let fixture: ComponentFixture<DesktopNavComponent>;
let navService: MockNavService;
let component: DesktopNavComponent
let fixture: ComponentFixture<DesktopNavComponent>
let navService: MockNavService

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -36,40 +36,40 @@ describe('DesktopNavComponent', () => {
{ provide: NavService, useClass: MockNavService },
{ provide: ActivatedRoute, useValue: mockActivatedRoute }
]
});
})

fixture = TestBed.createComponent(DesktopNavComponent);
component = fixture.componentInstance;
navService = TestBed.inject(NavService) as unknown as MockNavService;
fixture.detectChanges();
});
fixture = TestBed.createComponent(DesktopNavComponent)
component = fixture.componentInstance
navService = TestBed.inject(NavService) as unknown as MockNavService
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy();
});
expect(component).toBeTruthy()
})

it('should call openLoginModal when openLoginModal is invoked', () => {
component.openLoginModal();
expect(navService.openLoginModal).toHaveBeenCalled();
});
component.openLoginModal()
expect(navService.openLoginModal).toHaveBeenCalled()
})

it('should change language and update selectWidth', () => {
const event = new Event('change');
Object.defineProperty(event, 'target', { value: { value: 'es' }, enumerable: true });
const event = new Event('change')
Object.defineProperty(event, 'target', { value: { value: 'es' }, enumerable: true })

component.changeLanguage(event);
component.changeLanguage(event)

expect(navService.changeLanguage).toHaveBeenCalledWith('es');
expect(navService.selectWidth).toBe('57px'); // Verifica que el selectWidth se actualiza correctamente
});
expect(navService.changeLanguage).toHaveBeenCalledWith('es')
expect(navService.selectWidth).toBe('57px') // Verifica que el selectWidth se actualiza correctamente
})

it('should change language to "ca" and update selectWidth accordingly', () => {
const event = new Event('change');
Object.defineProperty(event, 'target', { value: { value: 'ca' }, enumerable: true });
const event = new Event('change')
Object.defineProperty(event, 'target', { value: { value: 'ca' }, enumerable: true })

component.changeLanguage(event);
component.changeLanguage(event)

expect(navService.changeLanguage).toHaveBeenCalledWith('ca');
expect(navService.selectWidth).toBe('69px'); // Verifica que el selectWidth se actualiza correctamente
});
});
expect(navService.changeLanguage).toHaveBeenCalledWith('ca')
expect(navService.selectWidth).toBe('69px') // Verifica que el selectWidth se actualiza correctamente
})
})
20 changes: 10 additions & 10 deletions src/app/core/layout/header/desktop-nav/desktop-nav.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Component } from '@angular/core';
import { NavService } from 'src/app/services/nav.service';
import { Component, Inject } from '@angular/core'
import { NavService } from 'src/app/services/nav.service'

@Component({
selector: 'app-desktop-nav',
templateUrl: './desktop-nav.component.html',
styleUrl: './desktop-nav.component.scss'
})
export class DesktopNavComponent {
constructor(public navService: NavService) {}
constructor (@Inject(NavService) public navService: NavService) {}

openLoginModal(): void {
this.navService.openLoginModal();
openLoginModal (): void {
this.navService.openLoginModal()
}

changeLanguage(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const language = selectElement.value;
this.navService.changeLanguage(language);
changeLanguage (event: Event): void {
const selectElement = event.target as HTMLSelectElement
const language = selectElement.value
this.navService.changeLanguage(language)
}
}
}
74 changes: 37 additions & 37 deletions src/app/core/layout/header/mobile-nav/mobile-nav.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MobileNavComponent } from './mobile-nav.component';
import { NavService } from 'src/app/services/nav.service';
import { TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { type ComponentFixture, TestBed } from '@angular/core/testing'
import { MobileNavComponent } from './mobile-nav.component'
import { NavService } from 'src/app/services/nav.service'
import { TranslateModule } from '@ngx-translate/core'
import { ActivatedRoute, RouterModule } from '@angular/router'

// Mock de NavService
class MockNavService {
public selectWidth = '69px';
public selectWidth = '69px'

openLoginModal = jest.fn(); // Simula la función openLoginModal
openLoginModal = jest.fn() // Simula la función openLoginModal
changeLanguage = jest.fn((language: string) => {
this.selectWidth = language === 'ca' ? '69px' : '57px';
});
this.selectWidth = language === 'ca' ? '69px' : '57px'
})
}

// Mock de ActivatedRoute para pruebas
Expand All @@ -21,12 +21,12 @@ const mockActivatedRoute = {
get: jest.fn().mockReturnValue(null)
}
}
};
}

describe('MobileNavComponent', () => {
let component: MobileNavComponent;
let fixture: ComponentFixture<MobileNavComponent>;
let navService: MockNavService;
let component: MobileNavComponent
let fixture: ComponentFixture<MobileNavComponent>
let navService: MockNavService

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -36,40 +36,40 @@ describe('MobileNavComponent', () => {
{ provide: NavService, useClass: MockNavService },
{ provide: ActivatedRoute, useValue: mockActivatedRoute }
]
});
})

fixture = TestBed.createComponent(MobileNavComponent);
component = fixture.componentInstance;
navService = TestBed.inject(NavService) as unknown as MockNavService;
fixture.detectChanges();
});
fixture = TestBed.createComponent(MobileNavComponent)
component = fixture.componentInstance
navService = TestBed.inject(NavService) as unknown as MockNavService
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy();
});
expect(component).toBeTruthy()
})

it('should call openLoginModal when openLoginModal is invoked', () => {
component.openLoginModal();
expect(navService.openLoginModal).toHaveBeenCalled();
});
component.openLoginModal()
expect(navService.openLoginModal).toHaveBeenCalled()
})

it('should change language and update selectWidth', () => {
const event = new Event('change');
Object.defineProperty(event, 'target', { value: { value: 'es' }, enumerable: true });
const event = new Event('change')
Object.defineProperty(event, 'target', { value: { value: 'es' }, enumerable: true })

component.changeLanguage(event);
component.changeLanguage(event)

expect(navService.changeLanguage).toHaveBeenCalledWith('es');
expect(navService.selectWidth).toBe('57px'); // Verifica que el selectWidth se actualiza correctamente
});
expect(navService.changeLanguage).toHaveBeenCalledWith('es')
expect(navService.selectWidth).toBe('57px') // Verifica que el selectWidth se actualiza correctamente
})

it('should change language to "ca" and update selectWidth accordingly', () => {
const event = new Event('change');
Object.defineProperty(event, 'target', { value: { value: 'ca' }, enumerable: true });
const event = new Event('change')
Object.defineProperty(event, 'target', { value: { value: 'ca' }, enumerable: true })

component.changeLanguage(event);
component.changeLanguage(event)

expect(navService.changeLanguage).toHaveBeenCalledWith('ca');
expect(navService.selectWidth).toBe('69px'); // Verifica que el selectWidth se actualiza correctamente
});
});
expect(navService.changeLanguage).toHaveBeenCalledWith('ca')
expect(navService.selectWidth).toBe('69px') // Verifica que el selectWidth se actualiza correctamente
})
})
20 changes: 10 additions & 10 deletions src/app/core/layout/header/mobile-nav/mobile-nav.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Component } from '@angular/core';
import { NavService } from 'src/app/services/nav.service';
import { Component, Inject } from '@angular/core'
import { NavService } from 'src/app/services/nav.service'

@Component({
selector: 'app-mobile-nav',
templateUrl: './mobile-nav.component.html',
styleUrl: './mobile-nav.component.scss'
})
export class MobileNavComponent {
constructor(public navService: NavService) {}
constructor (@Inject(NavService) public navService: NavService) {}

openLoginModal(): void {
this.navService.openLoginModal();
openLoginModal (): void {
this.navService.openLoginModal()
}

changeLanguage(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const language = selectElement.value;
this.navService.changeLanguage(language);
changeLanguage (event: Event): void {
const selectElement = event.target as HTMLSelectElement
const language = selectElement.value
this.navService.changeLanguage(language)
}
}
}
Loading

0 comments on commit 9da5da7

Please sign in to comment.