Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(*): working on increased coverage #327

Merged
merged 10 commits into from
Dec 11, 2023
Merged
10 changes: 8 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"outputPath": "dist/bellumgens/browser",
"index": "projects/bellumgens/src/index.html",
"main": "projects/bellumgens/src/main.ts",
"polyfills": ["zone.js"],
"polyfills": [
"zone.js",
"@angular/localize/init"
],
"tsConfig": "projects/bellumgens/tsconfig.app.json",
"assets": [
"projects/bellumgens/src/favicon.ico",
Expand Down Expand Up @@ -352,7 +355,10 @@
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ebleague/src/test.ts",
"polyfills": ["zone.js"],
"polyfills": [
"zone.js",
"@angular/localize/init"
],
"tsConfig": "projects/ebleague/tsconfig.spec.json",
"karmaConfig": "projects/ebleague/karma.conf.js",
"styles": [
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"@angular/service-worker": "17.0.4",
"@angular/ssr": "^17.0.3",
"@igniteui/material-icons-extended": "^3.0.2",
"@infragistics/igniteui-angular": "17.0.3",
"@infragistics/igniteui-angular": "17.0.4",
"@types/express": "^4.17.17",
"compression": "^1.7.4",
"express": "^4.18.1",
"hammerjs": "^2.0.8",
"igniteui-angular-i18n": "^17.0.3",
"igniteui-angular-i18n": "^17.0.4",
"minireset.css": "0.0.4",
"rxjs": "^7.8.0",
"tslib": "^2.6.2",
Expand Down
7 changes: 6 additions & 1 deletion projects/bellumgens/src/app/events/events.component.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
:host {
display: flex;
height: 100%;
height: calc(100% - 45px);
width: 100%;
background-image: url('/assets/bge/bge-background-right.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: bottom right;

@font-face {
font-family: 'dge-ebold';
Expand Down Expand Up @@ -42,6 +45,8 @@
}

@media screen and (max-width: 1024px) {
background-position: center;

.content-container h1 {
font-size: 36pt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { LoginButtonsComponent } from './login-buttons.component';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { ServiceWorkerModule } from '@angular/service-worker';
import { RouterTestingModule } from '@angular/router/testing';
import { LoginProvider } from '../../../models/login-provider';
import { LOGIN_ASSETS } from '../../../models/misc';
import { LoginService } from '../../../services/login.service';
import { LoginProvider, LoginService } from '../../../public_api';

describe('LoginButtonsComponent', () => {
let component: LoginButtonsComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { LoginDialogComponent } from './login-dialog.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ServiceWorkerModule } from '@angular/service-worker';
import {
IgxDialogModule,
IgxButtonModule,
IgxIconModule,
IgxDividerModule,
IgxCheckboxModule,
IgxInputGroupModule
} from '@infragistics/igniteui-angular';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { LoginButtonsComponent } from '../login-buttons/login-buttons.component';
import { ServiceWorkerModule } from '@angular/service-worker';

import { ApplicationUser, CommunicationService, LoginService } from '../../../public_api';

import { LoginDialogComponent } from './login-dialog.component';

describe('LoginDialogComponent', () => {
let component: LoginDialogComponent;
let fixture: ComponentFixture<LoginDialogComponent>;
let httpMock: HttpTestingController;
let loginService: LoginService;
let commsService: CommunicationService;
let router: Router;
const applicationUser: ApplicationUser = {
id: '1',
steamId: 'test-steam-id',
battleNetId: 'test-battlenet-id',
username: 'test-user',
email: 'test-email',
avatarFull: 'test-avatar',
avatarMedium: 'test-avatar',
avatarIcon: 'test-avatar',
customURL: 'test-url',
realname: 'test-realname',
searchVisible: false,
externalLogins: [
'Steam'
]
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
imports: [
FormsModule,
HttpClientTestingModule,
RouterTestingModule,
NoopAnimationsModule,
ServiceWorkerModule.register('', { enabled: false }),
IgxDialogModule,
IgxButtonModule,
IgxIconModule,
IgxDividerModule,
IgxCheckboxModule,
IgxInputGroupModule,
LoginDialogComponent, LoginButtonsComponent
]
})
LoginDialogComponent
]
})
.compileComponents();

loginService = TestBed.inject(LoginService);
httpMock = TestBed.inject(HttpTestingController);
commsService = TestBed.inject(CommunicationService);
router = TestBed.get(Router);
}));

beforeEach(() => {
Expand All @@ -49,4 +62,52 @@ describe('LoginDialogComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should initialize logininfo with empty values', () => {
expect(component.logininfo).toEqual({
username: '',
password: '',
rememberMe: false
})
});

it('should open the login dialog', () => {
spyOn(component.dialog, 'open');
component.openLogin();
expect(component.dialog.open).toHaveBeenCalled();
});

it('should open the registration dialog', () => {
spyOn(component.dialog, 'close');
spyOn(router, 'navigate');
component.openRegistration();
expect(component.dialog.close).toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith(['register']);
});

it('should perform login with form data', () => {
spyOn(component.dialog, 'close');
// Set form data
component.logininfo.username = 'testuser';
component.logininfo.password = 'testpassword';

commsService.success.subscribe(message => expect(message).toEqual('Logged in successfully!'));
// Call the loginWithForm method
component.loginWithForm();
const req = httpMock.expectOne(`${loginService['_apiEndpoint']}/login`);
expect(req.request.method).toBe('POST');
expect(req.request.body).toEqual(component.logininfo);
expect(req.request.withCredentials).toBe(true);
expect(component.submitInProgress).toBe(true);
req.flush(applicationUser);
expect(component.submitInProgress).toBe(false);
expect(component.dialog.close).toHaveBeenCalled();
expect(loginService['_applicationUser'].value).toEqual(applicationUser);

const req2 = httpMock.expectOne(`${loginService['_apiBase']}/tournament/registrations`);
expect(req2.request.method).toBe('GET');
expect(req2.request.withCredentials).toBe(true);
req2.flush([]);
expect(loginService['_registrations'].value).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ export class LoginDialogComponent {
}

public openRegistration() {
this.router.navigate(['register']);
this.dialog.close();
this.router.navigate(['register']);
}

public loginWithForm() {
this.authManager.loginWithForm(this.logininfo).subscribe(() => this.dialog.close());
this.submitInProgress = true;
this.authManager.loginWithForm(this.logininfo).subscribe(() => {
this.dialog.close();
this.submitInProgress = false;
});
}
}
2 changes: 0 additions & 2 deletions projects/common/src/lib/login/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { LoginComponent } from './login.component';
import { RouterTestingModule } from '@angular/router/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ServiceWorkerModule } from '@angular/service-worker';
import { FormsModule } from '@angular/forms';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { ApplicationUser, LoginService } from '../../public_api';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -32,7 +31,6 @@ describe('LoginComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
RouterTestingModule,
NoopAnimationsModule,
HttpClientTestingModule,
Expand Down
Loading