Skip to content

Commit

Permalink
test(*): generating more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdinev committed Nov 12, 2023
1 parent 2d6353a commit 45b2b6a
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 100 deletions.
4 changes: 2 additions & 2 deletions projects/bellumgens/src/app/pipes/strat-filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Pipe, PipeTransform } from '@angular/core';
import { AllCSGOMaps, CSGOMapPool, CSGOStrategy } from '../../../../common/src/public_api';
import { ACTIVE_DUTY, CSGOActiveDutyMap, CSGOStrategy } from '../../../../common/src/public_api';

@Pipe({
name: 'stratFilter',
standalone: true
})
export class StratFilterPipe implements PipeTransform {

private maps: CSGOMapPool [] = AllCSGOMaps;
private maps: CSGOActiveDutyMap [] = ACTIVE_DUTY;

public transform(strats: CSGOStrategy [], viewAll: boolean = true, _?: number): CSGOStrategy [] {
if (strats && !viewAll) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, EventEmitter, Output } from '@angular/core';
import { ACTIVE_DUTY, CSGOActiveDutyDescriptor, CSGOMapPool } from '../../../../../common/src/public_api';
import { ACTIVE_DUTY, CSGOMapPool } from '../../../../../common/src/public_api';
import { ActiveDutyMapsPipe } from '../../../../../common/src/lib/pipes/active-duty-maps.pipe';
import { FormsModule } from '@angular/forms';
import { IgxCardModule, IgxCheckboxModule } from '@infragistics/igniteui-angular';
Expand Down Expand Up @@ -36,15 +36,15 @@ export class MapPoolComponent {
public readOnly: boolean;

@Output()
public update = new EventEmitter<CSGOActiveDutyDescriptor>();
public update = new EventEmitter<CSGOMapPool>();

public maps = structuredClone(ACTIVE_DUTY);

private _maps: CSGOMapPool [];

constructor() { }

public mapChange(map: CSGOActiveDutyDescriptor) {
public mapChange(map: CSGOMapPool) {
this.update.emit(map);
}

Expand Down
13 changes: 4 additions & 9 deletions projects/bellumgens/src/app/player-section/player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
ApplicationUser,
CSGOTeam,
CSGOMapPool,
ALL_ROLES,
CSGOActiveDutyDescriptor
ALL_ROLES
} from '../../../../common/src/public_api';

import { BaseComponent } from '../base/base.component';
Expand Down Expand Up @@ -116,13 +115,9 @@ export class PlayerComponent extends BaseComponent {
this.apiService.setSecondaryRole(this.roles.find(r => r.id === value)).subscribe();
}

public mapChange(args: CSGOActiveDutyDescriptor) {
const map: CSGOMapPool = {
mapId: args.mapId,
isPlayed: args.isPlayed,
userId: this.authUser.id
}
this.apiService.setMapPool(map).subscribe();
public mapChange(args: CSGOMapPool) {
args.userId = this.authUser.id;
this.apiService.setMapPool(args).subscribe();
}

public inviteToTeam(args: ISelectionEventArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
NEW_EMPTY_STRAT,
CSGOTeam,
ApplicationUser,
CSGOActiveDutyDescriptor,
CSGOActiveDutyMap,
ACTIVE_DUTY,
ApiStrategiesService
} from '../../../../../common/src/public_api';
Expand Down Expand Up @@ -33,7 +33,7 @@ export class NewStrategyComponent {

public newStrategy: CSGOStrategy = Object.assign({}, NEW_EMPTY_STRAT);
public videoId: string;
public mapList: CSGOActiveDutyDescriptor [] = ACTIVE_DUTY;
public mapList: CSGOActiveDutyMap [] = ACTIVE_DUTY;
public selectedMap = this.mapList[0];
public title = 'Add a new team strategy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[selected]="map.isPlayed"
[selectable]="true"
(selectedChanging)="changeMaps($event, map)">
{{ map.mapId | csgomapname }}
{{ map.map }}
</igx-chip>
</igx-chips-area>
<igx-select [(ngModel)]="order" class="order-by">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { ActivatedRoute, RouterLink } from '@angular/router';
import {
BellumgensApiService,
CSGOStrategy, VoteDirection,
CSGOMapPool, AllCSGOMaps,
CSGOTeam,
LoginService,
ApplicationUser,
GLOBAL_OVERLAY_SETTINGS, StratOrder, StratOrderBy,
SocialMediaStrategyService,
ApiSearchService,
ApiStrategiesService,
CommunicationService
CommunicationService,
CSGOActiveDutyMap,
ACTIVE_DUTY
} from '../../../../common/src/public_api';
import { IChipSelectEventArgs, IgxButtonModule, IgxRippleModule, IgxChipsModule, IgxSelectModule, IgxInputGroupModule, IgxCardModule, IgxIconModule, IgxToggleModule, IgxBadgeModule, IgxDropDownModule, IgxAvatarModule } from '@infragistics/igniteui-angular';
import { SafeResourceUrl } from '@angular/platform-browser';
Expand Down Expand Up @@ -74,7 +75,7 @@ export class StrategiesComponent {
public isEditor: boolean = null;

public strats: CSGOStrategy [];
public maps: CSGOMapPool [] = AllCSGOMaps;
public maps: CSGOActiveDutyMap [] = ACTIVE_DUTY;
public team: CSGOTeam;
public authUser: ApplicationUser;
public sanitizedUrl: SafeResourceUrl;
Expand Down Expand Up @@ -147,7 +148,7 @@ export class StrategiesComponent {
this.authManager.emitOpenLogin();
}

public changeMaps(event: IChipSelectEventArgs, args: CSGOMapPool) {
public changeMaps(event: IChipSelectEventArgs, args: CSGOActiveDutyMap) {
if (event.originalEvent) {
this.maps.find(m => m.mapId === args.mapId).isPlayed = event.selected;
this.pipeTrigger++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, ViewChild, ElementRef, OnDestroy } from '@angular/core';
import {
CSGOActiveDutyDescriptor,
CSGOActiveDutyMap,
ACTIVE_DUTY,
CSGOMap,
StrategyEditor,
Expand Down Expand Up @@ -29,7 +29,7 @@ import { NgIf, NgFor, NgClass } from '@angular/common';
export class StrategyEditorComponent implements OnInit, OnDestroy {
@ViewChild('board', { static: true }) public canvas: ElementRef;

public maps: CSGOActiveDutyDescriptor [] = ACTIVE_DUTY;
public maps: CSGOActiveDutyMap [] = ACTIVE_DUTY;
public team: CSGOTeam;
public teammembers: TeamMember [];
public newStrategy: CSGOStrategy;
Expand All @@ -44,7 +44,7 @@ export class StrategyEditorComponent implements OnInit, OnDestroy {
public saveInProgress = false;
public changes = false;

private _activeMap: CSGOActiveDutyDescriptor;
private _activeMap: CSGOActiveDutyMap;
private _drag = false;
private _coordinates: PointCoordinate = {
x: 0,
Expand All @@ -57,7 +57,7 @@ export class StrategyEditorComponent implements OnInit, OnDestroy {
return this._activeMap;
}

public set map(map: CSGOActiveDutyDescriptor) {
public set map(map: CSGOActiveDutyMap) {
this._activeMap = map;
if (!this.layers.length || (this.layers[0] as ImageLayer).src !== map.radar[0]) {
const layer = this.editor.createImageLayer('Map Radar');
Expand Down
6 changes: 3 additions & 3 deletions projects/common/src/lib/pipes/active-duty-maps.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActiveDutyMapsPipe } from './active-duty-maps.pipe';
import { CSGOMap, CSGOMapPool } from '../../public_api';
import { CSGOActiveDutyMap, CSGOMap, CSGOMapPool } from '../../public_api';

describe('ActiveDutyMapsPipe', () => {
let pipe: ActiveDutyMapsPipe;
Expand All @@ -23,7 +23,7 @@ describe('ActiveDutyMapsPipe', () => {
{ mapId: CSGOMap.Vertigo, active: true, isPlayed: true },
{ mapId: CSGOMap.Ancient, active: true, isPlayed: true },
];
expect(pipe.transform(maps, true)).toEqual(maps);
expect(pipe.transform(maps as CSGOActiveDutyMap [], true)).toEqual(maps as CSGOActiveDutyMap []);
});

it('should return only active duty maps when viewAll is false', () => {
Expand All @@ -44,7 +44,7 @@ describe('ActiveDutyMapsPipe', () => {
{ mapId: CSGOMap.Overpass, active: true, isPlayed: true },
{ mapId: CSGOMap.Train, active: true, isPlayed: true },
];
expect(pipe.transform(maps, false)).toEqual(expected);
expect(pipe.transform(maps as CSGOActiveDutyMap [], false)).toEqual(expected as CSGOActiveDutyMap []);
});

it('should return empty array when maps is null or undefined', () => {
Expand Down
4 changes: 2 additions & 2 deletions projects/common/src/lib/pipes/active-duty-maps.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Pipe, PipeTransform } from '@angular/core';
import { CSGOMapPool } from '../../public_api';
import { CSGOActiveDutyMap } from '../../public_api';

@Pipe({
name: 'activeDutyMaps',
standalone: true
})
export class ActiveDutyMapsPipe implements PipeTransform {

public transform(maps: CSGOMapPool [], viewAll: boolean = true, _?: number): CSGOMapPool [] {
public transform(maps: CSGOActiveDutyMap [], viewAll: boolean = true, _?: number): CSGOActiveDutyMap [] {
if (maps && !viewAll) {
return maps.filter(m => m.active);
} if (!maps) {
Expand Down
37 changes: 35 additions & 2 deletions projects/common/src/lib/pipes/sc2-map-name.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
import * as e from 'express';

Check failure on line 1 in projects/common/src/lib/pipes/sc2-map-name.pipe.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'e' is defined but never used

Check failure on line 1 in projects/common/src/lib/pipes/sc2-map-name.pipe.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'e' is defined but never used
import { SC2Map } from '../../public_api';
import { Sc2MapNamePipe } from './sc2-map-name.pipe';


describe('Sc2MapNamePipe', () => {
it('create an instance', () => {
const pipe = new Sc2MapNamePipe();
let pipe: Sc2MapNamePipe;

beforeEach(() => {
pipe = new Sc2MapNamePipe();
});

it('should create an instance', () => {
expect(pipe).toBeTruthy();
});

it('should return the name of the map', () => {
expect(pipe.transform(SC2Map.TritonLE)).toEqual('Triton LE');
expect(pipe.transform(SC2Map.OxideLE)).toEqual('Oxide LE');
expect(pipe.transform(SC2Map.EternalEmpireLE)).toEqual('Eternal Empire LE');
expect(pipe.transform(SC2Map.PurityAndIndustryLE)).toEqual('Purity and Industry LE');
expect(pipe.transform(SC2Map.EverDreamLE)).toEqual('Ever Dream LE');
expect(pipe.transform(SC2Map.SubmarineLE)).toEqual('Submarine LE');
expect(pipe.transform(SC2Map.DeathauraLE)).toEqual('Deathaura LE');
expect(pipe.transform(SC2Map.PillarsofGoldLE)).toEqual('Pillars of Gold LE');
expect(pipe.transform(SC2Map.ZenLE)).toEqual('Zen LE');
expect(pipe.transform(SC2Map.SimulacrumLE)).toEqual('Simulacrum LE');
expect(pipe.transform(SC2Map.NightshadeLE)).toEqual('Nightshade LE');
expect(pipe.transform(SC2Map.GoldenWallLE)).toEqual('Golden Wall LE');
expect(pipe.transform(SC2Map.EphemeronLE)).toEqual('Ephemeron LE');
expect(pipe.transform(SC2Map.WorldofSleepersLE)).toEqual('World of Sleepers LE');
expect(pipe.transform(SC2Map.IceAndChromeLE)).toEqual('Ice and Chrome LE');
expect(pipe.transform(SC2Map.RomanticideLE)).toEqual('Romanticide LE');
expect(pipe.transform(SC2Map.JagannathaLE)).toEqual('Jagannatha LE');
expect(pipe.transform(SC2Map.LightshadeLE)).toEqual('Lightshade LE');
});

it('should return an empty string if the map is undefined', () => {
expect(pipe.transform(undefined)).toEqual('');
});
});
2 changes: 1 addition & 1 deletion projects/common/src/lib/pipes/sc2-map-name.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SC2Map, SC2_MAPS } from '../../models/sc2maps';
export class Sc2MapNamePipe implements PipeTransform {

public transform(map: SC2Map): string {
return map !== undefined ? SC2_MAPS.find(m => m.id === map).map : '';
return SC2_MAPS.find(m => m.id === map)?.map || '';
}

}
37 changes: 36 additions & 1 deletion projects/common/src/lib/pipes/weekday.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import { DayOfWeek } from '../../public_api';
import { WeekdayPipe } from './weekday.pipe';


describe('WeekdayPipe', () => {
let pipe: WeekdayPipe;

beforeEach(() => {
pipe = new WeekdayPipe();
});

it('create an instance', () => {
const pipe = new WeekdayPipe();
expect(pipe).toBeTruthy();
});

it('transforms DayOfWeek.Sunday to "Sundays"', () => {
expect(pipe.transform(DayOfWeek.Sunday)).toBe('Sundays');
});

it('transforms DayOfWeek.Monday to "Mondays"', () => {
expect(pipe.transform(DayOfWeek.Monday)).toBe('Mondays');
});

it('transforms DayOfWeek.Tuesday to "Tuesdays"', () => {
expect(pipe.transform(DayOfWeek.Tuesday)).toBe('Tuesdays');
});

it('transforms DayOfWeek.Wednesday to "Wednesdays"', () => {
expect(pipe.transform(DayOfWeek.Wednesday)).toBe('Wednesdays');
});

it('transforms DayOfWeek.Thursday to "Thursdays"', () => {
expect(pipe.transform(DayOfWeek.Thursday)).toBe('Thursdays');
});

it('transforms DayOfWeek.Friday to "Fridays"', () => {
expect(pipe.transform(DayOfWeek.Friday)).toBe('Fridays');
});

it('transforms DayOfWeek.Saturday to "Saturdays"', () => {
expect(pipe.transform(DayOfWeek.Saturday)).toBe('Saturdays');
});
});
62 changes: 2 additions & 60 deletions projects/common/src/models/csgomaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,71 +20,13 @@ export interface CSGOMapPool {
teamId?: string;
}

export interface CSGOActiveDutyDescriptor extends CSGOMapPool {
export interface CSGOActiveDutyMap extends CSGOMapPool {
map: string;
image: string;
radar?: string [];
}

export const AllCSGOMaps: CSGOMapPool [] = [
{
mapId: CSGOMap.Cache,
isPlayed: true,
active: false
},
{
mapId: CSGOMap.Dust2,
isPlayed: true,
active: false
},
{
mapId: CSGOMap.Inferno,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Mirage,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Nuke,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Overpass,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Train,
isPlayed: true,
active: false
},
{
mapId: CSGOMap.Vertigo,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Cobblestone,
isPlayed: true,
active: false
},
{
mapId: CSGOMap.Ancient,
isPlayed: true,
active: true
},
{
mapId: CSGOMap.Anubis,
isPlayed: true,
active: true
}
];

export const ACTIVE_DUTY: CSGOActiveDutyDescriptor [] = [
export const ACTIVE_DUTY: CSGOActiveDutyMap [] = [
{
mapId: CSGOMap.Cache,
map: 'Cache',
Expand Down
4 changes: 2 additions & 2 deletions projects/common/src/models/sc2maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export enum SC2Map {
IceAndChromeLE
}

export interface SC2LadderDescriptor {
export interface SC2LadderMap {
id: SC2Map;
map: string;
image?: string;
active?: boolean;
}

export const SC2_MAPS: SC2LadderDescriptor [] = [{
export const SC2_MAPS: SC2LadderMap [] = [{
id: SC2Map.TritonLE,
map: 'Triton LE'
}, {
Expand Down
Loading

0 comments on commit 45b2b6a

Please sign in to comment.