Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
uphrh-SunbirdEd-portal-old
Commits
7c4df7c5
Commit
7c4df7c5
authored
4 years ago
by
sudip mukherjee
Browse files
Options
Download
Patches
Plain Diff
Issue #SH-153 fix: TC coverage for add-to-group directive
parent
81c31c6c
master
Dark_theme
SB-25589
SB-28090
aws_fileRead
dependabot/npm_and_yarn/src/app/client/decode-uri-component-0.2.2
dependabot/npm_and_yarn/src/app/decode-uri-component-0.2.2
dependabot/npm_and_yarn/src/app/express-4.17.3
dependabot/npm_and_yarn/src/app/jsonwebtoken-9.0.0
dependabot/npm_and_yarn/src/desktop/OpenRAP/decode-uri-component-0.2.2
dependabot/npm_and_yarn/src/desktop/OpenRAP/express-4.17.3
dependabot/npm_and_yarn/src/desktop/OpenRAP/jsonwebtoken-9.0.0
dependabot/npm_and_yarn/src/desktop/OpenRAP/qs-6.5.3
dependabot/npm_and_yarn/src/desktop/decode-uri-component-0.2.2
dependabot/npm_and_yarn/src/desktop/express-4.17.3
dependabot/npm_and_yarn/src/desktop/jsonwebtoken-9.0.0
dependabot/npm_and_yarn/src/desktop/qs-6.10.3
filters_5.1.1
gcp
gcp_test
keshavprasadms-patch-1
keshavprasadms-patch-2
release-3.3.0
release-3.3.0-telemetry-fix
release-3.3.1
release-3.3.2
release-3.4.0
release-3.4.1
release-3.4.2
release-3.4.3
release-3.4.4
release-3.4.5
release-3.4.6
release-3.4.7
release-3.5.0
release-3.5.1
release-3.5.2
release-3.5.3
release-3.6.0
release-3.6.1
release-3.6.5
release-3.6.6
release-3.7.0
release-3.7.1
release-3.7.2
release-3.8.0
release-3.8.1
release-3.8.2
release-3.8.3
release-3.9.0
release-3.9.1
release-3.9.2
release-3.9.3
release-4.0.0
release-4.0.1
release-4.0.2
release-4.1
release-4.1.0
release-4.1.1
release-4.10.0
release-4.10.0.1
release-4.10.1
release-4.10.2
release-4.10.2.1
release-4.10.2.2
release-4.10.3
release-4.2.0
release-4.2.1
release-4.3.0
release-4.3.1
release-4.4.0
release-4.4.1
release-4.5.0
release-4.5.1
release-4.5.2
release-4.6.0
release-4.7.0
release-4.7.1
release-4.8.0
release-4.8.5
release-4.9.0
release-4.9.1
release-5.0.0
release-5.0.0.1
release-5.0.0.2
release-5.0.0.3
release-5.0.1
release-5.0.2
release-5.1.0
release-5.1.1
revert-5244-sh-809
revert-5260-SB-table-3.3.0
revert-8284-release-5.0.0
sharathkashyap-patch-1
Tags unavailable
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/client/src/app/modules/shared/directives/add-to-group/add-to-group.directive.spec.data.ts
+42
-2
...rectives/add-to-group/add-to-group.directive.spec.data.ts
src/app/client/src/app/modules/shared/directives/add-to-group/add-to-group.directive.spec.ts
+183
-6
...ed/directives/add-to-group/add-to-group.directive.spec.ts
with
225 additions
and
8 deletions
+225
-8
src/app/client/src/app/modules/shared/directives/add-to-group/add-to-group.directive.spec.data.ts
+
42
−
2
View file @
7c4df7c5
export
const
AddToGroupDirectiveMockData
=
{
csGroupAddableBlockData
:
{
groupData
:
{
'
membershipType
'
:
'
invite_only
'
,
'
updatedBy
'
:
'
8454cb21-3ce9-4e30-85b5-fade097880d8
'
,
'
createdBy
'
:
'
8454cb21-3ce9-4e30-85b5-fade097880d8
'
,
'
activities
'
:
[
{
'
id
'
:
'
do_1130958935577886721105
'
,
'
type
'
:
'
PracticeQuestionSet
'
}
],
'
members
'
:
[
{
'
userId
'
:
'
8454cb21-3ce9-4e30-85b5-fade097880d8
'
,
'
groupId
'
:
'
dcffdb33-edbe-4ea8-8ed5-4d6781c2e2e7
'
,
'
role
'
:
'
admin
'
,
'
status
'
:
'
active
'
,
'
createdOn
'
:
'
2020-09-09 07:05:27:543+0000
'
,
'
createdBy
'
:
'
8454cb21-3ce9-4e30-85b5-fade097880d8
'
,
'
updatedOn
'
:
null
,
'
updatedBy
'
:
null
,
'
removedOn
'
:
null
,
'
removedBy
'
:
null
,
'
name
'
:
'
Mentor First User
'
,
'
title
'
:
'
Mentor first user (You)
'
,
'
initial
'
:
'
M
'
,
'
identifier
'
:
'
8454cb21-3ce9-4e30-85b5-fade097880d8
'
,
'
isAdmin
'
:
true
,
'
isCreator
'
:
true
,
'
isSelf
'
:
true
,
'
isMenu
'
:
false
,
'
indexOfMember
'
:
0
}
],
'
name
'
:
'
My testing group
'
,
'
description
'
:
''
,
'
id
'
:
'
dcffdb33-edbe-4ea8-8ed5-4d6781c2e2e7
'
,
'
updatedOn
'
:
'
2020-09-09 07:21:15:380+0000
'
,
'
createdOn
'
:
'
2020-09-09 07:05:27:528+0000
'
,
'
status
'
:
'
active
'
,
'
isCreator
'
:
true
,
'
isAdmin
'
:
true
,
'
initial
'
:
'
M
'
}
};
This diff is collapsed.
Click to expand it.
src/app/client/src/app/modules/shared/directives/add-to-group/add-to-group.directive.spec.ts
+
183
−
6
View file @
7c4df7c5
...
...
@@ -8,12 +8,30 @@ import { BrowserCacheTtlService, UtilService } from '../../services';
import
{
HttpClientTestingModule
}
from
'
@angular/common/http/testing
'
;
import
{
ElementRef
}
from
'
@angular/core
'
;
import
{
Router
,
ActivatedRoute
}
from
'
@angular/router
'
;
import
{
AddToGroupDirectiveMockData
}
from
'
./add-to-group.directive.spec.data
'
;
import
{
of
as
observableOf
,
throwError
}
from
'
rxjs
'
;
import
*
as
_
from
'
lodash-es
'
;
import
{
configureTestSuite
}
from
'
@sunbird/test-util
'
;
import
{
CsGroupAddableBloc
}
from
'
@project-sunbird/client-services/blocs
'
;
describe
(
'
AddToGroupDirective
'
,
()
=>
{
let
directive
:
AddToGroupDirective
;
configureTestSuite
();
class
ResourceServiceStub
{
}
const
resourceBundleStub
=
{
messages
:
{
imsg
:
{
activityAddedSuccess
:
'
Activity added successfully
'
},
emsg
:
{
activityAddedToGroup
:
'
You have added this activity previously for the group
'
,
noAdminRole
:
'
You are not authorised to add activities
'
},
stmsg
:
{
activityAddFail
:
'
Could not add the activity. Try again later
'
}
}
};
class
RouterStub
{
...
...
@@ -23,7 +41,15 @@ describe('AddToGroupDirective', () => {
};
const
elementRefStub
=
{
nativeElement
:
{
'
lang
'
:
'
en
'
,
'
dir
'
:
'
ltr
'
}
};
const
elementRefStub
=
{
nativeElement
:
{
'
lang
'
:
'
en
'
,
'
dir
'
:
'
ltr
'
,
style
:
{
display
:
'
none
'
}
}
};
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
...
...
@@ -39,11 +65,11 @@ describe('AddToGroupDirective', () => {
UtilService
,
ToasterService
,
TelemetryService
,
{
provide
:
ResourceService
,
use
Class
:
R
esource
Servic
eStub
},
{
provide
:
ResourceService
,
use
Value
:
r
esource
Bundl
eStub
},
{
provide
:
ElementRef
,
useValue
:
elementRefStub
},
{
provide
:
Router
,
useClass
:
RouterStub
},
{
provide
:
ActivatedRoute
,
useValue
:
fakeActivatedRoute
},
{
provide
:
'
CS_GROUP_SERVICE
'
,
useFactory
:
csGroupServiceFactory
}
{
provide
:
ActivatedRoute
,
useValue
:
fakeActivatedRoute
},
{
provide
:
'
CS_GROUP_SERVICE
'
,
useFactory
:
csGroupServiceFactory
}
]
});
directive
=
TestBed
.
get
(
AddToGroupDirective
);
...
...
@@ -53,4 +79,155 @@ describe('AddToGroupDirective', () => {
expect
(
directive
).
toBeTruthy
();
});
it
(
'
should not add activity to the group if it is already been added
'
,
()
=>
{
/** Arrange */
const
toasterService
=
TestBed
.
get
(
ToasterService
);
directive
.
identifier
=
'
do_1130958935577886721105
'
;
spyOn
(
directive
,
'
sendInteractData
'
).
and
.
stub
();
directive
.
groupAddableBlocData
=
{
pageIds
:
[
'
course
'
],
groupId
:
[
'
SOME_GROUP_ID
'
],
params
:
{
searchQuery
:
'
{"request":{"filters":{"contentType":["Course"],"status":["Live"],"objectType":["Content"]}}}
'
,
groupData
:
AddToGroupDirectiveMockData
.
groupData
,
contentType
:
'
Course
'
}
};
spyOn
(
directive
,
'
goBack
'
).
and
.
stub
();
spyOn
(
toasterService
,
'
error
'
).
and
.
stub
();
/** Act */
directive
.
addActivityToGroup
();
/** Assert */
expect
(
directive
.
sendInteractData
).
toHaveBeenCalled
();
expect
(
directive
.
goBack
).
toHaveBeenCalled
();
expect
(
toasterService
.
error
).
toHaveBeenCalledWith
(
'
You have added this activity previously for the group
'
);
});
it
(
'
should add activity to the group if it is not added
'
,
()
=>
{
/** Arrange */
const
toasterService
=
TestBed
.
get
(
ToasterService
);
directive
.
identifier
=
'
do_12345
'
;
spyOn
(
directive
,
'
sendInteractData
'
).
and
.
stub
();
directive
.
groupAddableBlocData
=
{
pageIds
:
[
'
course
'
],
groupId
:
[
'
SOME_GROUP_ID
'
],
params
:
{
searchQuery
:
'
{"request":{"filters":{"contentType":["Course"],"status":["Live"],"objectType":["Content"]}}}
'
,
groupData
:
AddToGroupDirectiveMockData
.
groupData
,
contentType
:
'
Course
'
}
};
spyOn
(
directive
,
'
goBack
'
).
and
.
stub
();
spyOn
(
directive
[
'
csGroupService
'
],
'
addActivities
'
).
and
.
returnValue
(
observableOf
({}));
spyOn
(
toasterService
,
'
success
'
).
and
.
stub
();
/** Act */
directive
.
addActivityToGroup
();
/** Assert */
expect
(
directive
.
sendInteractData
).
toHaveBeenCalled
();
expect
(
directive
.
goBack
).
toHaveBeenCalled
();
expect
(
toasterService
.
success
).
toHaveBeenCalledWith
(
'
Activity added successfully
'
);
});
it
(
'
should show a toaster message if add activity api fail
'
,
()
=>
{
/** Arrange */
const
toasterService
=
TestBed
.
get
(
ToasterService
);
directive
.
identifier
=
'
do_12345
'
;
spyOn
(
directive
,
'
sendInteractData
'
).
and
.
stub
();
directive
.
groupAddableBlocData
=
{
pageIds
:
[
'
course
'
],
groupId
:
[
'
SOME_GROUP_ID
'
],
params
:
{
searchQuery
:
'
{"request":{"filters":{"contentType":["Course"],"status":["Live"],"objectType":["Content"]}}}
'
,
groupData
:
AddToGroupDirectiveMockData
.
groupData
,
contentType
:
'
Course
'
}
};
spyOn
(
directive
,
'
goBack
'
).
and
.
stub
();
spyOn
(
directive
[
'
csGroupService
'
],
'
addActivities
'
).
and
.
callFake
(()
=>
throwError
({}));
spyOn
(
toasterService
,
'
error
'
).
and
.
stub
();
/** Act */
directive
.
addActivityToGroup
();
/** Assert */
expect
(
directive
.
sendInteractData
).
toHaveBeenCalled
();
expect
(
directive
.
goBack
).
toHaveBeenCalled
();
expect
(
toasterService
.
error
).
toHaveBeenCalledWith
(
'
Could not add the activity. Try again later
'
);
});
it
(
'
should navigate to last url
'
,
()
=>
{
/** Arrange*/
const
navigationHelperService
=
TestBed
.
get
(
NavigationHelperService
);
spyOn
(
navigationHelperService
,
'
navigateToLastUrl
'
).
and
.
stub
();
/** Act */
directive
.
goBack
();
/** Assert */
expect
(
navigationHelperService
.
navigateToLastUrl
).
toHaveBeenCalled
();
});
it
(
'
should send interact data
'
,
()
=>
{
/** Arrange */
const
telemetryService
=
TestBed
.
get
(
TelemetryService
);
directive
.
groupAddableBlocData
=
{
pageIds
:
[
'
course
'
],
groupId
:
[
'
SOME_GROUP_ID
'
],
params
:
{
searchQuery
:
'
{"request":{"filters":{"contentType":["Course"],"status":["Live"],"objectType":["Content"]}}}
'
,
groupData
:
AddToGroupDirectiveMockData
.
groupData
,
contentType
:
'
Course
'
}
};
directive
.
identifier
=
'
do_12345
'
;
directive
.
pageId
=
'
course
'
;
const
telemetryData
=
{
context
:
{
env
:
'
groups
'
,
cdata
:
[{
type
:
_
.
get
(
directive
.
groupAddableBlocData
,
'
params.contentType
'
),
id
:
directive
.
identifier
}]
},
edata
:
{
id
:
'
add-to-group-button
'
,
type
:
'
CLICK
'
,
pageid
:
directive
.
pageId
}
};
spyOn
(
telemetryService
,
'
interact
'
);
/** Act */
directive
.
sendInteractData
();
/** Assert */
expect
(
telemetryService
.
interact
).
toHaveBeenCalledWith
(
telemetryData
);
});
it
(
'
should show the "Add to group button" if state has been set previously for a particular content type
'
,
()
=>
{
/** Arrange */
const
stateData
=
{
pageIds
:
[
'
course
'
],
groupId
:
[
'
SOME_GROUP_ID
'
],
params
:
{
searchQuery
:
'
{"request":{"filters":{"contentType":["Course"],"status":["Live"],"objectType":["Content"]}}}
'
,
groupData
:
AddToGroupDirectiveMockData
.
groupData
,
contentType
:
'
Course
'
}
};
directive
[
'
ref
'
]
=
TestBed
.
get
(
ElementRef
);
directive
.
pageId
=
'
course
'
;
spyOnProperty
<
any
>
(
CsGroupAddableBloc
.
instance
,
'
initialised
'
).
and
.
returnValue
(
true
);
spyOnProperty
<
any
>
(
CsGroupAddableBloc
.
instance
,
'
state$
'
).
and
.
returnValue
(
observableOf
(
stateData
));
/** Act */
directive
.
ngOnInit
();
/** Assert */
expect
(
directive
[
'
ref
'
].
nativeElement
.
style
.
display
).
toEqual
(
'
block
'
);
});
});
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets