JAVA-12422 Renamed jhipster to jhipster-modules
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { browser, element, by, $ } from 'protractor';
|
||||
|
||||
describe('account', () => {
|
||||
|
||||
const username = element(by.id('username'));
|
||||
const password = element(by.id('password'));
|
||||
const accountMenu = element(by.id('account-menu'));
|
||||
const login = element(by.id('login'));
|
||||
const logout = element(by.id('logout'));
|
||||
|
||||
beforeAll(() => {
|
||||
browser.get('/');
|
||||
});
|
||||
|
||||
it('should fail to login with bad password', () => {
|
||||
const expect1 = /home.title/;
|
||||
element.all(by.css('h1')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
accountMenu.click();
|
||||
login.click();
|
||||
|
||||
username.sendKeys('admin');
|
||||
password.sendKeys('foo');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
|
||||
const expect2 = /login.messages.error.authentication/;
|
||||
element.all(by.css('.alert-danger')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should login successfully with admin account', () => {
|
||||
const expect1 = /login.title/;
|
||||
element.all(by.css('.modal-content h1')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
username.clear();
|
||||
username.sendKeys('admin');
|
||||
password.clear();
|
||||
password.sendKeys('admin');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
|
||||
browser.waitForAngular();
|
||||
|
||||
const expect2 = /home.logged.message/;
|
||||
element.all(by.css('.alert-success span')).getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to update settings', () => {
|
||||
accountMenu.click();
|
||||
element(by.css('[routerLink="settings"]')).click();
|
||||
|
||||
const expect1 = /settings.title/;
|
||||
element.all(by.css('h2')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
element(by.css('button[type=submit]')).click();
|
||||
|
||||
const expect2 = /settings.messages.success/;
|
||||
element.all(by.css('.alert-success')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to update password', () => {
|
||||
accountMenu.click();
|
||||
element(by.css('[routerLink="password"]')).click();
|
||||
|
||||
const expect1 = /password.title/;
|
||||
element.all(by.css('h2')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
password.sendKeys('newpassword');
|
||||
element(by.id('confirmPassword')).sendKeys('newpassword');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
|
||||
const expect2 = /password.messages.success/;
|
||||
element.all(by.css('.alert-success')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect2);
|
||||
});
|
||||
accountMenu.click();
|
||||
logout.click();
|
||||
|
||||
accountMenu.click();
|
||||
login.click();
|
||||
|
||||
username.sendKeys('admin');
|
||||
password.sendKeys('newpassword');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
|
||||
accountMenu.click();
|
||||
element(by.css('[routerLink="password"]')).click();
|
||||
// change back to default
|
||||
password.clear();
|
||||
password.sendKeys('admin');
|
||||
element(by.id('confirmPassword')).clear();
|
||||
element(by.id('confirmPassword')).sendKeys('admin');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
accountMenu.click();
|
||||
logout.click();
|
||||
});
|
||||
});
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import { browser, element, by, $ } from 'protractor';
|
||||
|
||||
describe('administration', () => {
|
||||
|
||||
const username = element(by.id('username'));
|
||||
const password = element(by.id('password'));
|
||||
const accountMenu = element(by.id('account-menu'));
|
||||
const adminMenu = element(by.id('admin-menu'));
|
||||
const login = element(by.id('login'));
|
||||
const logout = element(by.id('logout'));
|
||||
|
||||
beforeAll(() => {
|
||||
browser.get('/');
|
||||
|
||||
accountMenu.click();
|
||||
login.click();
|
||||
|
||||
username.sendKeys('admin');
|
||||
password.sendKeys('admin');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
browser.waitForAngular();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
adminMenu.click();
|
||||
});
|
||||
|
||||
it('should load user management', () => {
|
||||
element(by.css('[routerLink="user-management"]')).click();
|
||||
const expect1 = /userManagement.home.title/;
|
||||
element.all(by.css('h2 span')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load metrics', () => {
|
||||
element(by.css('[routerLink="jhi-metrics"]')).click();
|
||||
const expect1 = /metrics.title/;
|
||||
element.all(by.css('h2 span')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load health', () => {
|
||||
element(by.css('[routerLink="jhi-health"]')).click();
|
||||
const expect1 = /health.title/;
|
||||
element.all(by.css('h2 span')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load configuration', () => {
|
||||
element(by.css('[routerLink="jhi-configuration"]')).click();
|
||||
const expect1 = /configuration.title/;
|
||||
element.all(by.css('h2')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load audits', () => {
|
||||
element(by.css('[routerLink="audits"]')).click();
|
||||
const expect1 = /audits.title/;
|
||||
element.all(by.css('h2')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load logs', () => {
|
||||
element(by.css('[routerLink="logs"]')).click();
|
||||
const expect1 = /logs.title/;
|
||||
element.all(by.css('h2')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expect1);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
accountMenu.click();
|
||||
logout.click();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { browser, element, by, $ } from 'protractor';
|
||||
|
||||
describe('Comment e2e test', () => {
|
||||
|
||||
const username = element(by.id('username'));
|
||||
const password = element(by.id('password'));
|
||||
const entityMenu = element(by.id('entity-menu'));
|
||||
const accountMenu = element(by.id('account-menu'));
|
||||
const login = element(by.id('login'));
|
||||
const logout = element(by.id('logout'));
|
||||
|
||||
beforeAll(() => {
|
||||
browser.get('/');
|
||||
|
||||
accountMenu.click();
|
||||
login.click();
|
||||
|
||||
username.sendKeys('admin');
|
||||
password.sendKeys('admin');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
browser.waitForAngular();
|
||||
});
|
||||
|
||||
it('should load Comments', () => {
|
||||
entityMenu.click();
|
||||
element.all(by.css('[routerLink="comment"]')).first().click().then(() => {
|
||||
const expectVal = /baeldungApp.comment.home.title/;
|
||||
element.all(by.css('h2 span')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expectVal);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should load create Comment dialog', function () {
|
||||
element(by.css('button.create-comment')).click().then(() => {
|
||||
const expectVal = /baeldungApp.comment.home.createOrEditLabel/;
|
||||
element.all(by.css('h4.modal-title')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expectVal);
|
||||
});
|
||||
|
||||
element(by.css('button.close')).click();
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
accountMenu.click();
|
||||
logout.click();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { browser, element, by, $ } from 'protractor';
|
||||
|
||||
describe('Post e2e test', () => {
|
||||
|
||||
const username = element(by.id('username'));
|
||||
const password = element(by.id('password'));
|
||||
const entityMenu = element(by.id('entity-menu'));
|
||||
const accountMenu = element(by.id('account-menu'));
|
||||
const login = element(by.id('login'));
|
||||
const logout = element(by.id('logout'));
|
||||
|
||||
beforeAll(() => {
|
||||
browser.get('/');
|
||||
|
||||
accountMenu.click();
|
||||
login.click();
|
||||
|
||||
username.sendKeys('admin');
|
||||
password.sendKeys('admin');
|
||||
element(by.css('button[type=submit]')).click();
|
||||
browser.waitForAngular();
|
||||
});
|
||||
|
||||
it('should load Posts', () => {
|
||||
entityMenu.click();
|
||||
element.all(by.css('[routerLink="post"]')).first().click().then(() => {
|
||||
const expectVal = /baeldungApp.post.home.title/;
|
||||
element.all(by.css('h2 span')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expectVal);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should load create Post dialog', function () {
|
||||
element(by.css('button.create-post')).click().then(() => {
|
||||
const expectVal = /baeldungApp.post.home.createOrEditLabel/;
|
||||
element.all(by.css('h4.modal-title')).first().getAttribute('jhiTranslate').then((value) => {
|
||||
expect(value).toMatch(expectVal);
|
||||
});
|
||||
|
||||
element(by.css('button.close')).click();
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
accountMenu.click();
|
||||
logout.click();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const WATCH = process.argv.indexOf('--watch') > -1;
|
||||
const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin");
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
|
||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||
basePath: './',
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['jasmine', 'intl-shim'],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'spec/entry.ts'
|
||||
],
|
||||
|
||||
|
||||
// list of files to exclude
|
||||
exclude: ['e2e/**'],
|
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
'spec/entry.ts': ['webpack', 'sourcemap']
|
||||
},
|
||||
|
||||
webpack: {
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/, enforce: 'pre', loader: 'tslint-loader', exclude: /(test|node_modules)/
|
||||
},
|
||||
{
|
||||
test: /\.ts$/,
|
||||
loaders: ['awesome-typescript-loader', 'angular2-template-loader?keepUrl=true'],
|
||||
exclude: /node_modules/
|
||||
},
|
||||
{
|
||||
test: /\.(html|css)$/,
|
||||
loader: 'raw-loader',
|
||||
exclude: /\.async\.(html|css)$/
|
||||
},
|
||||
{
|
||||
test: /\.async\.(html|css)$/,
|
||||
loaders: ['file?name=[name].[hash].[ext]', 'extract']
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: ['to-string-loader', 'css-loader', 'sass-loader']
|
||||
},
|
||||
{
|
||||
test: /src\/main\/webapp\/.+\.ts$/,
|
||||
enforce: 'post',
|
||||
exclude: /(test|node_modules)/,
|
||||
loader: 'sourcemap-istanbul-instrumenter-loader?force-sourcemap=true'
|
||||
}]
|
||||
},
|
||||
devtool: 'inline-source-map',
|
||||
plugins: [
|
||||
new webpack.ContextReplacementPlugin(
|
||||
// The (\\|\/) piece accounts for path separators in *nix and Windows
|
||||
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
|
||||
root('./src') // location of your src
|
||||
),
|
||||
new LoaderOptionsPlugin({
|
||||
options: {
|
||||
tslint: {
|
||||
emitErrors: !WATCH,
|
||||
failOnHint: false
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
},
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['dots', 'junit', 'progress', 'karma-remap-istanbul'],
|
||||
|
||||
junitReporter: {
|
||||
outputFile: '../../../../target/test-results/karma/TESTS-results.xml'
|
||||
},
|
||||
|
||||
remapIstanbulReporter: {
|
||||
reports: { // eslint-disable-line
|
||||
'html': 'target/test-results/coverage',
|
||||
'text-summary': null
|
||||
}
|
||||
},
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: WATCH,
|
||||
|
||||
// start these browsers
|
||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||
browsers: ['PhantomJS'],
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: !WATCH
|
||||
});
|
||||
};
|
||||
|
||||
function root(__path) {
|
||||
return path.join(__dirname, __path);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
var HtmlScreenshotReporter = require("protractor-jasmine2-screenshot-reporter");
|
||||
var JasmineReporters = require('jasmine-reporters');
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 20000,
|
||||
|
||||
specs: [
|
||||
'./e2e/account/*.spec.ts',
|
||||
'./e2e/admin/*.spec.ts',
|
||||
'./e2e/entities/*.spec.ts'
|
||||
],
|
||||
|
||||
capabilities: {
|
||||
'browserName': 'chrome',
|
||||
'phantomjs.binary.path': require('phantomjs-prebuilt').path,
|
||||
'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
|
||||
},
|
||||
|
||||
directConnect: true,
|
||||
|
||||
baseUrl: 'http://localhost:8080/',
|
||||
|
||||
framework: 'jasmine2',
|
||||
|
||||
jasmineNodeOpts: {
|
||||
showColors: true,
|
||||
defaultTimeoutInterval: 30000
|
||||
},
|
||||
|
||||
beforeLaunch: function() {
|
||||
require('ts-node').register({
|
||||
project: ''
|
||||
});
|
||||
},
|
||||
|
||||
onPrepare: function() {
|
||||
browser.driver.manage().window().setSize(1280, 1024);
|
||||
jasmine.getEnv().addReporter(new JasmineReporters.JUnitXmlReporter({
|
||||
savePath: 'target/reports/e2e',
|
||||
consolidateAll: false
|
||||
}));
|
||||
jasmine.getEnv().addReporter(new HtmlScreenshotReporter({
|
||||
dest: "target/reports/e2e/screenshots"
|
||||
}));
|
||||
},
|
||||
|
||||
useAllAngular2AppRoots: true
|
||||
};
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
import { TestBed, async, tick, fakeAsync, inject } from '@angular/core/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { MockActivatedRoute } from '../../../helpers/mock-route.service';
|
||||
import { LoginModalService } from '../../../../../../main/webapp/app/shared';
|
||||
import { Activate } from '../../../../../../main/webapp/app/account/activate/activate.service';
|
||||
import { ActivateComponent } from '../../../../../../main/webapp/app/account/activate/activate.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('ActivateComponent', () => {
|
||||
|
||||
let comp: ActivateComponent;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [ActivateComponent],
|
||||
providers: [
|
||||
Activate,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({'key': 'ABC123'})
|
||||
},
|
||||
{
|
||||
provide: LoginModalService,
|
||||
useValue: null
|
||||
}
|
||||
]
|
||||
}).overrideComponent(ActivateComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let fixture = TestBed.createComponent(ActivateComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('calls activate.get with the key from params',
|
||||
inject([Activate],
|
||||
fakeAsync((service: Activate) => {
|
||||
spyOn(service, 'get').and.returnValue(Observable.of());
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(service.get).toHaveBeenCalledWith('ABC123');
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('should set set success to OK upon successful activation',
|
||||
inject([Activate],
|
||||
fakeAsync((service: Activate) => {
|
||||
spyOn(service, 'get').and.returnValue(Observable.of({}));
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(comp.error).toBe(null);
|
||||
expect(comp.success).toEqual('OK');
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('should set set error to ERROR upon activation failure',
|
||||
inject([Activate],
|
||||
fakeAsync((service: Activate) => {
|
||||
spyOn(service, 'get').and.returnValue(Observable.throw('ERROR'));
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(comp.error).toBe('ERROR');
|
||||
expect(comp.success).toEqual(null);
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { ComponentFixture, TestBed, inject } from '@angular/core/testing';
|
||||
import { Renderer, ElementRef } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { LoginModalService } from '../../../../../../../main/webapp/app/shared';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { BaeldungTestModule } from '../../../../test.module';
|
||||
import { PasswordResetFinishComponent } from '../../../../../../../main/webapp/app/account/password-reset/finish/password-reset-finish.component';
|
||||
import { PasswordResetFinish } from '../../../../../../../main/webapp/app/account/password-reset/finish/password-reset-finish.service';
|
||||
import { MockActivatedRoute } from '../../../../helpers/mock-route.service';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('PasswordResetFinishComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<PasswordResetFinishComponent>;
|
||||
let comp: PasswordResetFinishComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [PasswordResetFinishComponent],
|
||||
providers: [
|
||||
PasswordResetFinish,
|
||||
{
|
||||
provide: LoginModalService,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({'key': 'XYZPDQ'})
|
||||
},
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: {
|
||||
invokeElementMethod(renderElement: any, methodName: string, args?: any[]) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: new ElementRef(null)
|
||||
}
|
||||
]
|
||||
}).overrideComponent(PasswordResetFinishComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).createComponent(PasswordResetFinishComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should define its initial state', function () {
|
||||
comp.ngOnInit();
|
||||
|
||||
expect(comp.keyMissing).toBeFalsy();
|
||||
expect(comp.key).toEqual('XYZPDQ');
|
||||
expect(comp.resetAccount).toEqual({});
|
||||
});
|
||||
|
||||
it('sets focus after the view has been initialized',
|
||||
inject([ElementRef], (elementRef: ElementRef) => {
|
||||
let element = fixture.nativeElement;
|
||||
let node = {
|
||||
focus() {}
|
||||
};
|
||||
|
||||
elementRef.nativeElement = element;
|
||||
spyOn(element, 'querySelector').and.returnValue(node);
|
||||
spyOn(node, 'focus');
|
||||
|
||||
comp.ngAfterViewInit();
|
||||
|
||||
expect(element.querySelector).toHaveBeenCalledWith('#password');
|
||||
expect(node.focus).toHaveBeenCalled();
|
||||
})
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
import { ComponentFixture, TestBed, inject } from '@angular/core/testing';
|
||||
import { Renderer, ElementRef } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { BaeldungTestModule } from '../../../../test.module';
|
||||
import { PasswordResetInitComponent } from '../../../../../../../main/webapp/app/account/password-reset/init/password-reset-init.component';
|
||||
import { PasswordResetInit } from '../../../../../../../main/webapp/app/account/password-reset/init/password-reset-init.service';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('PasswordResetInitComponent', function () {
|
||||
let fixture: ComponentFixture<PasswordResetInitComponent>;
|
||||
let comp: PasswordResetInitComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [PasswordResetInitComponent],
|
||||
providers: [
|
||||
PasswordResetInit,
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: {
|
||||
invokeElementMethod(renderElement: any, methodName: string, args?: any[]) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: new ElementRef(null)
|
||||
}
|
||||
]
|
||||
}).overrideComponent(PasswordResetInitComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).createComponent(PasswordResetInitComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.ngOnInit();
|
||||
});
|
||||
|
||||
it('should define its initial state', function () {
|
||||
expect(comp.success).toBeUndefined();
|
||||
expect(comp.error).toBeUndefined();
|
||||
expect(comp.errorEmailNotExists).toBeUndefined();
|
||||
expect(comp.resetAccount).toEqual({});
|
||||
});
|
||||
|
||||
it('sets focus after the view has been initialized',
|
||||
inject([ElementRef], (elementRef: ElementRef) => {
|
||||
let element = fixture.nativeElement;
|
||||
let node = {
|
||||
focus() {}
|
||||
};
|
||||
|
||||
elementRef.nativeElement = element;
|
||||
spyOn(element, 'querySelector').and.returnValue(node);
|
||||
spyOn(node, 'focus');
|
||||
|
||||
comp.ngAfterViewInit();
|
||||
|
||||
expect(element.querySelector).toHaveBeenCalledWith('#email');
|
||||
expect(node.focus).toHaveBeenCalled();
|
||||
})
|
||||
);
|
||||
|
||||
it('notifies of success upon successful requestReset',
|
||||
inject([PasswordResetInit], (service: PasswordResetInit) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.of({}));
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toEqual('OK');
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toBeNull();
|
||||
})
|
||||
);
|
||||
|
||||
it('notifies of unknown email upon e-mail address not registered/400',
|
||||
inject([PasswordResetInit], (service: PasswordResetInit) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw({
|
||||
status: 400,
|
||||
data: 'e-mail address not registered'
|
||||
}));
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toEqual('ERROR');
|
||||
})
|
||||
);
|
||||
|
||||
it('notifies of error upon error response',
|
||||
inject([PasswordResetInit], (service: PasswordResetInit) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw({
|
||||
status: 503,
|
||||
data: 'something else'
|
||||
}));
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toBeNull();
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
})
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
|
||||
import { PasswordStrengthBarComponent } from '../../../../../../main/webapp/app/account/password/password-strength-bar.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('PasswordStrengthBarComponent', () => {
|
||||
|
||||
let comp: PasswordStrengthBarComponent;
|
||||
let fixture: ComponentFixture<PasswordStrengthBarComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PasswordStrengthBarComponent]
|
||||
}).overrideComponent(PasswordStrengthBarComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordStrengthBarComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('PasswordStrengthBarComponents', () => {
|
||||
it('should initialize with default values', () => {
|
||||
expect(comp.measureStrength('')).toBe(0);
|
||||
expect(comp.colors).toEqual(['#F00', '#F90', '#FF0', '#9F0', '#0F0']);
|
||||
expect(comp.getColor(0).idx).toBe(1);
|
||||
expect(comp.getColor(0).col).toBe(comp.colors[0]);
|
||||
});
|
||||
|
||||
it('should increase strength upon password value change', () => {
|
||||
expect(comp.measureStrength('')).toBe(0);
|
||||
expect(comp.measureStrength('aa')).toBeGreaterThanOrEqual(comp.measureStrength(''));
|
||||
expect(comp.measureStrength('aa^6')).toBeGreaterThanOrEqual(comp.measureStrength('aa'));
|
||||
expect(comp.measureStrength('Aa090(**)')).toBeGreaterThanOrEqual(comp.measureStrength('aa^6'));
|
||||
expect(comp.measureStrength('Aa090(**)+-07365')).toBeGreaterThanOrEqual(comp.measureStrength('Aa090(**)'));
|
||||
});
|
||||
|
||||
it('should change the color based on strength', () => {
|
||||
expect(comp.getColor(0).col).toBe(comp.colors[0]);
|
||||
expect(comp.getColor(11).col).toBe(comp.colors[1]);
|
||||
expect(comp.getColor(22).col).toBe(comp.colors[2]);
|
||||
expect(comp.getColor(33).col).toBe(comp.colors[3]);
|
||||
expect(comp.getColor(44).col).toBe(comp.colors[4]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { PasswordComponent } from '../../../../../../main/webapp/app/account/password/password.component';
|
||||
import { Password } from '../../../../../../main/webapp/app/account/password/password.service';
|
||||
import { Principal } from '../../../../../../main/webapp/app/shared/auth/principal.service';
|
||||
import { AccountService } from '../../../../../../main/webapp/app/shared/auth/account.service';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('PasswordComponent', () => {
|
||||
|
||||
let comp: PasswordComponent;
|
||||
let fixture: ComponentFixture<PasswordComponent>;
|
||||
let service: Password;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [PasswordComponent],
|
||||
providers: [
|
||||
Principal,
|
||||
AccountService,
|
||||
Password
|
||||
]
|
||||
}).overrideComponent(PasswordComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(Password);
|
||||
});
|
||||
|
||||
it('should show error if passwords do not match', () => {
|
||||
// GIVEN
|
||||
comp.password = 'password1';
|
||||
comp.confirmPassword = 'password2';
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBe('ERROR');
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBeNull();
|
||||
});
|
||||
|
||||
it('should call Auth.changePassword when passwords match', () => {
|
||||
// GIVEN
|
||||
spyOn(service, 'save').and.returnValue(Observable.of(true));
|
||||
comp.password = comp.confirmPassword = 'myPassword';
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(service.save).toHaveBeenCalledWith('myPassword');
|
||||
});
|
||||
|
||||
it('should set success to OK upon success', function() {
|
||||
// GIVEN
|
||||
spyOn(service, 'save').and.returnValue(Observable.of(true));
|
||||
comp.password = comp.confirmPassword = 'myPassword';
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBe('OK');
|
||||
});
|
||||
|
||||
it('should notify of error if change password fails', function() {
|
||||
// GIVEN
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw('ERROR'));
|
||||
comp.password = comp.confirmPassword = 'myPassword';
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBeNull();
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.error).toBe('ERROR');
|
||||
});
|
||||
});
|
||||
});
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
import { ComponentFixture, TestBed, async, inject, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { Renderer, ElementRef } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { MockLanguageService } from '../../../helpers/mock-language.service';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { LoginModalService } from '../../../../../../main/webapp/app/shared';
|
||||
import { Register } from '../../../../../../main/webapp/app/account/register/register.service';
|
||||
import { RegisterComponent } from '../../../../../../main/webapp/app/account/register/register.component';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('RegisterComponent', () => {
|
||||
let fixture: ComponentFixture<RegisterComponent>;
|
||||
let comp: RegisterComponent;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [RegisterComponent],
|
||||
providers: [
|
||||
Register,
|
||||
{
|
||||
provide: LoginModalService,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: null
|
||||
}
|
||||
]
|
||||
}).overrideComponent(RegisterComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RegisterComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.ngOnInit();
|
||||
});
|
||||
|
||||
it('should ensure the two passwords entered match', function () {
|
||||
comp.registerAccount.password = 'password';
|
||||
comp.confirmPassword = 'non-matching';
|
||||
|
||||
comp.register();
|
||||
|
||||
expect(comp.doNotMatch).toEqual('ERROR');
|
||||
});
|
||||
|
||||
it('should update success to OK after creating an account',
|
||||
inject([Register, JhiLanguageService],
|
||||
fakeAsync((service: Register, mockTranslate: MockLanguageService) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.of({}));
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith({
|
||||
password: 'password',
|
||||
langKey: 'en'
|
||||
});
|
||||
expect(comp.success).toEqual(true);
|
||||
expect(comp.registerAccount.langKey).toEqual('en');
|
||||
expect(mockTranslate.getCurrentSpy).toHaveBeenCalled();
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('should notify of user existence upon 400/login already in use',
|
||||
inject([Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw({
|
||||
status: 400,
|
||||
_body: 'login already in use'
|
||||
}));
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorUserExists).toEqual('ERROR');
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('should notify of email existence upon 400/e-mail address already in use',
|
||||
inject([Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw({
|
||||
status: 400,
|
||||
_body: 'e-mail address already in use'
|
||||
}));
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorEmailExists).toEqual('ERROR');
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('should notify of generic error',
|
||||
inject([Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(Observable.throw({
|
||||
status: 503
|
||||
}));
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { JhiLanguageHelper } from '../../../../../../main/webapp/app/shared';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { Principal, AccountService } from '../../../../../../main/webapp/app/shared';
|
||||
import { SettingsComponent } from '../../../../../../main/webapp/app/account/settings/settings.component';
|
||||
import { MockAccountService } from '../../../helpers/mock-account.service';
|
||||
import { MockPrincipal } from '../../../helpers/mock-principal.service';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('SettingsComponent', () => {
|
||||
|
||||
let comp: SettingsComponent;
|
||||
let fixture: ComponentFixture<SettingsComponent>;
|
||||
let mockAuth: MockAccountService;
|
||||
let mockPrincipal: MockPrincipal;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [SettingsComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: Principal,
|
||||
useClass: MockPrincipal
|
||||
},
|
||||
{
|
||||
provide: AccountService,
|
||||
useClass: MockAccountService
|
||||
},
|
||||
{
|
||||
provide: JhiLanguageHelper,
|
||||
useValue: null
|
||||
},
|
||||
]
|
||||
}).overrideComponent(SettingsComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SettingsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
mockAuth = fixture.debugElement.injector.get(AccountService);
|
||||
mockPrincipal = fixture.debugElement.injector.get(Principal);
|
||||
});
|
||||
|
||||
it('should send the current identity upon save', function () {
|
||||
// GIVEN
|
||||
let accountValues = {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
|
||||
activated: true,
|
||||
email: 'john.doe@mail.com',
|
||||
langKey: 'en',
|
||||
login: 'john'
|
||||
};
|
||||
mockPrincipal.setResponse(accountValues);
|
||||
|
||||
// WHEN
|
||||
comp.settingsAccount = accountValues;
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(mockPrincipal.identitySpy).toHaveBeenCalled();
|
||||
expect(mockAuth.saveSpy).toHaveBeenCalledWith(accountValues);
|
||||
expect(comp.settingsAccount).toEqual(accountValues);
|
||||
});
|
||||
|
||||
it('should notify of success upon successful save', function () {
|
||||
// GIVEN
|
||||
let accountValues = {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe'
|
||||
};
|
||||
mockPrincipal.setResponse(accountValues);
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBe('OK');
|
||||
});
|
||||
|
||||
it('should notify of error upon failed save', function () {
|
||||
// GIVEN
|
||||
mockAuth.saveSpy.and.returnValue(Observable.throw('ERROR'));
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
expect(comp.success).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { NgbPaginationConfig} from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ParseLinks } from 'ng-jhipster';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { PaginationConfig } from '../../../../../../main/webapp/app/blocks/config/uib-pagination.config'
|
||||
import { AuditsComponent } from '../../../../../../main/webapp/app/admin/audits/audits.component';
|
||||
import { AuditsService } from '../../../../../../main/webapp/app/admin/audits/audits.service';
|
||||
import { ITEMS_PER_PAGE } from '../../../../../../main/webapp/app/shared';
|
||||
|
||||
|
||||
function getDate(isToday= true){
|
||||
let date: Date = new Date();
|
||||
if (isToday) {
|
||||
// Today + 1 day - needed if the current day must be included
|
||||
date.setDate(date.getDate() + 1);
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||
}
|
||||
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
||||
}
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('AuditsComponent', () => {
|
||||
|
||||
let comp: AuditsComponent;
|
||||
let fixture: ComponentFixture<AuditsComponent>;
|
||||
let service: AuditsService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [AuditsComponent],
|
||||
providers: [
|
||||
AuditsService,
|
||||
NgbPaginationConfig,
|
||||
ParseLinks,
|
||||
PaginationConfig,
|
||||
DatePipe
|
||||
]
|
||||
})
|
||||
.overrideComponent(AuditsComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AuditsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(AuditsService);
|
||||
});
|
||||
|
||||
describe('today function ', () => {
|
||||
it('should set toDate to current date', () => {
|
||||
comp.today();
|
||||
expect(comp.toDate).toBe(getDate());
|
||||
});
|
||||
});
|
||||
|
||||
describe('previousMonth function ', () => {
|
||||
it('should set toDate to current date', () => {
|
||||
comp.previousMonth();
|
||||
expect(comp.fromDate).toBe(getDate(false));
|
||||
});
|
||||
});
|
||||
|
||||
describe('By default, on init', () => {
|
||||
it('should set all default values correctly', () => {
|
||||
fixture.detectChanges();
|
||||
expect(comp.toDate).toBe(getDate());
|
||||
expect(comp.fromDate).toBe(getDate(false));
|
||||
expect(comp.itemsPerPage).toBe(ITEMS_PER_PAGE);
|
||||
expect(comp.page).toBe(1);
|
||||
expect(comp.reverse).toBeFalsy();
|
||||
expect(comp.orderProp).toBe('timestamp');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { BaeldungTestModule } from '../../../test.module';
|
||||
import { JhiHealthCheckComponent } from '../../../../../../main/webapp/app/admin/health/health.component';
|
||||
import { JhiHealthService } from '../../../../../../main/webapp/app/admin/health/health.service';
|
||||
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('JhiHealthCheckComponent', () => {
|
||||
|
||||
let comp: JhiHealthCheckComponent;
|
||||
let fixture: ComponentFixture<JhiHealthCheckComponent>;
|
||||
let service: JhiHealthService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [BaeldungTestModule],
|
||||
declarations: [JhiHealthCheckComponent],
|
||||
providers: [
|
||||
JhiHealthService,
|
||||
{
|
||||
provide: NgbModal,
|
||||
useValue: null
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideComponent(JhiHealthCheckComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(JhiHealthCheckComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(JhiHealthService);
|
||||
});
|
||||
|
||||
describe('baseName and subSystemName', () => {
|
||||
it('should return the basename when it has no sub system', () => {
|
||||
expect(comp.baseName('base')).toBe('base');
|
||||
});
|
||||
|
||||
it('should return the basename when it has sub systems', () => {
|
||||
expect(comp.baseName('base.subsystem.system')).toBe('base');
|
||||
});
|
||||
|
||||
it('should return the sub system name', () => {
|
||||
expect(comp.subSystemName('subsystem')).toBe('');
|
||||
});
|
||||
|
||||
it('should return the subsystem when it has multiple keys', () => {
|
||||
expect(comp.subSystemName('subsystem.subsystem.system')).toBe(' - subsystem.system');
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformHealthData', () => {
|
||||
it('should flatten empty health data', () => {
|
||||
const data = {};
|
||||
const expected = [];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should flatten health data with no subsystems', () => {
|
||||
const data = {
|
||||
'status': 'UP',
|
||||
'db': {
|
||||
'status': 'UP',
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
},
|
||||
'mail': {
|
||||
'status': 'UP',
|
||||
'error': 'mail.a.b.c'
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
'name': 'db',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mail',
|
||||
'error': 'mail.a.b.c',
|
||||
'status': 'UP'
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has no additional information', () => {
|
||||
const data = {
|
||||
'status': 'UP',
|
||||
'db': {
|
||||
'status': 'UP',
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
},
|
||||
'mail': {
|
||||
'status': 'UP',
|
||||
'error': 'mail.a.b.c'
|
||||
},
|
||||
'system': {
|
||||
'status': 'DOWN',
|
||||
'subsystem1': {
|
||||
'status': 'UP',
|
||||
'property1': 'system.subsystem1.property1'
|
||||
},
|
||||
'subsystem2': {
|
||||
'status': 'DOWN',
|
||||
'error': 'system.subsystem1.error',
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
'name': 'db',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mail',
|
||||
'error': 'mail.a.b.c',
|
||||
'status': 'UP'
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem1',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'property1': 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem2',
|
||||
'error': 'system.subsystem1.error',
|
||||
'status': 'DOWN',
|
||||
'details': {
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has additional information', () => {
|
||||
const data = {
|
||||
'status': 'UP',
|
||||
'db': {
|
||||
'status': 'UP',
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
},
|
||||
'mail': {
|
||||
'status': 'UP',
|
||||
'error': 'mail.a.b.c'
|
||||
},
|
||||
'system': {
|
||||
'status': 'DOWN',
|
||||
'property1': 'system.property1',
|
||||
'subsystem1': {
|
||||
'status': 'UP',
|
||||
'property1': 'system.subsystem1.property1'
|
||||
},
|
||||
'subsystem2': {
|
||||
'status': 'DOWN',
|
||||
'error': 'system.subsystem1.error',
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
'name': 'db',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mail',
|
||||
'error': 'mail.a.b.c',
|
||||
'status': 'UP'
|
||||
},
|
||||
{
|
||||
'name': 'system',
|
||||
'error': undefined,
|
||||
'status': 'DOWN',
|
||||
'details': {
|
||||
'property1': 'system.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem1',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'property1': 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem2',
|
||||
'error': 'system.subsystem1.error',
|
||||
'status': 'DOWN',
|
||||
'details': {
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has additional error', () => {
|
||||
const data = {
|
||||
'status': 'UP',
|
||||
'db': {
|
||||
'status': 'UP',
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
},
|
||||
'mail': {
|
||||
'status': 'UP',
|
||||
'error': 'mail.a.b.c'
|
||||
},
|
||||
'system': {
|
||||
'status': 'DOWN',
|
||||
'error': 'show me',
|
||||
'subsystem1': {
|
||||
'status': 'UP',
|
||||
'property1': 'system.subsystem1.property1'
|
||||
},
|
||||
'subsystem2': {
|
||||
'status': 'DOWN',
|
||||
'error': 'system.subsystem1.error',
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
'name': 'db',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'database': 'H2',
|
||||
'hello': '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mail',
|
||||
'error': 'mail.a.b.c',
|
||||
'status': 'UP'
|
||||
},
|
||||
{
|
||||
'name': 'system',
|
||||
'error': 'show me',
|
||||
'status': 'DOWN'
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem1',
|
||||
'error': undefined,
|
||||
'status': 'UP',
|
||||
'details': {
|
||||
'property1': 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'system.subsystem2',
|
||||
'error': 'system.subsystem1.error',
|
||||
'status': 'DOWN',
|
||||
'details': {
|
||||
'property2': 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing';
|
||||
import { MockBackend } from '@angular/http/testing';
|
||||
import { Http, BaseRequestOptions } from '@angular/http';
|
||||
import { OnInit } from '@angular/core';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { DateUtils, DataUtils } from 'ng-jhipster';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { MockLanguageService } from '../../../helpers/mock-language.service';
|
||||
import { MockActivatedRoute } from '../../../helpers/mock-route.service';
|
||||
import { CommentDetailComponent } from '../../../../../../main/webapp/app/entities/comment/comment-detail.component';
|
||||
import { CommentService } from '../../../../../../main/webapp/app/entities/comment/comment.service';
|
||||
import { Comment } from '../../../../../../main/webapp/app/entities/comment/comment.model';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('Comment Management Detail Component', () => {
|
||||
let comp: CommentDetailComponent;
|
||||
let fixture: ComponentFixture<CommentDetailComponent>;
|
||||
let service: CommentService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CommentDetailComponent],
|
||||
providers: [
|
||||
MockBackend,
|
||||
BaseRequestOptions,
|
||||
DateUtils,
|
||||
DataUtils,
|
||||
DatePipe,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({id: 123})
|
||||
},
|
||||
{
|
||||
provide: Http,
|
||||
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
|
||||
return new Http(backendInstance, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
},
|
||||
{
|
||||
provide: JhiLanguageService,
|
||||
useClass: MockLanguageService
|
||||
},
|
||||
CommentService
|
||||
]
|
||||
}).overrideComponent(CommentDetailComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CommentDetailComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(CommentService);
|
||||
});
|
||||
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
|
||||
spyOn(service, 'find').and.returnValue(Observable.of(new Comment(10)));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.find).toHaveBeenCalledWith(123);
|
||||
expect(comp.comment).toEqual(jasmine.objectContaining({id:10}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing';
|
||||
import { MockBackend } from '@angular/http/testing';
|
||||
import { Http, BaseRequestOptions } from '@angular/http';
|
||||
import { OnInit } from '@angular/core';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { DateUtils, DataUtils } from 'ng-jhipster';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { MockLanguageService } from '../../../helpers/mock-language.service';
|
||||
import { MockActivatedRoute } from '../../../helpers/mock-route.service';
|
||||
import { PostDetailComponent } from '../../../../../../main/webapp/app/entities/post/post-detail.component';
|
||||
import { PostService } from '../../../../../../main/webapp/app/entities/post/post.service';
|
||||
import { Post } from '../../../../../../main/webapp/app/entities/post/post.model';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
|
||||
describe('Post Management Detail Component', () => {
|
||||
let comp: PostDetailComponent;
|
||||
let fixture: ComponentFixture<PostDetailComponent>;
|
||||
let service: PostService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PostDetailComponent],
|
||||
providers: [
|
||||
MockBackend,
|
||||
BaseRequestOptions,
|
||||
DateUtils,
|
||||
DataUtils,
|
||||
DatePipe,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({id: 123})
|
||||
},
|
||||
{
|
||||
provide: Http,
|
||||
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
|
||||
return new Http(backendInstance, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
},
|
||||
{
|
||||
provide: JhiLanguageService,
|
||||
useClass: MockLanguageService
|
||||
},
|
||||
PostService
|
||||
]
|
||||
}).overrideComponent(PostDetailComponent, {
|
||||
set: {
|
||||
template: ''
|
||||
}
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PostDetailComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(PostService);
|
||||
});
|
||||
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
|
||||
spyOn(service, 'find').and.returnValue(Observable.of(new Post(10)));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.find).toHaveBeenCalledWith(123);
|
||||
expect(comp.post).toEqual(jasmine.objectContaining({id:10}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path="../../../../node_modules/@types/jasmine/index.d.ts" />
|
||||
import 'core-js';
|
||||
import 'zone.js/dist/zone';
|
||||
import 'zone.js/dist/long-stack-trace-zone';
|
||||
import 'zone.js/dist/async-test';
|
||||
import 'zone.js/dist/fake-async-test';
|
||||
import 'zone.js/dist/sync-test';
|
||||
import 'zone.js/dist/proxy';
|
||||
import 'zone.js/dist/jasmine-patch';
|
||||
import 'rxjs';
|
||||
import 'intl/locale-data/jsonp/en-US.js';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
||||
|
||||
declare let require: any;
|
||||
const testsContext: any = require.context('./', true, /\.spec/);
|
||||
testsContext.keys().forEach(testsContext);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { AccountService } from '../../../../main/webapp/app/shared/auth/account.service';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockAccountService extends SpyObject {
|
||||
|
||||
getSpy: Spy;
|
||||
saveSpy: Spy;
|
||||
fakeResponse: any;
|
||||
|
||||
constructor() {
|
||||
super(AccountService);
|
||||
|
||||
this.fakeResponse = null;
|
||||
this.getSpy = this.spy('get').andReturn(this);
|
||||
this.saveSpy = this.spy('save').andReturn(this);
|
||||
}
|
||||
|
||||
subscribe(callback: any) {
|
||||
callback(this.fakeResponse);
|
||||
}
|
||||
|
||||
setResponse(json: any): void {
|
||||
this.fakeResponse = json;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockLanguageService extends SpyObject {
|
||||
|
||||
getCurrentSpy: Spy;
|
||||
fakeResponse: any;
|
||||
|
||||
constructor() {
|
||||
super(JhiLanguageService);
|
||||
|
||||
this.fakeResponse = 'en';
|
||||
this.getCurrentSpy = this.spy('getCurrent').andReturn(Promise.resolve(this.fakeResponse));
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
changeLanguage(languageKey: string) {}
|
||||
|
||||
setLocations(locations: string[]) {}
|
||||
|
||||
addLocation(location: string) {}
|
||||
|
||||
reload() {}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { Principal } from '../../../../main/webapp/app/shared/auth/principal.service';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockPrincipal extends SpyObject {
|
||||
|
||||
identitySpy: Spy;
|
||||
fakeResponse: any;
|
||||
|
||||
constructor() {
|
||||
super(Principal);
|
||||
|
||||
this.fakeResponse = {};
|
||||
this.identitySpy = this.spy('identity').andReturn(Promise.resolve(this.fakeResponse));
|
||||
}
|
||||
|
||||
setResponse(json: any): void {
|
||||
this.fakeResponse = json;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export class MockActivatedRoute extends ActivatedRoute {
|
||||
|
||||
constructor(parameters?: any) {
|
||||
super();
|
||||
this.queryParams = Observable.of(parameters);
|
||||
this.params = Observable.of(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
export class MockRouter {
|
||||
navigate = jasmine.createSpy('navigate');
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
export interface GuinessCompatibleSpy extends jasmine.Spy {
|
||||
/** By chaining the spy with and.returnValue, all calls to the function will return a specific
|
||||
* value. */
|
||||
andReturn(val: any): void;
|
||||
/** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied
|
||||
* function. */
|
||||
andCallFake(fn: Function): GuinessCompatibleSpy;
|
||||
/** removes all recorded calls */
|
||||
reset();
|
||||
}
|
||||
|
||||
export class SpyObject {
|
||||
static stub(object = null, config = null, overrides = null) {
|
||||
if (!(object instanceof SpyObject)) {
|
||||
overrides = config;
|
||||
config = object;
|
||||
object = new SpyObject();
|
||||
}
|
||||
|
||||
let m = {};
|
||||
Object.keys(config).forEach((key) => m[key] = config[key]);
|
||||
Object.keys(overrides).forEach((key) => m[key] = overrides[key]);
|
||||
Object.keys(m).forEach((key) => {
|
||||
object.spy(key).andReturn(m[key]);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
constructor(type = null) {
|
||||
if (type) {
|
||||
Object.keys(type.prototype).forEach((prop) => {
|
||||
let m = null;
|
||||
try {
|
||||
m = type.prototype[prop];
|
||||
} catch (e) {
|
||||
// As we are creating spys for abstract classes,
|
||||
// these classes might have getters that throw when they are accessed.
|
||||
// As we are only auto creating spys for methods, this
|
||||
// should not matter.
|
||||
}
|
||||
if (typeof m === 'function') {
|
||||
this.spy(prop);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
spy(name) {
|
||||
if (!this[name]) {
|
||||
this[name] = this._createGuinnessCompatibleSpy(name);
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
|
||||
prop(name, value) {
|
||||
this[name] = value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_createGuinnessCompatibleSpy(name): GuinessCompatibleSpy {
|
||||
let newSpy: GuinessCompatibleSpy = < any > jasmine.createSpy(name);
|
||||
newSpy.andCallFake = < any > newSpy.and.callFake;
|
||||
newSpy.andReturn = < any > newSpy.and.returnValue;
|
||||
newSpy.reset = < any > newSpy.calls.reset;
|
||||
// revisit return null here (previously needed for rtts_assert).
|
||||
newSpy.and.returnValue(null);
|
||||
return newSpy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { MockBackend } from '@angular/http/testing';
|
||||
import { Http, BaseRequestOptions } from '@angular/http';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { MockLanguageService } from './helpers/mock-language.service';
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
MockBackend,
|
||||
BaseRequestOptions,
|
||||
{
|
||||
provide: JhiLanguageService,
|
||||
useClass: MockLanguageService
|
||||
},
|
||||
{
|
||||
provide: Http,
|
||||
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
|
||||
return new Http(backendInstance, defaultOptions);
|
||||
},
|
||||
deps: [MockBackend, BaseRequestOptions]
|
||||
}
|
||||
]
|
||||
})
|
||||
export class BaeldungTestModule {}
|
||||
Reference in New Issue
Block a user