Skip to content
Snippets Groups Projects
Commit 93a61fe3 authored by Maciej Żuralski's avatar Maciej Żuralski
Browse files

test: wedding component ale nie wiem co tu dac za testy

parent 2cfafd2f
Branches
1 merge request!110test: front tests
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { WeddingComponent } from './wedding.component';
import { WeddingService } from '../../services/wedding.service';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { of } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { WeddingType } from '../../models/wedding.type';
import { SharedService } from '../../services/shared.service';
describe('WeddingComponent', () => {
let component: WeddingComponent;
let fixture: ComponentFixture<WeddingComponent>;
let native: HTMLElement;
let weddingService: jasmine.SpyObj<WeddingService>;
let sharedService: jasmine.SpyObj<SharedService>;
const weddingId = '4d35e8f0-b155-4e79-b5e8-f0b1550e7940';
beforeEach(async () => {
const spyWeddingService = jasmine.createSpyObj<WeddingService>('WeddingService', ['getWeddingById', 'getWeddingBackground']);
const spyShardedService = jasmine.createSpyObj<SharedService>('SharedService', ['changeWeddingMessage']);
await TestBed.configureTestingModule({
imports: [WeddingComponent]
imports: [
WeddingComponent,
NoopAnimationsModule
],
providers: [
provideRouter([]),
provideHttpClient(),
provideHttpClientTesting(),
{ provide: WeddingService, useValue: spyWeddingService },
{ provide: SharedService, useValue: spyShardedService }
]
})
.compileComponents();
.compileComponents();
fixture = TestBed.createComponent(WeddingComponent);
native = fixture.nativeElement;
component = fixture.componentInstance;
component.weddingId = weddingId;
weddingService = TestBed.inject(WeddingService) as jasmine.SpyObj<WeddingService>;
sharedService = TestBed.inject(SharedService) as jasmine.SpyObj<SharedService>;
const wedding : WeddingType =
{
id: weddingId,
name: 'Test wedding',
eventStartDateTime: '2020-20-20 20:20'
};
weddingService.getWeddingById.and.returnValue(of(wedding));
sharedService.changeWeddingMessage.and.returnValue();
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
......@@ -66,7 +66,7 @@ export class WeddingComponent implements OnInit {
let weddingDate = new Date(wedding.eventStartDateTime);
let today = new Date();
this.sharedService.changeWeddingMessage(weddingDate.getTime() - today.getTime() < 8640000000); // 86400000 = 24h
this.sharedService.changeWeddingMessage(weddingDate.getTime() - today.getTime() < 86400000); // 86400000 = 24h
},
error: (error) => console.error('Error getting wedding:', error)
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment