Skip to content

Commit f5eb185

Browse files
committed
added test angular in project
1 parent 3469f2b commit f5eb185

File tree

10 files changed

+307
-72
lines changed

10 files changed

+307
-72
lines changed

.angular-cli.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"project": {
4+
"name": "my-app-test"
5+
},
6+
"apps": [
7+
{
8+
"root": "src",
9+
"outDir": "dist",
10+
"assets": [
11+
"assets",
12+
"favicon.ico"
13+
],
14+
"index": "index.html",
15+
"main": "main.ts",
16+
"polyfills": "polyfills.ts",
17+
"test": "test.ts",
18+
"tsconfig": "tsconfig.app.json",
19+
"testTsconfig": "tsconfig.spec.json",
20+
"prefix": "app",
21+
"styles": [
22+
"styles.css"
23+
],
24+
"scripts": [],
25+
"environmentSource": "environments/environment.ts",
26+
"environments": {
27+
"dev": "environments/environment.ts",
28+
"prod": "environments/environment.prod.ts"
29+
}
30+
}
31+
],
32+
"e2e": {
33+
"protractor": {
34+
"config": "./protractor.conf.js"
35+
}
36+
},
37+
"lint": [
38+
{
39+
"project": "src/tsconfig.app.json",
40+
"exclude": "**/node_modules/**"
41+
},
42+
{
43+
"project": "src/tsconfig.spec.json",
44+
"exclude": "**/node_modules/**"
45+
},
46+
{
47+
"project": "e2e/tsconfig.e2e.json",
48+
"exclude": "**/node_modules/**"
49+
}
50+
],
51+
"test": {
52+
"karma": {
53+
"config": "./karma.conf.js"
54+
}
55+
},
56+
"defaults": {
57+
"styleExt": "css",
58+
"component": {}
59+
}
60+
}
61+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ dist.tgz
3636
dist/
3737

3838
!protractor.conf.js
39+
!karma.conf.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/fernandocode/ionic-database-builder/issues)
33

44
# ionic-database-builder
5-
Extended library from [database-builder](https://github.com/fernandocode/database-builder) to assist in creating and maintaining SQL commands. Allowing integrate execute commands with [SQLite ('@ionic-native/sqlite')](https://ionicframework.com/docs/native/sqlite/), [Web Sql](https://www.w3.org/TR/webdatabase/), [Indexed Database](https://www.w3.org/TR/IndexedDB/), etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.
5+
Extended library from [database-builder](https://github.com/fernandocode/database-builder) to assist in creating and maintaining SQL commands. Allowing integrate execute commands with [SQLite ('@ionic-native/sqlite')](https://ionicframework.com/docs/native/sqlite/), [Web Sql](https://www.w3.org/TR/webdatabase/), etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.
66

77
# Getting Started
88

karma.conf.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular/cli'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage-istanbul-reporter'),
13+
require('@angular/cli/plugins/karma')
14+
],
15+
client:{
16+
clearContext: false // leave Jasmine Spec Runner output visible in browser
17+
},
18+
coverageIstanbulReporter: {
19+
reports: [ 'html', 'lcovonly' ],
20+
fixWebpackSourcePaths: true
21+
},
22+
angularCli: {
23+
environment: 'dev'
24+
},
25+
reporters: ['progress', 'kjhtml'],
26+
port: 9876,
27+
colors: true,
28+
logLevel: config.LOG_INFO,
29+
autoWatch: true,
30+
browsers: ['Chrome'],
31+
singleRun: false
32+
});
33+
};
34+

package.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ionic-database-builder",
33
"version": "0.0.7",
4-
"description": "Extended library from database-builder to assist in creating and maintaining SQL commands. Allowing integrate execute commands with SQLite ('@ionic-native/sqlite'), Web Sql, Indexed Database, etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.",
4+
"description": "Extended library from database-builder to assist in creating and maintaining SQL commands. Allowing integrate execute commands with SQLite ('@ionic-native/sqlite'), Web Sql, etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.",
55
"main": "index.js",
66
"scripts": {
77
"ng": "ng",
@@ -45,16 +45,35 @@
4545
"homepage": "https://github.com/fernandocode/ionic-database-builder#readme",
4646
"dependencies": {
4747
"@angular/core": "5.0.0",
48-
"database-builder": "0.0.22",
49-
"zone.js": "0.8.26"
48+
"database-builder": "0.0.22"
5049
},
5150
"devDependencies": {
5251
"@angular/cli": "^1.7.4",
52+
"@angular/common": "5.0.0",
5353
"@angular/compiler": "5.0.0",
5454
"@angular/compiler-cli": "5.0.0",
55+
"@angular/language-service": "5.0.0",
56+
"@angular/platform-browser": "5.0.0",
57+
"@angular/platform-browser-dynamic": "5.0.0",
58+
"@types/jasmine": "~2.8.3",
59+
"@types/jasminewd2": "~2.0.2",
60+
"@types/node": "~6.0.60",
61+
"codelyzer": "^4.0.1",
62+
"jasmine-core": "~2.8.0",
63+
"jasmine-spec-reporter": "~4.2.1",
64+
"karma": "~2.0.0",
65+
"karma-chrome-launcher": "~2.2.0",
66+
"karma-coverage-istanbul-reporter": "^1.2.1",
67+
"karma-jasmine": "~1.1.0",
68+
"karma-jasmine-html-reporter": "^0.2.2",
5569
"ng-packagr": "2.4.2",
70+
"protractor": "~5.1.2",
71+
"rxjs": "^5.5.9",
72+
"ts-node": "~4.1.0",
5673
"tsickle": "0.27.5",
57-
"typescript": "2.8.1"
74+
"tslint": "~5.9.1",
75+
"typescript": "~2.5.3",
76+
"zone.js": "^0.8.26"
5877
},
5978
"tsconfig": "./tsconfig.json"
6079
}

src/polyfills.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* This file includes polyfills needed by Angular and is loaded before the app.
3+
* You can add your own extra polyfills to this file.
4+
*
5+
* This file is divided into 2 sections:
6+
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7+
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8+
* file.
9+
*
10+
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11+
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12+
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13+
*
14+
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15+
*/
16+
17+
/***************************************************************************************************
18+
* BROWSER POLYFILLS
19+
*/
20+
21+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
22+
// import 'core-js/es6/symbol';
23+
// import 'core-js/es6/object';
24+
// import 'core-js/es6/function';
25+
// import 'core-js/es6/parse-int';
26+
// import 'core-js/es6/parse-float';
27+
// import 'core-js/es6/number';
28+
// import 'core-js/es6/math';
29+
// import 'core-js/es6/string';
30+
// import 'core-js/es6/date';
31+
// import 'core-js/es6/array';
32+
// import 'core-js/es6/regexp';
33+
// import 'core-js/es6/map';
34+
// import 'core-js/es6/weak-map';
35+
// import 'core-js/es6/set';
36+
37+
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
38+
// import 'classlist.js'; // Run `npm install --save classlist.js`.
39+
40+
/** IE10 and IE11 requires the following for the Reflect API. */
41+
// import 'core-js/es6/reflect';
42+
43+
44+
/** Evergreen browsers require these. **/
45+
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46+
import "core-js/es7/reflect";
47+
48+
49+
/**
50+
* Required to support Web Animations `@angular/platform-browser/animations`.
51+
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
52+
**/
53+
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
54+
55+
/**
56+
* By default, zone.js will patch all possible macroTask and DomEvents
57+
* user can disable parts of macroTask/DomEvents patch by setting following flags
58+
*/
59+
60+
// (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
61+
// (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
62+
// (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
63+
64+
/*
65+
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
66+
* with the following flag, it will bypass `zone.js` patch for IE/Edge
67+
*/
68+
// (window as any).__Zone_enable_cross_context_check = true;
69+
70+
/***************************************************************************************************
71+
* Zone JS is required by default for Angular itself.
72+
*/
73+
import "zone.js/dist/zone"; // Included with Angular CLI.
74+
75+
76+
77+
/***************************************************************************************************
78+
* APPLICATION IMPORTS
79+
*/

src/test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
2+
3+
import "zone.js/dist/zone-testing";
4+
import { getTestBed } from "@angular/core/testing";
5+
import {
6+
BrowserDynamicTestingModule,
7+
platformBrowserDynamicTesting
8+
} from "@angular/platform-browser-dynamic/testing";
9+
10+
declare const require: any;
11+
12+
// First, initialize the Angular testing environment.
13+
getTestBed().initTestEnvironment(
14+
BrowserDynamicTestingModule,
15+
platformBrowserDynamicTesting()
16+
);
17+
// Then we find all the tests.
18+
const context = require.context("./", true, /\.spec\.ts$/);
19+
// And load the modules.
20+
context.keys().map(context);

src/test/mapper.spec.ts

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,67 @@
1-
// import { Classificacao } from "./models/classificacao";
2-
// import { SubRegiao } from "./models/sub-regiao";
3-
// import { Cidade } from "./models/cidade";
4-
// import { Cliente } from "./models/cliente";
5-
// import { MappersTableSimple } from "..";
6-
// import { DatabaseHelper, Insert } from "database-builder";
7-
// import { TestClazz } from "./models/test-clazz";
8-
// import { TestClazzRef } from "./models/test-clazz-ref";
9-
// import { Uf } from "./models/uf";
10-
// import { Regiao } from "./models/regiao";
11-
// import { expect } from "chai";
1+
import { Classificacao } from "./models/classificacao";
2+
import { SubRegiao } from "./models/sub-regiao";
3+
import { Cidade } from "./models/cidade";
4+
import { Cliente } from "./models/cliente";
5+
import { MappersTableSimple } from "..";
6+
import { DatabaseHelper, Insert } from "database-builder";
7+
import { TestClazz } from "./models/test-clazz";
8+
import { TestClazzRef } from "./models/test-clazz-ref";
9+
import { Uf } from "./models/uf";
10+
import { Regiao } from "./models/regiao";
1211

13-
// describe("Mapper", () => {
12+
describe("Mapper", () => {
1413

15-
// const mapper = new MappersTableSimple(new DatabaseHelper(), {
16-
// references: false,
17-
// referencesId: true,
18-
// referencesIdRecursive: false,
19-
// referencesIdColumn: "id"
20-
// })
21-
// .mapper(
22-
// false,
23-
// void 0,
24-
// void 0,
25-
// TestClazz,
26-
// TestClazzRef,
27-
// Cliente,
28-
// Cidade,
29-
// Uf,
30-
// SubRegiao,
31-
// Regiao,
32-
// Classificacao
33-
// );
14+
const mapper = new MappersTableSimple(new DatabaseHelper(), {
15+
references: false,
16+
referencesId: true,
17+
referencesIdRecursive: false,
18+
referencesIdColumn: "id"
19+
})
20+
.mapper(
21+
false,
22+
void 0,
23+
void 0,
24+
TestClazz,
25+
TestClazzRef,
26+
Cliente,
27+
Cidade,
28+
Uf,
29+
SubRegiao,
30+
Regiao,
31+
Classificacao
32+
);
3433

35-
// const clienteToSave = {
36-
// id: 1,
37-
// razaoSocial: "Razão",
38-
// apelido: "Apelido",
39-
// cidade: {
40-
// id: 2,
41-
// nome: "Cidade",
42-
// uf: {
43-
// id: "SC",
44-
// nome: "Santa Catarina"
45-
// } as Uf,
46-
// subRegiao: {
47-
// id: 4,
48-
// nome: "Sub Região",
49-
// regiao: {
50-
// id: 5,
51-
// nome: "Região"
52-
// } as Regiao
53-
// } as SubRegiao,
54-
// } as Cidade,
55-
// classificacao: {
56-
// id: 3,
57-
// descricao: "Top"
58-
// } as Classificacao,
59-
// desativo: false
60-
// } as Cliente;
34+
const clienteToSave = {
35+
id: 1,
36+
razaoSocial: "Razão",
37+
apelido: "Apelido",
38+
cidade: {
39+
id: 2,
40+
nome: "Cidade",
41+
uf: {
42+
id: "SC",
43+
nome: "Santa Catarina"
44+
} as Uf,
45+
subRegiao: {
46+
id: 4,
47+
nome: "Sub Região",
48+
regiao: {
49+
id: 5,
50+
nome: "Região"
51+
} as Regiao
52+
} as SubRegiao,
53+
} as Cidade,
54+
classificacao: {
55+
id: 3,
56+
descricao: "Top"
57+
} as Classificacao,
58+
desativo: false
59+
} as Cliente;
6160

62-
// it("Test mapper insert", () => {
63-
// const result = new Insert(Cliente, clienteToSave, mapper.getMapper(Cliente)).compile();
64-
// expect(result.params.toString()).to.equal([1, "Razão", "Apelido", false, 2, 3].toString());
65-
// expect(result.query).to.equal("INSERT INTO Cliente (id, razaoSocial, apelido, desativo, cidade_id, classificacao_id) VALUES (?, ?, ?, ?, ?, ?)");
66-
// });
61+
it("Test mapper insert", () => {
62+
const result = new Insert(Cliente, clienteToSave, mapper.getMapper(Cliente)).compile();
63+
expect(result.params.toString()).toEqual([1, "Razão", "Apelido", false, 2, 3].toString());
64+
expect(result.query).toEqual("INSERT INTO Cliente (id, razaoSocial, apelido, desativo, cidade_id, classificacao_id) VALUES (?, ?, ?, ?, ?, ?)");
65+
});
6766

68-
// });
67+
});

0 commit comments

Comments
 (0)