Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X-Road-catalogue
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
X-tee
X-Road-catalogue
Commits
78d31ca6
Commit
78d31ca6
authored
Mar 22, 2019
by
Vitali Stupin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding unit tests
parent
0bbc1088
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
315 additions
and
21 deletions
+315
-21
src/app/app-routing.module.spec.ts
src/app/app-routing.module.spec.ts
+13
-0
src/app/app.component.spec.ts
src/app/app.component.spec.ts
+1
-1
src/app/app.module.spec.ts
src/app/app.module.spec.ts
+20
-0
src/app/subsystems.service.spec.ts
src/app/subsystems.service.spec.ts
+280
-20
src/app/subsystems.service.ts
src/app/subsystems.service.ts
+1
-0
No files found.
src/app/app-routing.module.spec.ts
0 → 100644
View file @
78d31ca6
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
describe
(
'
AppModule
'
,
()
=>
{
let
module
:
AppRoutingModule
;
beforeEach
(()
=>
{
module
=
new
AppRoutingModule
();
});
it
(
'
should be created
'
,
()
=>
{
expect
(
module
).
toBeTruthy
();
});
});
src/app/app.component.spec.ts
View file @
78d31ca6
import
{
TestBed
,
async
}
from
'
@angular/core/testing
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
describe
(
'
AppComponent
'
,
()
=>
{
...
...
src/app/app.module.spec.ts
0 → 100644
View file @
78d31ca6
import
{
AppModule
,
HttpLoaderFactory
}
from
'
./app.module
'
;
import
{
TranslateHttpLoader
}
from
'
@ngx-translate/http-loader
'
;
describe
(
'
AppModule
'
,
()
=>
{
let
module
:
AppModule
;
let
httpClientSpy
:
{
get
:
jasmine
.
Spy
};
beforeEach
(()
=>
{
httpClientSpy
=
jasmine
.
createSpyObj
(
'
HttpClient
'
,
[
'
get
'
]);
module
=
new
AppModule
();
});
it
(
'
should be created
'
,
()
=>
{
expect
(
module
).
toBeTruthy
();
});
it
(
'
HttpLoaderFactory should work
'
,
()
=>
{
expect
(
HttpLoaderFactory
(
httpClientSpy
as
any
)
instanceof
TranslateHttpLoader
).
toBeTruthy
();
});
});
src/app/subsystems.service.spec.ts
View file @
78d31ca6
import
{
TestBed
}
from
'
@angular/core/testing
'
;
import
{
TranslateModule
}
from
'
@ngx-translate/core
'
;
import
{
SubsystemsService
}
from
'
./subsystems.service
'
;
import
{
HttpClientTestingModule
,
HttpTestingController
}
from
'
@angular/common/http/testing
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
of
,
defer
}
from
'
rxjs
'
;
import
{
Subsystem
}
from
'
./subsystem
'
;
import
{
Method
}
from
'
./method
'
;
import
{
HttpErrorResponse
}
from
'
@angular/common/http
'
;
import
{
tick
,
fakeAsync
}
from
'
@angular/core/testing
'
;
import
{
FILTER_DEBOUNCE
,
DEFAULT_LIMIT
,
INSTANCES
}
from
'
./config
'
;
describe
(
'
SubsystemsService
'
,
()
=>
{
let
httpClientSpy
:
{
get
:
jasmine
.
Spy
};
let
service
:
SubsystemsService
;
let
httpClient
:
HttpClient
;
let
httpTestingController
:
HttpTestingController
;
beforeEach
(()
=>
TestBed
.
configureTestingModule
({
imports
:
[
TranslateModule
.
forRoot
(),
HttpClientTestingModule
]
}));
beforeEach
(()
=>
{
httpClient
=
TestBed
.
get
(
HttpClient
);
httpTestingController
=
TestBed
.
get
(
HttpTestingController
);
service
=
TestBed
.
get
(
SubsystemsService
);
httpClientSpy
=
jasmine
.
createSpyObj
(
'
HttpClient
'
,
[
'
get
'
]);
service
=
new
SubsystemsService
(
httpClientSpy
as
any
);
});
it
(
'
should be created
'
,
()
=>
{
expect
(
service
).
toBeTruthy
();
});
/*it('should set instance', () => {
it
(
'
should set instance on HTTP OK
'
,
()
=>
{
const
sourceSubsystems
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
methods
:
[
{
methodStatus
:
'
OK
'
,
serviceCode
:
'
SERVICE
'
,
wsdl
:
'
URL
'
,
serviceVersion
:
'
VER
'
}
]
},
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER2
'
,
methods
:
[]
}
];
const
expectedSubsystems
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER/SYSTEM
'
,
methods
:
[
{
methodStatus
:
'
OK
'
,
serviceCode
:
'
SERVICE
'
,
wsdl
:
'
URL
'
,
serviceVersion
:
'
VER
'
,
fullMethodName
:
'
INST/CLASS/MEMBER/SYSTEM/SERVICE/VER
'
}
]
},
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER2
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER2/SYSTEM
'
,
methods
:
[]
}
];
httpClientSpy
.
get
.
and
.
returnValue
(
of
(
sourceSubsystems
));
// Setting value to test resetting of values
service
.
subsystemsSubject
.
next
([
new
Subsystem
()]);
service
.
filteredSubsystemsSubject
.
next
([
new
Subsystem
()]);
service
.
setInstance
(
'
EE
'
);
// expect(service).toBeTruthy();
// httpTestingController.expectOne('https://x-tee.ee/catalogue/EE/wsdls/index.json');
});*/
expect
(
httpClientSpy
.
get
).
toHaveBeenCalledWith
(
'
https://www.x-tee.ee/catalogue/EE/wsdls/index.json
'
);
expect
(
service
.
subsystemsSubject
.
value
).
toEqual
(
expectedSubsystems
);
// No filters yet
expect
(
service
.
filteredSubsystemsSubject
.
value
).
toEqual
(
expectedSubsystems
);
});
it
(
'
should set instance on HTTP ERROR
'
,
fakeAsync
(()
=>
{
const
errorResponse
=
new
HttpErrorResponse
({
error
:
'
error
'
,
status
:
404
,
statusText
:
'
Not Found
'
});
httpClientSpy
.
get
.
and
.
returnValue
(
defer
(()
=>
Promise
.
reject
(
errorResponse
)));
// Setting value to test resetting of values
service
.
subsystemsSubject
.
next
([
new
Subsystem
()]);
service
.
filteredSubsystemsSubject
.
next
([
new
Subsystem
()]);
service
.
setInstance
(
'
EE
'
);
// Waiting for some (unknown) asynchronous work
tick
();
expect
(
httpClientSpy
.
get
).
toHaveBeenCalledWith
(
'
https://www.x-tee.ee/catalogue/EE/wsdls/index.json
'
);
expect
(
service
.
subsystemsSubject
.
value
).
toEqual
([]);
expect
(
service
.
filteredSubsystemsSubject
.
value
).
toEqual
([]);
}));
it
(
'
should filter nonEmpty subsystems
'
,
()
=>
{
const
sourceSubsystems
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER/SYSTEM
'
,
methods
:
[{}
as
Method
]
},
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER2
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER2/SYSTEM
'
,
methods
:
[]
}
];
const
expectedSubsystems
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER/SYSTEM
'
,
methods
:
[{}
as
Method
]
}
];
service
.
subsystemsSubject
.
next
(
sourceSubsystems
);
service
.
setNonEmpty
(
true
);
expect
(
service
.
filteredSubsystemsSubject
.
value
).
toEqual
(
expectedSubsystems
);
});
it
(
'
should set filter for subsystems
'
,
fakeAsync
(()
=>
{
const
sourceSubsystems
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER/SYSTEM
'
,
methods
:
[
{
methodStatus
:
'
OK
'
,
serviceCode
:
'
SERVICE
'
,
wsdl
:
'
URL
'
,
serviceVersion
:
'
VER
'
,
fullMethodName
:
'
INST/CLASS/MEMBER/SYSTEM/SERVICE/VER
'
},
{
methodStatus
:
'
OK
'
,
serviceCode
:
'
SERVICE2
'
,
wsdl
:
'
URL
'
,
serviceVersion
:
'
VER
'
,
fullMethodName
:
'
INST/CLASS/MEMBER/SYSTEM/SERVICE2/VER
'
}
]
},
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER2
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER2/SYSTEM
'
,
methods
:
[]
}
];
const
expectedSubsystems1
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER2
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER2/SYSTEM
'
,
methods
:
[]
}
];
const
expectedSubsystems2
=
[
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
,
fullSubsystemName
:
'
INST/CLASS/MEMBER/SYSTEM
'
,
methods
:
[
{
methodStatus
:
'
OK
'
,
serviceCode
:
'
SERVICE2
'
,
wsdl
:
'
URL
'
,
serviceVersion
:
'
VER
'
,
fullMethodName
:
'
INST/CLASS/MEMBER/SYSTEM/SERVICE2/VER
'
}
]
}
];
service
.
subsystemsSubject
.
next
(
sourceSubsystems
);
// Search member without methods
service
.
setFilter
(
'
MEMBER2
'
);
// Waiting for a debounce time to apply filter
tick
(
FILTER_DEBOUNCE
);
expect
(
service
.
filteredSubsystemsSubject
.
value
).
toEqual
(
expectedSubsystems1
);
// Search member with multiple methods
service
.
setFilter
(
'
SERVICE2
'
);
// Waiting for a debounce time to apply filter
tick
(
FILTER_DEBOUNCE
);
expect
(
service
.
filteredSubsystemsSubject
.
value
).
toEqual
(
expectedSubsystems2
);
// Search with limit
const
sourceSubsystems2
=
[];
for
(
let
i
=
0
;
i
<
DEFAULT_LIMIT
+
1
;
i
++
)
{
sourceSubsystems2
.
push
(
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
+
i
,
fullSubsystemName
:
'
INST/CLASS/MEMBER
'
+
i
+
'
/SYSTEM
'
,
methods
:
[]
}
);
}
service
.
subsystemsSubject
.
next
(
sourceSubsystems2
);
service
.
setFilter
(
'
MEMBER
'
);
// Waiting for a debounce time to apply filter
tick
(
FILTER_DEBOUNCE
);
expect
(
service
.
filteredSubsystemsSubject
.
value
.
length
).
toEqual
(
DEFAULT_LIMIT
);
}));
it
(
'
should set limit
'
,
()
=>
{
const
sourceSubsystems
=
[];
for
(
let
i
=
0
;
i
<
51
;
i
++
)
{
sourceSubsystems
.
push
(
{
memberClass
:
'
CLASS
'
,
subsystemCode
:
'
SYSTEM
'
,
xRoadInstance
:
'
INST
'
,
subsystemStatus
:
'
OK
'
,
memberCode
:
'
MEMBER
'
+
i
,
fullSubsystemName
:
'
INST/CLASS/MEMBER
'
+
i
+
'
/SYSTEM
'
,
methods
:
[]
}
);
}
service
.
subsystemsSubject
.
next
(
sourceSubsystems
);
service
.
setLimit
(
'
all
'
);
expect
(
service
.
filteredSubsystemsSubject
.
value
.
length
).
toEqual
(
51
);
service
.
setLimit
(
'
50
'
);
expect
(
service
.
filteredSubsystemsSubject
.
value
.
length
).
toEqual
(
50
);
service
.
setLimit
(
'
20
'
);
expect
(
service
.
filteredSubsystemsSubject
.
value
.
length
).
toEqual
(
20
);
service
.
setLimit
(
'
10
'
);
expect
(
service
.
filteredSubsystemsSubject
.
value
.
length
).
toEqual
(
10
);
});
it
(
'
getLimit should work
'
,
()
=>
{
expect
(
service
.
getLimit
()).
toEqual
(
DEFAULT_LIMIT
.
toString
());
service
.
setLimit
(
'
all
'
);
expect
(
service
.
getLimit
()).
toEqual
(
'
all
'
);
});
it
(
'
getInstances should work
'
,
()
=>
{
expect
(
service
.
getInstances
()).
toEqual
(
Object
.
keys
(
INSTANCES
));
});
it
(
'
getDefaultInstance should work
'
,
()
=>
{
expect
(
service
.
getDefaultInstance
()).
toEqual
(
Object
.
keys
(
INSTANCES
)[
0
]);
});
it
(
'
getInstance should work
'
,
()
=>
{
// Default value
expect
(
service
.
getInstance
()).
toEqual
(
''
);
});
it
(
'
getApiUrlBase should work
'
,
()
=>
{
// Default value
expect
(
service
.
getApiUrlBase
()).
toEqual
(
''
);
});
});
src/app/subsystems.service.ts
View file @
78d31ca6
...
...
@@ -96,6 +96,7 @@ export class SubsystemsService {
*/
private
handleError
<
T
>
(
result
?:
T
)
{
return
(
error
:
any
):
Observable
<
T
>
=>
{
// TODO: translation!
this
.
emitWarning
(
'
Error while loading data from server!
'
);
// Let the app keep running by returning an empty result.
return
of
(
result
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment