add unit test
This commit is contained in:
parent
275bd37552
commit
02932ee64b
21 changed files with 19754 additions and 19754 deletions
222
angular.json
222
angular.json
|
|
@ -1,112 +1,112 @@
|
|||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"TFTPaths": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
"style": "scss"
|
||||
}
|
||||
},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "dist/TFTPaths",
|
||||
"index": "src/index.html",
|
||||
"main": "src/main.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"aot": false,
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "src/environments/environment.ts",
|
||||
"with": "src/environments/environment.prod.ts"
|
||||
}
|
||||
],
|
||||
"optimization": true,
|
||||
"outputHashing": "all",
|
||||
"sourceMap": false,
|
||||
"extractCss": true,
|
||||
"namedChunks": false,
|
||||
"aot": true,
|
||||
"extractLicenses": true,
|
||||
"vendorChunk": false,
|
||||
"buildOptimizer": true,
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "2mb",
|
||||
"maximumError": "5mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "6kb",
|
||||
"maximumError": "10kb"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"options": {
|
||||
"browserTarget": "TFTPaths:build"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "TFTPaths:build:production"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "TFTPaths:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"tsconfig.app.json",
|
||||
"tsconfig.spec.json",
|
||||
"e2e/tsconfig.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
},
|
||||
"e2e": {
|
||||
"builder": "@angular-devkit/build-angular:protractor",
|
||||
"options": {
|
||||
"protractorConfig": "e2e/protractor.conf.js",
|
||||
"devServerTarget": "TFTPaths:serve"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"devServerTarget": "TFTPaths:serve:production"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
"defaultProject": "TFTPaths"
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"TFTPaths": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
"style": "scss"
|
||||
}
|
||||
},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "dist/TFTPaths",
|
||||
"index": "src/index.html",
|
||||
"main": "src/main.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"aot": false,
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "src/environments/environment.ts",
|
||||
"with": "src/environments/environment.prod.ts"
|
||||
}
|
||||
],
|
||||
"optimization": true,
|
||||
"outputHashing": "all",
|
||||
"sourceMap": false,
|
||||
"extractCss": true,
|
||||
"namedChunks": false,
|
||||
"aot": true,
|
||||
"extractLicenses": true,
|
||||
"vendorChunk": false,
|
||||
"buildOptimizer": true,
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "2mb",
|
||||
"maximumError": "5mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "6kb",
|
||||
"maximumError": "10kb"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"options": {
|
||||
"browserTarget": "TFTPaths:build"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "TFTPaths:build:production"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "TFTPaths:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"tsconfig.app.json",
|
||||
"tsconfig.spec.json",
|
||||
"e2e/tsconfig.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
},
|
||||
"e2e": {
|
||||
"builder": "@angular-devkit/build-angular:protractor",
|
||||
"options": {
|
||||
"protractorConfig": "e2e/protractor.conf.js",
|
||||
"devServerTarget": "TFTPaths:serve"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"devServerTarget": "TFTPaths:serve:production"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
"defaultProject": "TFTPaths"
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
const { pathsToModuleNameMapper } = require('ts-jest/utils');
|
||||
const { compilerOptions } = require('./tsconfig');
|
||||
|
||||
module.exports = {
|
||||
preset: 'jest-preset-angular',
|
||||
roots: ['<rootDir>/src/'],
|
||||
testMatch: ['**/+(*.)+(spec).+(ts)'],
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test.ts'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html'],
|
||||
coverageDirectory: 'coverage/my-app',
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, {
|
||||
prefix: '<rootDir>/'
|
||||
})
|
||||
const { pathsToModuleNameMapper } = require('ts-jest/utils');
|
||||
const { compilerOptions } = require('./tsconfig');
|
||||
|
||||
module.exports = {
|
||||
preset: 'jest-preset-angular',
|
||||
roots: ['<rootDir>/src/'],
|
||||
testMatch: ['**/+(*.)+(spec).+(ts)'],
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test.ts'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html'],
|
||||
coverageDirectory: 'coverage/my-app',
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, {
|
||||
prefix: '<rootDir>/'
|
||||
})
|
||||
};
|
||||
35470
package-lock.json
generated
35470
package-lock.json
generated
File diff suppressed because it is too large
Load diff
92
package.json
92
package.json
|
|
@ -1,46 +1,46 @@
|
|||
{
|
||||
"name": "tftpaths",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"test": "npx jest",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^11.2.11",
|
||||
"@angular/common": "^11.2.11",
|
||||
"@angular/compiler": "^11.2.11",
|
||||
"@angular/core": "^11.2.11",
|
||||
"@angular/forms": "^11.2.11",
|
||||
"@angular/platform-browser": "^11.2.11",
|
||||
"@angular/platform-browser-dynamic": "^11.2.11",
|
||||
"@angular/router": "^11.2.11",
|
||||
"lodash": "^4.17.21",
|
||||
"rxjs": "~6.6.7",
|
||||
"tslib": "^1.14.1",
|
||||
"zone.js": "~0.10.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^0.1102.10",
|
||||
"@angular/cli": "^11.2.10",
|
||||
"@angular/compiler-cli": "^11.2.11",
|
||||
"@angular/language-service": "^11.2.11",
|
||||
"@types/jasmine": "~3.3.8",
|
||||
"@types/jasminewd2": "^2.0.8",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "~8.9.4",
|
||||
"codelyzer": "^6.0.1",
|
||||
"jasmine-core": "~3.4.0",
|
||||
"jasmine-spec-reporter": "~4.2.1",
|
||||
"jest": "^27.3.1",
|
||||
"jest-preset-angular": "^10.0.1",
|
||||
"protractor": "^7.0.0",
|
||||
"ts-node": "~7.0.0",
|
||||
"tslint": "~6.1.3",
|
||||
"typescript": "~4.0.7"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "tftpaths",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"test": "npx jest",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^11.2.11",
|
||||
"@angular/common": "^11.2.11",
|
||||
"@angular/compiler": "^11.2.11",
|
||||
"@angular/core": "^11.2.11",
|
||||
"@angular/forms": "^11.2.11",
|
||||
"@angular/platform-browser": "^11.2.11",
|
||||
"@angular/platform-browser-dynamic": "^11.2.11",
|
||||
"@angular/router": "^11.2.11",
|
||||
"lodash": "^4.17.21",
|
||||
"rxjs": "~6.6.7",
|
||||
"tslib": "^1.14.1",
|
||||
"zone.js": "~0.10.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^0.1102.10",
|
||||
"@angular/cli": "^11.2.10",
|
||||
"@angular/compiler-cli": "^11.2.11",
|
||||
"@angular/language-service": "^11.2.11",
|
||||
"@types/jasmine": "~3.3.8",
|
||||
"@types/jasminewd2": "^2.0.8",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "~8.9.4",
|
||||
"codelyzer": "^6.0.1",
|
||||
"jasmine-core": "~3.4.0",
|
||||
"jasmine-spec-reporter": "~4.2.1",
|
||||
"jest": "^27.3.1",
|
||||
"jest-preset-angular": "^10.0.1",
|
||||
"protractor": "^7.0.0",
|
||||
"ts-node": "~7.0.0",
|
||||
"tslint": "~6.1.3",
|
||||
"typescript": "~4.0.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule
|
||||
],
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should have as title 'TFTPaths'`, () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
app.ngOnInit();
|
||||
expect(app.title).toEqual('TFTPaths');
|
||||
});
|
||||
|
||||
});
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule
|
||||
],
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should have as title 'TFTPaths'`, () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
app.ngOnInit();
|
||||
expect(app.title).toEqual('TFTPaths');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,18 +1,18 @@
|
|||
import { Bonus } from './bonus';
|
||||
|
||||
describe('Bonus', () => {
|
||||
let bonus: Bonus;
|
||||
beforeEach(() => {
|
||||
bonus = new Bonus('bonus example', 'knight', 1, 6);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockBonus = {
|
||||
description: 'bonus example',
|
||||
role: 'knight',
|
||||
units: 1,
|
||||
maxUnits: 6
|
||||
}
|
||||
expect(bonus).toEqual(mockBonus);
|
||||
});
|
||||
import { Bonus } from './bonus';
|
||||
|
||||
describe('Bonus', () => {
|
||||
let bonus: Bonus;
|
||||
beforeEach(() => {
|
||||
bonus = new Bonus('bonus example', 'knight', 1, 6);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockBonus = {
|
||||
description: 'bonus example',
|
||||
role: 'knight',
|
||||
units: 1,
|
||||
maxUnits: 6
|
||||
}
|
||||
expect(bonus).toEqual(mockBonus);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,21 +1,21 @@
|
|||
import { Champion } from './champion';
|
||||
|
||||
describe('Champion', () => {
|
||||
let champion: Champion;
|
||||
beforeEach(() => {
|
||||
champion = new Champion('John Doe', 'johndoe', ['knight'], 3, false, false, false);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockChampion = {
|
||||
name: 'John Doe',
|
||||
img: 'johndoe',
|
||||
roles: ['knight'],
|
||||
cost: 3,
|
||||
isSelected: false,
|
||||
sinergy: false,
|
||||
sinergy2: false
|
||||
}
|
||||
expect(champion).toEqual(mockChampion);
|
||||
});
|
||||
import { Champion } from './champion';
|
||||
|
||||
describe('Champion', () => {
|
||||
let champion: Champion;
|
||||
beforeEach(() => {
|
||||
champion = new Champion('John Doe', 'johndoe', ['knight'], 3, false, false, false);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockChampion = {
|
||||
name: 'John Doe',
|
||||
img: 'johndoe',
|
||||
roles: ['knight'],
|
||||
cost: 3,
|
||||
isSelected: false,
|
||||
sinergy: false,
|
||||
sinergy2: false
|
||||
}
|
||||
expect(champion).toEqual(mockChampion);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
import { Bonus } from './bonus';
|
||||
import { Champion } from './champion';
|
||||
import { DataToShare } from './dataToShare';
|
||||
|
||||
describe('DataToShare', () => {
|
||||
let dataToShare: DataToShare;
|
||||
const champion = new Champion('John Doe', 'johndoe', ['knight'], 3, false, false, false);
|
||||
const bonus = new Bonus('bonus example', 'knight', 1, 6);
|
||||
beforeEach(() => {
|
||||
dataToShare = new DataToShare([champion], ['knight'], [3, 6], ['knight'], [bonus], true, 1);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockDataToShare = {
|
||||
champions: [champion],
|
||||
roles: ['knight'],
|
||||
rolesCount: [3, 6],
|
||||
rolesPool: ['knight'],
|
||||
bonusesPool: [bonus],
|
||||
noChampSelected: true,
|
||||
teamSize: 1
|
||||
}
|
||||
expect(dataToShare).toEqual(mockDataToShare);
|
||||
});
|
||||
import { Bonus } from './bonus';
|
||||
import { Champion } from './champion';
|
||||
import { DataToShare } from './dataToShare';
|
||||
|
||||
describe('DataToShare', () => {
|
||||
let dataToShare: DataToShare;
|
||||
const champion = new Champion('John Doe', 'johndoe', ['knight'], 3, false, false, false);
|
||||
const bonus = new Bonus('bonus example', 'knight', 1, 6);
|
||||
beforeEach(() => {
|
||||
dataToShare = new DataToShare([champion], ['knight'], [3, 6], ['knight'], [bonus], true, 1);
|
||||
});
|
||||
|
||||
it('should create a bonus', () => {
|
||||
const mockDataToShare = {
|
||||
champions: [champion],
|
||||
roles: ['knight'],
|
||||
rolesCount: [3, 6],
|
||||
rolesPool: ['knight'],
|
||||
bonusesPool: [bonus],
|
||||
noChampSelected: true,
|
||||
teamSize: 1
|
||||
}
|
||||
expect(dataToShare).toEqual(mockDataToShare);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,40 +1,40 @@
|
|||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CardComponent } from './card.component';
|
||||
|
||||
describe('CardComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule
|
||||
],
|
||||
declarations: [
|
||||
CardComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create a card', () => {
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
expect(card).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should get a imageUrl', () => {
|
||||
const mockResponse = 'url(../../assets/images/champions/johndoe.png)';
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
expect(card.getImage('johndoe').changingThisBreaksApplicationSecurity).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should emit a value', () => {
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
let valueEmitted;
|
||||
card.championClicked.subscribe( event =>{
|
||||
valueEmitted = event;
|
||||
})
|
||||
card.selectChampion('John Doe');
|
||||
expect(valueEmitted).toBe('John Doe');
|
||||
});
|
||||
});
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CardComponent } from './card.component';
|
||||
|
||||
describe('CardComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule
|
||||
],
|
||||
declarations: [
|
||||
CardComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create a card', () => {
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
expect(card).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should get a imageUrl', () => {
|
||||
const mockResponse = 'url(../../assets/images/champions/johndoe.png)';
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
expect(card.getImage('johndoe').changingThisBreaksApplicationSecurity).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should emit a value', () => {
|
||||
const fixture = TestBed.createComponent(CardComponent);
|
||||
const card = fixture.debugElement.componentInstance;
|
||||
let valueEmitted;
|
||||
card.championClicked.subscribe( event =>{
|
||||
valueEmitted = event;
|
||||
})
|
||||
card.selectChampion('John Doe');
|
||||
expect(valueEmitted).toBe('John Doe');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
import { Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
import { Champion } from '@models/champion';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-card',
|
||||
templateUrl: './card.component.html',
|
||||
styleUrls: ['./card.component.scss']
|
||||
})
|
||||
|
||||
export class CardComponent{
|
||||
|
||||
@Input() champion: Champion;
|
||||
@Input() noChampSelected: boolean;
|
||||
@Output() championClicked = new EventEmitter<Champion>();
|
||||
|
||||
constructor(
|
||||
private sanitizer: DomSanitizer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get champion image
|
||||
* @param name Champion name
|
||||
*/
|
||||
getImage(name) {
|
||||
return this.sanitizer.bypassSecurityTrustStyle(`url(${'../../assets/images/champions/' + name + '.png'})`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output to parent with champion clicked
|
||||
* @param champion Champion
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
this.championClicked.emit(champion);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
import { Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
import { Champion } from '@models/champion';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-card',
|
||||
templateUrl: './card.component.html',
|
||||
styleUrls: ['./card.component.scss']
|
||||
})
|
||||
|
||||
export class CardComponent{
|
||||
|
||||
@Input() champion: Champion;
|
||||
@Input() noChampSelected: boolean;
|
||||
@Output() championClicked = new EventEmitter<Champion>();
|
||||
|
||||
constructor(
|
||||
private sanitizer: DomSanitizer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get champion image
|
||||
* @param name Champion name
|
||||
*/
|
||||
getImage(name) {
|
||||
return this.sanitizer.bypassSecurityTrustStyle(`url(${'../../assets/images/champions/' + name + '.png'})`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output to parent with champion clicked
|
||||
* @param champion Champion
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
this.championClicked.emit(champion);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +1,73 @@
|
|||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CardComponent } from '../card/card.component';
|
||||
import { PoolComponent } from './pool.component';
|
||||
|
||||
describe('PoolComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
declarations: [
|
||||
PoolComponent,
|
||||
CardComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create a pool', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
expect(pool).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should set form teamSize', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
pool.ngOnInit();
|
||||
expect(pool.formFilters).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should select a Champion', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockChampion = pool.champions[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectChampion(mockChampion);
|
||||
expect(pool.teamSize).toBe(1);
|
||||
expect(pool.rolesPool).toContain(mockChampion.roles[0]);
|
||||
});
|
||||
|
||||
it('should select a Role', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
expect(pool.teamSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check if a role is selected', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
expect(pool.checkRoleFilter(mockRole)).toBe(true);
|
||||
});
|
||||
|
||||
it('should reset composition', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
pool.resetComposition();
|
||||
expect(pool.teamSize).toBe(0);
|
||||
expect(pool.rolesCount.lenght).toBeUndefined();
|
||||
expect(pool.rolesPool.lenght).toBeUndefined();
|
||||
});
|
||||
});
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CardComponent } from '../card/card.component';
|
||||
import { PoolComponent } from './pool.component';
|
||||
|
||||
describe('PoolComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
declarations: [
|
||||
PoolComponent,
|
||||
CardComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create a pool', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
expect(pool).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should set form teamSize', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
pool.ngOnInit();
|
||||
expect(pool.formFilters).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should select a Champion', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockChampion = pool.champions[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectChampion(mockChampion);
|
||||
expect(pool.teamSize).toBe(1);
|
||||
expect(pool.rolesPool).toContain(mockChampion.roles[0]);
|
||||
});
|
||||
|
||||
it('should select a Role', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
expect(pool.teamSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check if a role is selected', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
expect(pool.checkRoleFilter(mockRole)).toBe(true);
|
||||
});
|
||||
|
||||
it('should reset composition', () => {
|
||||
const fixture = TestBed.createComponent(PoolComponent);
|
||||
const pool = fixture.debugElement.componentInstance;
|
||||
const mockRole = pool.champions[0].roles[0];
|
||||
pool.ngOnInit();
|
||||
pool.selectRole(mockRole);
|
||||
pool.resetComposition();
|
||||
expect(pool.teamSize).toBe(0);
|
||||
expect(pool.rolesCount.lenght).toBeUndefined();
|
||||
expect(pool.rolesPool.lenght).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,100 +1,100 @@
|
|||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
|
||||
import { Champion } from '@models/champion';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import { PoolService } from '@modules/pool/services/pool.service';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { DataToShare } from '@models/dataToShare';
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-pool',
|
||||
templateUrl: './pool.component.html',
|
||||
styleUrls: ['./pool.component.scss']
|
||||
})
|
||||
|
||||
export class PoolComponent implements OnInit, OnDestroy {
|
||||
formFilters: FormGroup;
|
||||
bonusesPool: Bonus[] = [];
|
||||
champions: Champion[] = [];
|
||||
noChampSelected = true;
|
||||
roles: string[] = [];
|
||||
rolesCount: number[] = [];
|
||||
rolesPool: string[] = [];
|
||||
teamSize = 0;
|
||||
subscription: Subscription;
|
||||
|
||||
|
||||
constructor(
|
||||
private fb: FormBuilder,
|
||||
private poolService: PoolService
|
||||
) {
|
||||
this.subscription = this.poolService.setChampions().subscribe( (data: DataToShare) => {
|
||||
if (data) {
|
||||
const {champions, roles, rolesPool, bonusesPool, noChampSelected, teamSize} = data;
|
||||
this.champions = champions;
|
||||
this.roles = roles;
|
||||
this.rolesPool = rolesPool;
|
||||
this.bonusesPool = bonusesPool;
|
||||
this.noChampSelected = noChampSelected;
|
||||
this.teamSize = teamSize;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.formFilters = this.fb.group({
|
||||
teamSize: [this.teamSize]
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if(this.subscription) {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select or unselect champion
|
||||
* @param champion model
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
this.poolService.selectChampion(champion);
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select role pool
|
||||
* @param role name of role
|
||||
*/
|
||||
selectRole(role) {
|
||||
this.poolService.selectRole(role);
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check role filter selected
|
||||
* @param role name
|
||||
*/
|
||||
checkRoleFilter(role) {
|
||||
return this.poolService.checkRoleFilter(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset composition
|
||||
*/
|
||||
resetComposition() {
|
||||
this.poolService.resetComposition();
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
}
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
|
||||
import { Champion } from '@models/champion';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import { PoolService } from '@modules/pool/services/pool.service';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { DataToShare } from '@models/dataToShare';
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-pool',
|
||||
templateUrl: './pool.component.html',
|
||||
styleUrls: ['./pool.component.scss']
|
||||
})
|
||||
|
||||
export class PoolComponent implements OnInit, OnDestroy {
|
||||
formFilters: FormGroup;
|
||||
bonusesPool: Bonus[] = [];
|
||||
champions: Champion[] = [];
|
||||
noChampSelected = true;
|
||||
roles: string[] = [];
|
||||
rolesCount: number[] = [];
|
||||
rolesPool: string[] = [];
|
||||
teamSize = 0;
|
||||
subscription: Subscription;
|
||||
|
||||
|
||||
constructor(
|
||||
private fb: FormBuilder,
|
||||
private poolService: PoolService
|
||||
) {
|
||||
this.subscription = this.poolService.setChampions().subscribe( (data: DataToShare) => {
|
||||
if (data) {
|
||||
const {champions, roles, rolesPool, bonusesPool, noChampSelected, teamSize} = data;
|
||||
this.champions = champions;
|
||||
this.roles = roles;
|
||||
this.rolesPool = rolesPool;
|
||||
this.bonusesPool = bonusesPool;
|
||||
this.noChampSelected = noChampSelected;
|
||||
this.teamSize = teamSize;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.formFilters = this.fb.group({
|
||||
teamSize: [this.teamSize]
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if(this.subscription) {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select or unselect champion
|
||||
* @param champion model
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
this.poolService.selectChampion(champion);
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select role pool
|
||||
* @param role name of role
|
||||
*/
|
||||
selectRole(role) {
|
||||
this.poolService.selectRole(role);
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check role filter selected
|
||||
* @param role name
|
||||
*/
|
||||
checkRoleFilter(role) {
|
||||
return this.poolService.checkRoleFilter(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset composition
|
||||
*/
|
||||
resetComposition() {
|
||||
this.poolService.resetComposition();
|
||||
this.formFilters.patchValue({
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { PoolRoutingModule } from './pool-routing.module';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { PoolService } from '@modules/pool/services/pool.service';
|
||||
|
||||
import { PoolComponent } from './components/pool/pool.component';
|
||||
import { CardComponent } from './components/card/card.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
PoolComponent,
|
||||
CardComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
PoolRoutingModule,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
providers: [PoolService]
|
||||
})
|
||||
|
||||
export class PoolModule { }
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { PoolRoutingModule } from './pool-routing.module';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { PoolService } from '@modules/pool/services/pool.service';
|
||||
|
||||
import { PoolComponent } from './components/pool/pool.component';
|
||||
import { CardComponent } from './components/card/card.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
PoolComponent,
|
||||
CardComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
PoolRoutingModule,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
providers: [PoolService]
|
||||
})
|
||||
|
||||
export class PoolModule { }
|
||||
|
|
|
|||
|
|
@ -1,66 +1,66 @@
|
|||
import { PoolService } from './pool.service';
|
||||
|
||||
describe('PoolService', () => {
|
||||
let poolService: PoolService;
|
||||
beforeEach(() => {
|
||||
poolService = new PoolService();
|
||||
|
||||
});
|
||||
|
||||
it('should set Champions', () => {
|
||||
let dataSet;
|
||||
poolService.dataToShare.subscribe( data => {
|
||||
dataSet = data;
|
||||
})
|
||||
poolService.setChampions();
|
||||
expect(dataSet).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should update data to share', () => {
|
||||
let dataSetBefore;
|
||||
let dataSetAfter;
|
||||
poolService.dataToShare.subscribe( data => {
|
||||
if (dataSetBefore === undefined) {
|
||||
dataSetBefore = data;
|
||||
} else {
|
||||
dataSetAfter = data;
|
||||
}
|
||||
});
|
||||
poolService.setChampions();
|
||||
poolService.updateDataToShare();
|
||||
expect(dataSetBefore).not.toEqual(dataSetAfter);
|
||||
});
|
||||
|
||||
it('should select a champion', () => {
|
||||
const mockChampion = poolService.champions[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectChampion(mockChampion);
|
||||
expect(poolService.teamSize).toBe(1);
|
||||
poolService.selectChampion(mockChampion);
|
||||
expect(poolService.teamSize).toBe(0);
|
||||
});
|
||||
|
||||
it('should select a role', () => {
|
||||
const mockRole = poolService.champions[0].roles[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.teamSize).toBeGreaterThan(0);
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.teamSize).toBe(0);
|
||||
});
|
||||
|
||||
it('should check role filter', () => {
|
||||
const mockRole = poolService.champions[0].roles[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.checkRoleFilter(mockRole)).toBe(true);
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.checkRoleFilter(mockRole)).toBe(false);
|
||||
});
|
||||
|
||||
it('should sort champions', () => {
|
||||
poolService.setChampions();
|
||||
poolService.championSort('cost');
|
||||
expect(poolService.champions[0].cost).toBe(1);
|
||||
});
|
||||
import { PoolService } from './pool.service';
|
||||
|
||||
describe('PoolService', () => {
|
||||
let poolService: PoolService;
|
||||
beforeEach(() => {
|
||||
poolService = new PoolService();
|
||||
|
||||
});
|
||||
|
||||
it('should set Champions', () => {
|
||||
let dataSet;
|
||||
poolService.dataToShare.subscribe( data => {
|
||||
dataSet = data;
|
||||
})
|
||||
poolService.setChampions();
|
||||
expect(dataSet).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should update data to share', () => {
|
||||
let dataSetBefore;
|
||||
let dataSetAfter;
|
||||
poolService.dataToShare.subscribe( data => {
|
||||
if (dataSetBefore === undefined) {
|
||||
dataSetBefore = data;
|
||||
} else {
|
||||
dataSetAfter = data;
|
||||
}
|
||||
});
|
||||
poolService.setChampions();
|
||||
poolService.updateDataToShare();
|
||||
expect(dataSetBefore).not.toEqual(dataSetAfter);
|
||||
});
|
||||
|
||||
it('should select a champion', () => {
|
||||
const mockChampion = poolService.champions[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectChampion(mockChampion);
|
||||
expect(poolService.teamSize).toBe(1);
|
||||
poolService.selectChampion(mockChampion);
|
||||
expect(poolService.teamSize).toBe(0);
|
||||
});
|
||||
|
||||
it('should select a role', () => {
|
||||
const mockRole = poolService.champions[0].roles[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.teamSize).toBeGreaterThan(0);
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.teamSize).toBe(0);
|
||||
});
|
||||
|
||||
it('should check role filter', () => {
|
||||
const mockRole = poolService.champions[0].roles[0];
|
||||
poolService.setChampions();
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.checkRoleFilter(mockRole)).toBe(true);
|
||||
poolService.selectRole(mockRole);
|
||||
expect(poolService.checkRoleFilter(mockRole)).toBe(false);
|
||||
});
|
||||
|
||||
it('should sort champions', () => {
|
||||
poolService.setChampions();
|
||||
poolService.championSort('cost');
|
||||
expect(poolService.champions[0].cost).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,214 +1,214 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
|
||||
import { Constants } from '@shared/constants';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import { Champion } from '@models/champion';
|
||||
import { DataToShare } from '@models/dataToShare';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PoolService {
|
||||
bonuses: Bonus[] = [...Constants.bonuses];
|
||||
bonusesPool: Bonus[] = [];
|
||||
champions: Champion[] = [...Constants.Champions];
|
||||
championsPool: Champion[] = [];
|
||||
noChampSelected = true;
|
||||
roles: string[]= [...Constants.roles];
|
||||
rolesCount: number[]= [];
|
||||
rolesPool: string[] = [];
|
||||
selectedRole = '';
|
||||
teamSize = 0;
|
||||
dataToShare = new BehaviorSubject<DataToShare>(null);
|
||||
|
||||
constructor() { }
|
||||
|
||||
/**
|
||||
* Set Champion pool and return data
|
||||
* @returns Observable
|
||||
*/
|
||||
setChampions(): Observable<DataToShare> {
|
||||
this.roles.forEach(role => {
|
||||
this.rolesCount[role] = 0;
|
||||
});
|
||||
this.championSort(Constants.championName);
|
||||
this.updateDataToShare();
|
||||
return this.dataToShare.asObservable();
|
||||
}
|
||||
|
||||
updateDataToShare(): void {
|
||||
this.dataToShare.next({
|
||||
champions: this.champions,
|
||||
roles: this.roles,
|
||||
rolesCount: this.rolesCount,
|
||||
rolesPool: this.rolesPool,
|
||||
bonusesPool: this.bonusesPool,
|
||||
noChampSelected: this.noChampSelected,
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select or unselect champion
|
||||
* @param champion model
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
const champIndex = this.champions.findIndex((champ => champ.name === champion.name));
|
||||
if (!this.champions[champIndex].isSelected) {
|
||||
this.champions[champIndex].isSelected = true;
|
||||
this.championsPool.push(champion);
|
||||
champion.roles.forEach(role => {
|
||||
this.rolesCount[role]++;
|
||||
});
|
||||
this.teamSize++;
|
||||
this.noChampSelected = false;
|
||||
} else {
|
||||
this.champions[champIndex].isSelected = false;
|
||||
this.championsPool = _.remove(this.championsPool, champ => {
|
||||
return champ.name !== champion.name;
|
||||
});
|
||||
champion.roles.forEach(role => {
|
||||
this.rolesCount[role]--;
|
||||
});
|
||||
this.teamSize--;
|
||||
if (this.teamSize === 0) {
|
||||
this.noChampSelected = true;
|
||||
}
|
||||
}
|
||||
this.getBonus();
|
||||
this.updatePool();
|
||||
this.updateSinergies();
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort champion by param
|
||||
* @param param use to sort
|
||||
*/
|
||||
championSort(param) {
|
||||
this.champions.sort((a, b) => {
|
||||
if (a[param] > b[param]) {
|
||||
return 1;
|
||||
}
|
||||
if (a[param] < b[param]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select role pool
|
||||
* @param role name of role
|
||||
*/
|
||||
selectRole(role): void {
|
||||
if (role !== this.selectedRole) {
|
||||
this.resetComposition();
|
||||
this.selectedRole = role;
|
||||
let countChampions = 0;
|
||||
this.champions.map(champion => {
|
||||
if (_.indexOf(champion.roles, role) !== -1) {
|
||||
champion.isSelected = true;
|
||||
countChampions++;
|
||||
this.championsPool.push(champion);
|
||||
champion.roles.forEach(rol => {
|
||||
this.rolesCount[rol]++;
|
||||
});
|
||||
}
|
||||
return champion;
|
||||
});
|
||||
this.updatePool();
|
||||
this.updateSinergies();
|
||||
this.teamSize = countChampions;
|
||||
this.getBonus();
|
||||
this.noChampSelected = false;
|
||||
} else {
|
||||
this.resetComposition();
|
||||
}
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get champions bonuses
|
||||
*/
|
||||
getBonus() {
|
||||
this.bonusesPool = [];
|
||||
this.bonuses.forEach(bonus => {
|
||||
if (bonus.units <= this.rolesCount[bonus.role]) {
|
||||
this.bonusesPool[bonus.role] = bonus;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update role pool
|
||||
*/
|
||||
updatePool() {
|
||||
this.rolesPool = [];
|
||||
this.championsPool.forEach(champion => {
|
||||
this.rolesPool = _.union(this.rolesPool, champion.roles);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sinergies
|
||||
*/
|
||||
updateSinergies() {
|
||||
this.champions.map(champion => {
|
||||
champion.sinergy2 = false;
|
||||
return champion.sinergy = false;
|
||||
});
|
||||
this.champions.map(champion => {
|
||||
let countRoles = 0;
|
||||
this.rolesPool.forEach(role => {
|
||||
if (_.indexOf(champion.roles, role) !== -1) {
|
||||
countRoles++;
|
||||
}
|
||||
});
|
||||
switch (countRoles) {
|
||||
case 1:
|
||||
return champion.sinergy = true;
|
||||
case 2:
|
||||
return champion.sinergy2 = true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check role filter selected
|
||||
* @param role name
|
||||
*/
|
||||
checkRoleFilter(role) {
|
||||
if (this.selectedRole === role) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset composition
|
||||
*/
|
||||
resetComposition() {
|
||||
this.rolesCount = [];
|
||||
this.rolesPool = [];
|
||||
this.championsPool = [];
|
||||
this.noChampSelected = true;
|
||||
this.selectedRole = '';
|
||||
this.teamSize = 0;
|
||||
this.champions.map(champion => {
|
||||
champion.sinergy = false;
|
||||
champion.sinergy2 = false;
|
||||
champion.isSelected = false;
|
||||
return champion;
|
||||
});
|
||||
this.setChampions();
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
|
||||
import { Constants } from '@shared/constants';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import { Champion } from '@models/champion';
|
||||
import { DataToShare } from '@models/dataToShare';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PoolService {
|
||||
bonuses: Bonus[] = [...Constants.bonuses];
|
||||
bonusesPool: Bonus[] = [];
|
||||
champions: Champion[] = [...Constants.Champions];
|
||||
championsPool: Champion[] = [];
|
||||
noChampSelected = true;
|
||||
roles: string[]= [...Constants.roles];
|
||||
rolesCount: number[]= [];
|
||||
rolesPool: string[] = [];
|
||||
selectedRole = '';
|
||||
teamSize = 0;
|
||||
dataToShare = new BehaviorSubject<DataToShare>(null);
|
||||
|
||||
constructor() { }
|
||||
|
||||
/**
|
||||
* Set Champion pool and return data
|
||||
* @returns Observable
|
||||
*/
|
||||
setChampions(): Observable<DataToShare> {
|
||||
this.roles.forEach(role => {
|
||||
this.rolesCount[role] = 0;
|
||||
});
|
||||
this.championSort(Constants.championName);
|
||||
this.updateDataToShare();
|
||||
return this.dataToShare.asObservable();
|
||||
}
|
||||
|
||||
updateDataToShare(): void {
|
||||
this.dataToShare.next({
|
||||
champions: this.champions,
|
||||
roles: this.roles,
|
||||
rolesCount: this.rolesCount,
|
||||
rolesPool: this.rolesPool,
|
||||
bonusesPool: this.bonusesPool,
|
||||
noChampSelected: this.noChampSelected,
|
||||
teamSize: this.teamSize
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select or unselect champion
|
||||
* @param champion model
|
||||
*/
|
||||
selectChampion(champion) {
|
||||
const champIndex = this.champions.findIndex((champ => champ.name === champion.name));
|
||||
if (!this.champions[champIndex].isSelected) {
|
||||
this.champions[champIndex].isSelected = true;
|
||||
this.championsPool.push(champion);
|
||||
champion.roles.forEach(role => {
|
||||
this.rolesCount[role]++;
|
||||
});
|
||||
this.teamSize++;
|
||||
this.noChampSelected = false;
|
||||
} else {
|
||||
this.champions[champIndex].isSelected = false;
|
||||
this.championsPool = _.remove(this.championsPool, champ => {
|
||||
return champ.name !== champion.name;
|
||||
});
|
||||
champion.roles.forEach(role => {
|
||||
this.rolesCount[role]--;
|
||||
});
|
||||
this.teamSize--;
|
||||
if (this.teamSize === 0) {
|
||||
this.noChampSelected = true;
|
||||
}
|
||||
}
|
||||
this.getBonus();
|
||||
this.updatePool();
|
||||
this.updateSinergies();
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort champion by param
|
||||
* @param param use to sort
|
||||
*/
|
||||
championSort(param) {
|
||||
this.champions.sort((a, b) => {
|
||||
if (a[param] > b[param]) {
|
||||
return 1;
|
||||
}
|
||||
if (a[param] < b[param]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select role pool
|
||||
* @param role name of role
|
||||
*/
|
||||
selectRole(role): void {
|
||||
if (role !== this.selectedRole) {
|
||||
this.resetComposition();
|
||||
this.selectedRole = role;
|
||||
let countChampions = 0;
|
||||
this.champions.map(champion => {
|
||||
if (_.indexOf(champion.roles, role) !== -1) {
|
||||
champion.isSelected = true;
|
||||
countChampions++;
|
||||
this.championsPool.push(champion);
|
||||
champion.roles.forEach(rol => {
|
||||
this.rolesCount[rol]++;
|
||||
});
|
||||
}
|
||||
return champion;
|
||||
});
|
||||
this.updatePool();
|
||||
this.updateSinergies();
|
||||
this.teamSize = countChampions;
|
||||
this.getBonus();
|
||||
this.noChampSelected = false;
|
||||
} else {
|
||||
this.resetComposition();
|
||||
}
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get champions bonuses
|
||||
*/
|
||||
getBonus() {
|
||||
this.bonusesPool = [];
|
||||
this.bonuses.forEach(bonus => {
|
||||
if (bonus.units <= this.rolesCount[bonus.role]) {
|
||||
this.bonusesPool[bonus.role] = bonus;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update role pool
|
||||
*/
|
||||
updatePool() {
|
||||
this.rolesPool = [];
|
||||
this.championsPool.forEach(champion => {
|
||||
this.rolesPool = _.union(this.rolesPool, champion.roles);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sinergies
|
||||
*/
|
||||
updateSinergies() {
|
||||
this.champions.map(champion => {
|
||||
champion.sinergy2 = false;
|
||||
return champion.sinergy = false;
|
||||
});
|
||||
this.champions.map(champion => {
|
||||
let countRoles = 0;
|
||||
this.rolesPool.forEach(role => {
|
||||
if (_.indexOf(champion.roles, role) !== -1) {
|
||||
countRoles++;
|
||||
}
|
||||
});
|
||||
switch (countRoles) {
|
||||
case 1:
|
||||
return champion.sinergy = true;
|
||||
case 2:
|
||||
return champion.sinergy2 = true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check role filter selected
|
||||
* @param role name
|
||||
*/
|
||||
checkRoleFilter(role) {
|
||||
if (this.selectedRole === role) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset composition
|
||||
*/
|
||||
resetComposition() {
|
||||
this.rolesCount = [];
|
||||
this.rolesPool = [];
|
||||
this.championsPool = [];
|
||||
this.noChampSelected = true;
|
||||
this.selectedRole = '';
|
||||
this.teamSize = 0;
|
||||
this.champions.map(champion => {
|
||||
champion.sinergy = false;
|
||||
champion.sinergy2 = false;
|
||||
champion.isSelected = false;
|
||||
return champion;
|
||||
});
|
||||
this.setChampions();
|
||||
this.updateDataToShare();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
import { Champion } from '@models/champion';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import champions from '@assets/data/champions.json';
|
||||
import traits from '@assets/data/traits.json';
|
||||
|
||||
export class Constants {
|
||||
public static Champions: Champion [] = champions.map(champion => {
|
||||
const championMapped = new Champion(
|
||||
champion.name,
|
||||
champion.championId,
|
||||
champion.traits.map(trait => traits.find(t => t.key === trait).name),
|
||||
champion.cost,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
)
|
||||
return championMapped;
|
||||
}).filter( champion => champion.name !== 'Target Dummy');
|
||||
|
||||
public static championName = 'name';
|
||||
|
||||
public static roles = traits.map(trait => trait.name);
|
||||
|
||||
public static bonuses: Bonus [] = traits.reduce((previous, current) => {
|
||||
current.sets.forEach(set => {
|
||||
previous.push({
|
||||
description: current.description,
|
||||
role: current.name,
|
||||
units: set.min,
|
||||
maxUnits: current.sets[current.sets.length-1].min
|
||||
})
|
||||
})
|
||||
return previous;
|
||||
}, [])
|
||||
}
|
||||
import { Champion } from '@models/champion';
|
||||
import { Bonus } from '@models/bonus';
|
||||
import champions from '@assets/data/champions.json';
|
||||
import traits from '@assets/data/traits.json';
|
||||
|
||||
export class Constants {
|
||||
public static Champions: Champion [] = champions.map(champion => {
|
||||
const championMapped = new Champion(
|
||||
champion.name,
|
||||
champion.championId,
|
||||
champion.traits.map(trait => traits.find(t => t.key === trait).name),
|
||||
champion.cost,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
)
|
||||
return championMapped;
|
||||
}).filter( champion => champion.name !== 'Target Dummy');
|
||||
|
||||
public static championName = 'name';
|
||||
|
||||
public static roles = traits.map(trait => trait.name);
|
||||
|
||||
public static bonuses: Bonus [] = traits.reduce((previous, current) => {
|
||||
current.sets.forEach(set => {
|
||||
previous.push({
|
||||
description: current.description,
|
||||
role: current.name,
|
||||
units: set.min,
|
||||
maxUnits: current.sets[current.sets.length-1].min
|
||||
})
|
||||
})
|
||||
return previous;
|
||||
}, [])
|
||||
}
|
||||
|
|
|
|||
44
src/test.ts
44
src/test.ts
|
|
@ -1,23 +1,23 @@
|
|||
import 'jest-preset-angular/setup-jest';
|
||||
|
||||
Object.defineProperty(window, 'CSS', {value: null});
|
||||
Object.defineProperty(window, 'getComputedStyle', {
|
||||
value: () => {
|
||||
return {
|
||||
display: 'none',
|
||||
appearance: ['-webkit-appearance']
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(document, 'doctype', {
|
||||
value: '<!DOCTYPE html>'
|
||||
});
|
||||
Object.defineProperty(document.body.style, 'transform', {
|
||||
value: () => {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
|
||||
Object.defineProperty(window, 'CSS', {value: null});
|
||||
Object.defineProperty(window, 'getComputedStyle', {
|
||||
value: () => {
|
||||
return {
|
||||
display: 'none',
|
||||
appearance: ['-webkit-appearance']
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(document, 'doctype', {
|
||||
value: '<!DOCTYPE html>'
|
||||
});
|
||||
Object.defineProperty(document.body.style, 'transform', {
|
||||
value: () => {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"outDir": "./dist/out-tsc",
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"downlevelIteration": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "es2015",
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
],
|
||||
"lib": [
|
||||
"es2018",
|
||||
"dom"
|
||||
],
|
||||
"paths": {
|
||||
"@assets/*": ["src/assets/*"],
|
||||
"@models/*": ["src/models/*"],
|
||||
"@modules/*": ["src/modules/*"],
|
||||
"@shared/*": ["src/shared/*"]
|
||||
}
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"fullTemplateTypeCheck": true,
|
||||
"strictInjectionParameters": true
|
||||
}
|
||||
}
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"outDir": "./dist/out-tsc",
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"downlevelIteration": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "es2015",
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
],
|
||||
"lib": [
|
||||
"es2018",
|
||||
"dom"
|
||||
],
|
||||
"paths": {
|
||||
"@assets/*": ["src/assets/*"],
|
||||
"@models/*": ["src/models/*"],
|
||||
"@modules/*": ["src/modules/*"],
|
||||
"@shared/*": ["src/shared/*"]
|
||||
}
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"fullTemplateTypeCheck": true,
|
||||
"strictInjectionParameters": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jest",
|
||||
"jasmine",
|
||||
"node"
|
||||
],
|
||||
"esModuleInterop": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"files": [
|
||||
"src/test.ts",
|
||||
"src/polyfills.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jest",
|
||||
"jasmine",
|
||||
"node"
|
||||
],
|
||||
"esModuleInterop": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"files": [
|
||||
"src/test.ts",
|
||||
"src/polyfills.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue