-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from theImmortalCoders/dev
Release 0.2
- Loading branch information
Showing
63 changed files
with
1,686 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,7 @@ | |
"schematicCollections": [ | ||
"@angular-eslint/schematics", | ||
"@schematics/angular" | ||
] | ||
], | ||
"analytics": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 88 additions & 17 deletions
105
src/app/game/components/ai-socket-menu/ai-socket-menu.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,112 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { AiSocketMenuComponent } from './ai-socket-menu.component'; | ||
import { AiSocketService } from './services/ai-socket.service'; | ||
import { DebugModeMenuComponent } from './components/debug-mode-menu/debug-mode-menu.component'; | ||
import { DebugModePanelComponent } from './components/debug-mode-panel/debug-mode-panel.component'; | ||
import { TExchangeData } from 'app/game/models/exchange-data.type'; | ||
import { EventEmitter } from '@angular/core'; | ||
|
||
describe('AiSocketMenuComponent', () => { | ||
let component: AiSocketMenuComponent; | ||
let fixture: ComponentFixture<AiSocketMenuComponent>; | ||
let aiSocketServiceStub: Partial<AiSocketService>; | ||
let socketService: AiSocketService; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [AiSocketMenuComponent], | ||
beforeEach(waitForAsync(() => { | ||
aiSocketServiceStub = { | ||
getIsSocketConnected: jasmine | ||
.createSpy('getIsSocketConnected') | ||
.and.returnValue(false), | ||
getIsDataSendingActive: jasmine | ||
.createSpy('getIsDataSendingActive') | ||
.and.returnValue(false), | ||
getSocket: jasmine.createSpy('getSocket').and.returnValue({ | ||
close: jasmine.createSpy('close'), | ||
} as unknown as WebSocket), | ||
stopDataExchange: jasmine.createSpy('stopDataExchange'), | ||
startDataExchange: jasmine.createSpy('startDataExchange'), | ||
connect: jasmine | ||
.createSpy('connect') | ||
.and.callFake((_url, onOpen, _onMessage, _onClose) => { | ||
onOpen(); | ||
}), | ||
sendDataToSocket: jasmine.createSpy('sendDataToSocket'), | ||
}; | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [ | ||
AiSocketMenuComponent, | ||
DebugModeMenuComponent, | ||
DebugModePanelComponent, | ||
], | ||
providers: [{ provide: AiSocketService, useValue: aiSocketServiceStub }], | ||
}).compileComponents(); | ||
}); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AiSocketMenuComponent); | ||
component = fixture.componentInstance; | ||
socketService = TestBed.inject(AiSocketService); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create the component', () => { | ||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should initialize socket to null', () => { | ||
expect(component.socket).toBeNull(); | ||
it('should display "Connect" button when socket is not connected', () => { | ||
(socketService.getIsSocketConnected as jasmine.Spy).and.returnValue(false); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement; | ||
expect(button.textContent).toContain('Connect'); | ||
}); | ||
|
||
it('should display "Disconnect" button when socket is connected', () => { | ||
(socketService.getIsSocketConnected as jasmine.Spy).and.returnValue(true); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement; | ||
expect(button.textContent).toContain('Disconnect'); | ||
}); | ||
|
||
it('should call connect method when "Connect" button is clicked', () => { | ||
(socketService.getIsSocketConnected as jasmine.Spy).and.returnValue(false); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement; | ||
button.click(); | ||
expect(socketService.connect).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call disconnect method when "Disconnect" button is clicked', () => { | ||
(socketService.getIsSocketConnected as jasmine.Spy).and.returnValue(true); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement; | ||
button.click(); | ||
expect(socketService.getSocket()?.close).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should emit logData when logDataEmitter is called', () => { | ||
const logData = { message: 'Test log message' }; | ||
it('should emit logData when socket connects', () => { | ||
spyOn(component.logDataEmitter, 'emit'); | ||
component.logDataEmitter.emit(logData); | ||
expect(component.logDataEmitter.emit).toHaveBeenCalledWith(logData); | ||
(socketService.getIsSocketConnected as jasmine.Spy).and.returnValue(false); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement; | ||
button.click(); | ||
expect(component.logDataEmitter.emit).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should load recent phrases on init', () => { | ||
const phrases = ['ws://localhost1', 'ws://localhost2']; | ||
spyOn(localStorage, 'getItem').and.returnValue(JSON.stringify(phrases)); | ||
component.ngOnInit(); | ||
expect(component.recentPhrases).toEqual(phrases); | ||
}); | ||
|
||
it('should connect to the socket when connect is called', () => { | ||
const socketDomain = 'ws://localhost:8080/'; | ||
component.connect(socketDomain); | ||
expect(component.socket).not.toBeNull(); | ||
expect(component.socket?.url).toBe(socketDomain); | ||
it('should toggle debug mode', () => { | ||
const debugMenu = fixture.debugElement.query( | ||
By.directive(DebugModeMenuComponent) | ||
); | ||
debugMenu.triggerEventHandler('debugModeEmitter', true); | ||
fixture.detectChanges(); | ||
expect(component.isDebugModeActive).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.