Merge branch 'tests'
This commit is contained in:
commit
cfceee3551
|
@ -1,32 +1,36 @@
|
||||||
// Karma configuration file, see link for more information
|
// Karma configuration file, see link for more information
|
||||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||||
|
|
||||||
module.exports = function (config) {
|
const process = require('process');
|
||||||
config.set({
|
process.env.CHROME_BIN = require('puppeteer').executablePath();
|
||||||
basePath: "",
|
|
||||||
frameworks: ["jasmine", "@angular-devkit/build-angular"],
|
module.exports = function (config) {
|
||||||
plugins: [
|
config.set({
|
||||||
require("karma-jasmine"),
|
basePath: '',
|
||||||
require("karma-chrome-launcher"),
|
files: ['src/assets/env.js'],
|
||||||
require("karma-jasmine-html-reporter"),
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||||
require("karma-coverage-istanbul-reporter"),
|
plugins: [
|
||||||
require("@angular-devkit/build-angular/plugins/karma"),
|
require('karma-jasmine'),
|
||||||
],
|
require('karma-chrome-launcher'),
|
||||||
client: {
|
require('karma-jasmine-html-reporter'),
|
||||||
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
require('karma-coverage-istanbul-reporter'),
|
||||||
},
|
require('karma-spec-reporter'),
|
||||||
coverageIstanbulReporter: {
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
dir: require("path").join(__dirname, "./coverage/frontend"),
|
],
|
||||||
reports: ["html", "lcovonly", "text-summary"],
|
client: {
|
||||||
fixWebpackSourcePaths: true,
|
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
reporters: ["progress", "kjhtml"],
|
coverageIstanbulReporter: {
|
||||||
port: 9876,
|
dir: require("path").join(__dirname, "./coverage/frontend"),
|
||||||
colors: true,
|
reports: ["html", "lcovonly", "text-summary"],
|
||||||
logLevel: config.LOG_INFO,
|
fixWebpackSourcePaths: true,
|
||||||
autoWatch: true,
|
},
|
||||||
browsers: ["Chrome"],
|
reporters: ['progress', 'kjhtml', 'spec'],
|
||||||
singleRun: false,
|
port: 9876,
|
||||||
restartOnFileChange: true,
|
colors: true,
|
||||||
});
|
logLevel: config.LOG_INFO,
|
||||||
};
|
autoWatch: true,
|
||||||
|
browsers: ['ChromeHeadless'],
|
||||||
|
singleRun: true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
122
package.json
122
package.json
|
@ -1,60 +1,62 @@
|
||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e"
|
"e2e": "ng e2e"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "~9.1.9",
|
"@angular/animations": "~9.1.9",
|
||||||
"@angular/common": "~9.1.9",
|
"@angular/common": "~9.1.9",
|
||||||
"@angular/compiler": "~9.1.9",
|
"@angular/compiler": "~9.1.9",
|
||||||
"@angular/core": "~9.1.9",
|
"@angular/core": "~9.1.9",
|
||||||
"@angular/forms": "~9.1.9",
|
"@angular/forms": "~9.1.9",
|
||||||
"@angular/localize": "~9.1.9",
|
"@angular/localize": "~9.1.9",
|
||||||
"@angular/platform-browser": "~9.1.9",
|
"@angular/platform-browser": "~9.1.9",
|
||||||
"@angular/platform-browser-dynamic": "~9.1.9",
|
"@angular/platform-browser-dynamic": "~9.1.9",
|
||||||
"@angular/router": "~9.1.9",
|
"@angular/router": "~9.1.9",
|
||||||
"@ng-bootstrap/ng-bootstrap": "^6.0.0",
|
"@ng-bootstrap/ng-bootstrap": "^6.0.0",
|
||||||
"bootstrap": "^4.4.0",
|
"bootstrap": "^4.4.0",
|
||||||
"chart.js": "^2.9.3",
|
"chart.js": "^2.9.3",
|
||||||
"component": "^1.1.0",
|
"component": "^1.1.0",
|
||||||
"rxjs": "~6.5.4",
|
"rxjs": "~6.5.4",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
"zone.js": "~0.10.2"
|
"zone.js": "~0.10.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "~0.901.7",
|
"@angular-devkit/build-angular": "~0.901.7",
|
||||||
"@angular/cli": "~9.1.7",
|
"@angular/cli": "~9.1.7",
|
||||||
"@angular/compiler-cli": "~9.1.9",
|
"@angular/compiler-cli": "~9.1.9",
|
||||||
"@types/jasmine": "~3.5.0",
|
"@types/jasmine": "~3.5.0",
|
||||||
"@types/jasminewd2": "~2.0.3",
|
"@types/jasminewd2": "~2.0.3",
|
||||||
"@types/node": "^12.11.1",
|
"@types/node": "^12.11.1",
|
||||||
"codelyzer": "^5.1.2",
|
"codelyzer": "^5.1.2",
|
||||||
"jasmine-core": "~3.5.0",
|
"jasmine-core": "~3.5.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~5.0.0",
|
"karma": "~5.0.0",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
"karma-coverage-istanbul-reporter": "~2.1.0",
|
"karma-coverage-istanbul-reporter": "~2.1.0",
|
||||||
"karma-jasmine": "~3.0.1",
|
"karma-jasmine": "~3.0.1",
|
||||||
"karma-jasmine-html-reporter": "^1.4.2",
|
"karma-jasmine-html-reporter": "^1.4.2",
|
||||||
"prettier": "2.0.5",
|
"prettier": "2.0.5",
|
||||||
"protractor": "~7.0.0",
|
"karma-spec-reporter": "0.0.32",
|
||||||
"ts-node": "~8.3.0",
|
"protractor": "~7.0.0",
|
||||||
"tslint": "~6.1.0",
|
"puppeteer": "^5.1.0",
|
||||||
"typescript": "~3.8.3"
|
"ts-node": "~8.3.0",
|
||||||
},
|
"tslint": "~6.1.0",
|
||||||
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.7.",
|
"typescript": "~3.8.3"
|
||||||
"main": "karma.conf.js",
|
},
|
||||||
"repository": {
|
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.7.",
|
||||||
"type": "git",
|
"main": "karma.conf.js",
|
||||||
"url": "https://git.informatik.fh-nuernberg.de/scrum-taskboard/frontend.git"
|
"repository": {
|
||||||
},
|
"type": "git",
|
||||||
"author": "",
|
"url": "https://git.informatik.fh-nuernberg.de/scrum-taskboard/frontend.git"
|
||||||
"license": "ISC"
|
},
|
||||||
}
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
|
|
|
@ -1,33 +1,29 @@
|
||||||
import { TestBed, async } from '@angular/core/testing';
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [RouterTestingModule],
|
imports: [
|
||||||
declarations: [AppComponent],
|
RouterTestingModule,
|
||||||
}).compileComponents();
|
],
|
||||||
}));
|
declarations: [
|
||||||
|
AppComponent,
|
||||||
it('should create the app', () => {
|
],
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
}).compileComponents();
|
||||||
const app = fixture.debugElement.componentInstance;
|
}));
|
||||||
expect(app).toBeTruthy();
|
|
||||||
});
|
it('should create the app', () => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
it(`should have as title 'frontend'`, () => {
|
const app = fixture.debugElement.componentInstance;
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
expect(app).toBeTruthy();
|
||||||
const app = fixture.debugElement.componentInstance;
|
});
|
||||||
expect(app.title).toEqual('frontend');
|
|
||||||
});
|
it('should render router-outlet', () => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
it('should render title', () => {
|
fixture.detectChanges();
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const compiled = fixture.debugElement.nativeElement;
|
||||||
fixture.detectChanges();
|
expect(compiled.querySelector('router-outlet').textContent).toBeDefined();
|
||||||
const compiled = fixture.debugElement.nativeElement;
|
});
|
||||||
expect(compiled.querySelector('.content span').textContent).toContain(
|
});
|
||||||
'frontend app is running!'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BacklogComponent } from './backlog.component';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
|
||||||
|
describe('BacklogComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
BacklogComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(BacklogComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { DashboardComponent } from './dashboard.component';
|
||||||
|
|
||||||
|
describe('DashboardComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
DashboardComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(DashboardComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse dates correctly', () => {
|
||||||
|
const fixture = TestBed.createComponent(DashboardComponent);
|
||||||
|
const app = fixture.componentInstance;
|
||||||
|
expect(app.toDateString('2020-07-01T14:30:20')).toEqual('1.7.2020');
|
||||||
|
expect(app.toDateString('2020-11-23T07:30:20')).toEqual('23.11.2020');
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { SprintFormComponent } from './sprint-form.component';
|
||||||
|
|
||||||
|
describe('SprintFormComponent', () => {
|
||||||
|
let component: SprintFormComponent;
|
||||||
|
let fixture: ComponentFixture<SprintFormComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
HttpClientModule,
|
||||||
|
NgbModule,
|
||||||
|
],
|
||||||
|
declarations: [ SprintFormComponent ],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
NgbActiveModal,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SprintFormComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { SprintTableComponent } from './sprint-table.component';
|
||||||
|
|
||||||
|
describe('SprintTableComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
SprintTableComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(SprintTableComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { TaskTableComponent } from './task-table.component';
|
||||||
|
|
||||||
|
describe('TaskTableComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
TaskTableComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(TaskTableComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BackendService } from '../../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { UserstoryTableComponent } from './userstory-table.component';
|
||||||
|
|
||||||
|
describe('UserstoryTableComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
UserstoryTableComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(UserstoryTableComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,24 +1,36 @@
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { TaskFormComponent } from './task-form.component';
|
import { TaskFormComponent } from './task-form.component';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
describe('TaskFormComponent', () => {
|
import { BackendService } from '../../services/backend.service';
|
||||||
let component: TaskFormComponent;
|
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
let fixture: ComponentFixture<TaskFormComponent>;
|
|
||||||
|
describe('TaskFormComponent', () => {
|
||||||
beforeEach(async(() => {
|
let component: TaskFormComponent;
|
||||||
TestBed.configureTestingModule({
|
let fixture: ComponentFixture<TaskFormComponent>;
|
||||||
declarations: [TaskFormComponent],
|
|
||||||
}).compileComponents();
|
beforeEach(async(() => {
|
||||||
}));
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
beforeEach(() => {
|
HttpClientModule,
|
||||||
fixture = TestBed.createComponent(TaskFormComponent);
|
NgbModule,
|
||||||
component = fixture.componentInstance;
|
],
|
||||||
fixture.detectChanges();
|
declarations: [TaskFormComponent],
|
||||||
});
|
providers: [
|
||||||
|
BackendService,
|
||||||
it('should create', () => {
|
NgbActiveModal,
|
||||||
expect(component).toBeTruthy();
|
]
|
||||||
});
|
})
|
||||||
});
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(TaskFormComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { UserstoryFormComponent } from './userstory-form.component';
|
||||||
|
|
||||||
|
describe('UserstoryFormComponent', () => {
|
||||||
|
let component: UserstoryFormComponent;
|
||||||
|
let fixture: ComponentFixture<UserstoryFormComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
HttpClientModule,
|
||||||
|
NgbModule,
|
||||||
|
],
|
||||||
|
declarations: [ UserstoryFormComponent ],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
NgbActiveModal,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(UserstoryFormComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { BackendService } from '../../services/backend.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { UserstoryInnerTableComponent } from './userstory-inner-table.component';
|
||||||
|
|
||||||
|
describe('UserstoryInnerTableComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
UserstoryInnerTableComponent,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
BackendService,
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the component', () => {
|
||||||
|
const fixture = TestBed.createComponent(UserstoryInnerTableComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { sortByDateAscending, sortByNumberAscending, sortByStringAscending } from './sorting.service';
|
||||||
|
|
||||||
|
describe('SortingService', () => {
|
||||||
|
|
||||||
|
it('should sort correctly by number', () => {
|
||||||
|
const items = [7, 3, 2, 6, 4, 8, 0];
|
||||||
|
sortByNumberAscending(items, x => x);
|
||||||
|
expect(items).toEqual([0, 2, 3, 4, 6, 7, 8]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort strings by length correctly', () => {
|
||||||
|
const items = ['aaaaa', 'a', 'aaa'];
|
||||||
|
sortByNumberAscending(items, x => x.length);
|
||||||
|
expect(items).toEqual(['a', 'aaa', 'aaaaa']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort strings alphanumerically', () => {
|
||||||
|
const items = ['biz', 'bar', 'foo'];
|
||||||
|
sortByStringAscending(items, x => x);
|
||||||
|
expect(items).toEqual(['bar', 'biz', 'foo']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort dates correctly', () => {
|
||||||
|
const items = [
|
||||||
|
new Date(2020, 2, 10, 13, 30),
|
||||||
|
new Date(2020, 2, 10, 12, 30),
|
||||||
|
new Date(2019, 4, 4),
|
||||||
|
new Date(2020, 2, 11, 13, 30),
|
||||||
|
];
|
||||||
|
sortByDateAscending(items, x => x);
|
||||||
|
expect(items).toEqual([
|
||||||
|
new Date(2019, 4, 4),
|
||||||
|
new Date(2020, 2, 10, 12, 30),
|
||||||
|
new Date(2020, 2, 10, 13, 30),
|
||||||
|
new Date(2020, 2, 11, 13, 30),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -1,24 +1,24 @@
|
||||||
import { Priority } from './backend.service';
|
import { Priority } from './backend.service';
|
||||||
|
|
||||||
export function sortByNumberAscending<T>(items: T[], key: (T) => number) {
|
export function sortByNumberAscending<T>(items: T[], key: (T) => number) {
|
||||||
return items.sort((a, b) => key(a) - key(b));
|
return items.sort((a, b) => key(a) - key(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortByStringAscending<T>(items: T[], key: (T) => string) {
|
export function sortByStringAscending<T>(items: T[], key: (T) => string) {
|
||||||
return items.sort((a, b) => key(a).localeCompare(key(b)));
|
return items.sort((a, b) => key(a).localeCompare(key(b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortByDateAscending<T>(items: T[], key: (T) => Date) {
|
export function sortByDateAscending<T>(items: T[], key: (T) => Date) {
|
||||||
return items.sort((a, b) => <any>key(b) - <any>key(a));
|
return items.sort((a, b) => (key(a) as any) - (key(b) as any));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNumberForPriority(priority: Priority): number {
|
export function getNumberForPriority(priority: Priority): number {
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
case Priority.High:
|
case Priority.High:
|
||||||
return 2;
|
return 2;
|
||||||
case Priority.Medium:
|
case Priority.Medium:
|
||||||
return 1;
|
return 1;
|
||||||
case Priority.Low:
|
case Priority.Low:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue