diff --git a/src/app/core/store/store.service.ts b/src/app/core/store/store.service.ts index e1fb019..f72b8c5 100644 --- a/src/app/core/store/store.service.ts +++ b/src/app/core/store/store.service.ts @@ -15,8 +15,8 @@ export class StoreService { currentPage = 1; currentColor = ''; currentType = ''; - private usernameForm = new BehaviorSubject(''); - public usernameForm$ = this.state.asObservable(); + private usernameForm = new BehaviorSubject('Freak'); + public usernameForm$ = this.usernameForm.asObservable(); private isAuthenticated = new BehaviorSubject(false); constructor(private repo: RepoService, private router: Router) { this.loadData(); @@ -56,4 +56,8 @@ export class StoreService { getIsAuthenticated(): Observable { return this.isAuthenticated.asObservable(); } + changeUsername(username: string) { + this.usernameForm.next(username); + this.isAuthenticated.next(true); + } } diff --git a/src/app/feature/error/error.component.html b/src/app/feature/error/error.component.html index 1a06ca4..fb6c2c6 100644 --- a/src/app/feature/error/error.component.html +++ b/src/app/feature/error/error.component.html @@ -5,6 +5,6 @@ Error

ERROR

-

WE CAN'T FIND YOUR MANA

+

WE CAN'T FIND YOUR MANA

diff --git a/src/app/feature/error/error.component.spec.ts b/src/app/feature/error/error.component.spec.ts index b5a1275..6970763 100644 --- a/src/app/feature/error/error.component.spec.ts +++ b/src/app/feature/error/error.component.spec.ts @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import ErrorComponent from './error.component'; import { provideRouter } from '@angular/router'; import { routes } from '../../app.routes'; +import { provideHttpClient } from '@angular/common/http'; describe('ErrorComponent', () => { let component: ErrorComponent; @@ -11,7 +12,7 @@ describe('ErrorComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ErrorComponent], - providers: [provideRouter(routes)], + providers: [provideRouter(routes), provideHttpClient()], }).compileComponents(); fixture = TestBed.createComponent(ErrorComponent); @@ -34,7 +35,7 @@ describe('ErrorComponent', () => { const img = compiled.querySelector('section > img'); expect(img.src).toContain('error-image.jpeg'); expect(compiled.querySelector('h2').textContent).toContain('ERROR'); - expect(compiled.querySelector('p').textContent).toContain( + expect(compiled.querySelector('.error').textContent).toContain( "WE CAN'T FIND YOUR MANA" ); }); diff --git a/src/app/feature/greeting/greeting.component.css b/src/app/feature/greeting/greeting.component.css new file mode 100644 index 0000000..b605ca6 --- /dev/null +++ b/src/app/feature/greeting/greeting.component.css @@ -0,0 +1,6 @@ +p { + color: white; + position: absolute; + left: 36rem; + top: 3rem; +} diff --git a/src/app/feature/greeting/greeting.component.html b/src/app/feature/greeting/greeting.component.html new file mode 100644 index 0000000..26dc9c2 --- /dev/null +++ b/src/app/feature/greeting/greeting.component.html @@ -0,0 +1 @@ +

Welcome {{ user }}

diff --git a/src/app/feature/greeting/greeting.component.spec.ts b/src/app/feature/greeting/greeting.component.spec.ts new file mode 100644 index 0000000..9438db1 --- /dev/null +++ b/src/app/feature/greeting/greeting.component.spec.ts @@ -0,0 +1,27 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GreetingComponent } from './greeting.component'; +import { provideHttpClient } from '@angular/common/http'; + +describe('GreetingComponent', () => { + let component: GreetingComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [GreetingComponent], + providers: [provideHttpClient()], + }).compileComponents(); + + fixture = TestBed.createComponent(GreetingComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + it('should set isGreeting to true on component initialization', () => { + expect(component.isGreeting).toBeTrue(); + }); +}); diff --git a/src/app/feature/greeting/greeting.component.ts b/src/app/feature/greeting/greeting.component.ts new file mode 100644 index 0000000..94923cf --- /dev/null +++ b/src/app/feature/greeting/greeting.component.ts @@ -0,0 +1,23 @@ +import { Component } from '@angular/core'; +import { StoreService } from '../../core/store/store.service'; + +@Component({ + selector: 'app-greeting', + standalone: true, + imports: [], + templateUrl: './greeting.component.html', + styleUrl: './greeting.component.css', +}) +export class GreetingComponent { + user: string = 'Freak'; + isGreeting: boolean = false; + constructor(private service: StoreService) { + this.getLoggedIn(); + } + getLoggedIn() { + this.isGreeting = true; + this.service.usernameForm$.subscribe((name) => { + this.user = name; + }); + } +} diff --git a/src/app/feature/initial-form/initial-form.component.css b/src/app/feature/initial-form/initial-form.component.css index dc57fae..24a79a6 100644 --- a/src/app/feature/initial-form/initial-form.component.css +++ b/src/app/feature/initial-form/initial-form.component.css @@ -17,15 +17,15 @@ form { flex-direction: column; gap: 0.5rem; button { - cursor: pointer; margin-inline: 3rem; background-color: white; border: none; border-radius: 1rem; padding: 0.4rem; - &:hover { + &:not(:disabled):hover { background-color: black; color: white; + cursor: pointer; } } } diff --git a/src/app/feature/initial-form/initial-form.component.html b/src/app/feature/initial-form/initial-form.component.html index 960ae20..7d18338 100644 --- a/src/app/feature/initial-form/initial-form.component.html +++ b/src/app/feature/initial-form/initial-form.component.html @@ -27,7 +27,6 @@

Sign in

- - + diff --git a/src/app/feature/initial-form/initial-form.component.spec.ts b/src/app/feature/initial-form/initial-form.component.spec.ts index 356559c..75cf6fd 100644 --- a/src/app/feature/initial-form/initial-form.component.spec.ts +++ b/src/app/feature/initial-form/initial-form.component.spec.ts @@ -40,6 +40,6 @@ describe('InitialFormComponent', () => { }); it('form invalid when empty', () => { - expect(component.form.invalid).toBeFalsy(); + expect(component.form.invalid).toBeTruthy(); }); }); diff --git a/src/app/feature/initial-form/initial-form.component.ts b/src/app/feature/initial-form/initial-form.component.ts index c24c8d7..6867489 100644 --- a/src/app/feature/initial-form/initial-form.component.ts +++ b/src/app/feature/initial-form/initial-form.component.ts @@ -1,5 +1,10 @@ import { Component } from '@angular/core'; -import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; +import { + FormControl, + FormGroup, + ReactiveFormsModule, + Validators, +} from '@angular/forms'; import { StoreService } from '../../core/store/store.service'; @Component({ @@ -14,7 +19,7 @@ export class InitialFormComponent { email: new FormControl(), password: new FormControl(), repeatpassword: new FormControl(), - username: new FormControl(), + username: new FormControl('', Validators.required), }); displayWeb: boolean = false; diff --git a/src/app/shared/header/header.component.css b/src/app/shared/header/header.component.css index 30b7b06..4c5d637 100644 --- a/src/app/shared/header/header.component.css +++ b/src/app/shared/header/header.component.css @@ -3,4 +3,4 @@ header { padding-inline: 3rem; display: flex; justify-content: space-between; -} +} diff --git a/src/app/shared/header/header.component.html b/src/app/shared/header/header.component.html index 953ac0a..48301c4 100644 --- a/src/app/shared/header/header.component.html +++ b/src/app/shared/header/header.component.html @@ -6,5 +6,7 @@

width="200" />

+ + - + diff --git a/src/app/shared/header/header.component.spec.ts b/src/app/shared/header/header.component.spec.ts index a5637f5..eb5dcfc 100644 --- a/src/app/shared/header/header.component.spec.ts +++ b/src/app/shared/header/header.component.spec.ts @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { HeaderComponent } from './header.component'; import { By } from '@angular/platform-browser'; +import { provideHttpClient } from '@angular/common/http'; describe('HeaderComponent', () => { let component: HeaderComponent; @@ -10,6 +11,7 @@ describe('HeaderComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [HeaderComponent], + providers: [provideHttpClient()], }).compileComponents(); fixture = TestBed.createComponent(HeaderComponent); @@ -37,4 +39,4 @@ describe('HeaderComponent', () => { const image = fixture.debugElement.query(By.css('img')).nativeElement; expect(image.alt).toContain('Logo de Magic'); }); -}); +}); diff --git a/src/app/shared/header/header.component.ts b/src/app/shared/header/header.component.ts index 963cbc1..ba74421 100644 --- a/src/app/shared/header/header.component.ts +++ b/src/app/shared/header/header.component.ts @@ -1,11 +1,12 @@ import { Component } from '@angular/core'; import { MenuComponent } from '../menu/menu.component'; +import { GreetingComponent } from '../../feature/greeting/greeting.component'; @Component({ selector: 'app-header', standalone: true, templateUrl: './header.component.html', styleUrl: './header.component.css', - imports: [MenuComponent], + imports: [MenuComponent, GreetingComponent], }) -export class HeaderComponent {} +export class HeaderComponent {}