Commit 808bb8b9 authored by Christopher Fullarton's avatar Christopher Fullarton

Fixes running local tests with the intellij runner

parent c02e6c45
......@@ -511,7 +511,7 @@
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"karmaConfig": "karma.conf.js",
"styles": [
"src/styles/styles.scss"
],
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/assets" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/src/assets/js" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="cookieconsent" level="application" />
<orderEntry type="library" name="all" level="application" />
</component>
</module>
\ No newline at end of file
......@@ -3,7 +3,7 @@
module.exports = function (config) {
config.set({
basePath: '',
basePath: 'src',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
......
......@@ -42,5 +42,9 @@ module.exports = function (config) {
autoWatch: false,
browsers: ['ChromeHeadless'],
singleRun: true,
angularCli: {
config: './angular.json',
environment: 'dev'
},
});
};
import { UserEntity } from '../../app/lib/entities/UserEntity';
export const UserMock: UserEntity = {
name: 'user-test',
gitlabToken: 'gitlab-token',
passwordHash: 'password-hash',
privateKey: 'private-key',
token: 'token',
userAuthorizations: [],
};
......@@ -3,7 +3,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
import { UserService } from '../../service/user/user.service';
import { QuizDetailsAdminComponent } from './quiz-details-admin.component';
describe('QuizDetailsAdminComponent', () => {
......
......@@ -3,10 +3,14 @@ import { PLATFORM_ID } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { JWT_OPTIONS, JwtHelperService, JwtModule } from '@auth0/angular-jwt';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
import { RxStompService } from '@stomp/ng2-stompjs';
import { Observable, of } from 'rxjs';
import { UserMock } from '../../../_mocks/_fixtures/user.mock';
import { TranslateServiceMock } from '../../../_mocks/TranslateServiceMock';
import { jwtOptionsFactory } from '../../lib/jwt.factory';
import { AdminApiService } from '../../service/api/admin/admin-api.service';
import { ConnectionMockService } from '../../service/connection/connection.mock.service';
import { ConnectionService } from '../../service/connection/connection.service';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
......@@ -29,6 +33,10 @@ import { UserAdminComponent } from './user-admin.component';
describe('UserAdminComponent', () => {
let component: UserAdminComponent;
let fixture: ComponentFixture<UserAdminComponent>;
const newUser = {
...UserMock,
name: 'new-user-name',
};
beforeEach(async(() => {
TestBed.configureTestingModule({
......@@ -42,8 +50,7 @@ describe('UserAdminComponent', () => {
}),
],
providers: [
RxStompService,
{
RxStompService, {
provide: TranslateService,
useClass: TranslateServiceMock,
}, I18nService, {
......@@ -60,8 +67,30 @@ describe('UserAdminComponent', () => {
useClass: ConnectionMockService,
}, SharedService, {
provide: UserService,
useValue: {},
}, JwtHelperService,
useValue: {
hashPassword: () => 'hashed-password',
},
}, JwtHelperService, {
provide: AdminApiService,
useValue: {
getAvailableUsers: () => of([UserMock]),
deleteUser: () => new Observable(subscriber => {
subscriber.next();
subscriber.complete();
}),
updateUser: () => new Observable(subscriber => {
subscriber.next();
subscriber.complete();
}),
},
}, {
provide: NgbModal,
useValue: {
open: () => (
{ result: new Promise(resolve => resolve(newUser)) }
),
},
},
],
declarations: [
UserAdminComponent,
......@@ -78,4 +107,25 @@ describe('UserAdminComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should check if a user is currently deleted', () => {
expect(component.isDeletingElem(UserMock)).toBeFalsy();
component['_deletingElements'].push(UserMock.name);
expect(component.isDeletingElem(UserMock)).toBeTruthy();
});
it('should delete a given user by name', () => {
component.deleteElem(UserMock);
expect(component.data).not.toContain(UserMock);
});
it('should show the adduser modal', async(() => done => {
component.showAddUserModal().then(() => done());
expect(component.data).toContain(newUser);
}));
it('should edit an existing user', async(() => done => {
component.editElem(UserMock).then(() => done());
expect(component.data).toContain(newUser);
}));
});
......@@ -51,8 +51,8 @@ export class UserAdminComponent implements OnInit {
});
}
public showAddUserModal(): void {
this.ngbModal.open(AddUserComponent).result.then(value => {
public showAddUserModal(): Promise<void> {
return this.ngbModal.open(AddUserComponent).result.then(value => {
value.passwordHash = this.userService.hashPassword(value.name, value.password);
delete value.password;
this.adminApiService.updateUser(value).subscribe(() => {
......@@ -61,14 +61,14 @@ export class UserAdminComponent implements OnInit {
}).catch(() => {});
}
public editElem(user: UserEntity): void {
public editElem(user: UserEntity): Promise<void> {
const ref = this.ngbModal.open(AddUserComponent);
ref.componentInstance.name = user.name;
ref.componentInstance.privateKey = user.privateKey;
ref.componentInstance.gitlabToken = user.gitlabToken;
ref.componentInstance.userAuthorizations = user.userAuthorizations;
ref.result.then(value => {
return ref.result.then(value => {
value.originalUser = user.name;
value.passwordHash = this.userService.hashPassword(value.name, value.password);
delete value.password;
......
Markdown is supported
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