Test Classpublic ConnectApi.TopicPage feedItemPage{get;set;}
public CommunityGroupPage()
{
// Chatter Group Id
Id groupid = apexpages.currentpage().getparameters().get('id');
/ pull all chatter groups, faster than individual queries + 1 SOQL
chatterGroups = [SELECT id, Name, NetworkId FROM CollaborationGroup where id =: groupid Limit 1];
String comid;
String grpid;
if(chatterGroups.Size() > 0)
{
comid = chatterGroups[0].NetworkId;
grpid = chatterGroups[0].Id;
}
//This will be used to fetch Recently Talking about topics for current chatter group
feedItemPage = ConnectApi.Topics.getRecentlyTalkingAboutTopicsForGroup(comId,grpid);
}
Please help me to fix this issue.Thanks,AMit Singh**
* An apex page controller that exposes the Chatter Group Page functionality
*/
@IsTest global with sharing class CommunityGroupPageTest {
@IsTest(SeeAllData=true) global static void testCommunityGroupPage () {
// Instantiate a new controller with all parameters in the page
Network community;
String communityId;
Id currentUserId = UserInfo.getUserId();
User usr = [select id,Name from User where id =: currentUserId];
System.runAs(usr) {
community = [SELECT id, Name,OptionsReputationEnabled FROM Network where name =: 'Customer Community'];
communityId = community.id;
collaborationgroup cg = new collaborationgroup(name ='ChatterGroupPage',CollaborationType='Public',OwnerId=currentUserId,NetworkId=communityId);
insert cg;
PageReference pageRef = Page.CommunityChatterPage;
Test.setCurrentPage(pageRef);//Applying page context here
// Add parameters to page URL
ApexPages.currentPage().getParameters().put('id', cg.id);//Observe how helpful it was to set the parameters in your page from Unit test
CommunityGroupPage controller = new CommunityGroupPage ();
controller.groupid = System.currentPagereference().getParameters().get('id');
ConnectApi.TopicPage testPage = new ConnectApi.TopicPage();
List<ConnectApi.Topic> testItemList = new List<ConnectApi.Topic>();
testItemList.add(new ConnectApi.Topic());
testItemList.add(new ConnectApi.Topic());
testPage.topics = testItemList;
ConnectApi.Topics.setTestGetRecentlyTalkingAboutTopicsForGroup(communityId, cg.id, testPage);
ConnectApi.Topics.getRecentlyTalkingAboutTopicsForGroup(communityId,cg.id);
}
}
}
You need to register the test stub by calling ConnectApi.Topics.setTestGetRecentlyTalkingAboutTopicsForGroup(communityId, cg.id, testPage) before you create the CommunityGroupPage controller, because it's the CommunityGroupPage constructor that calls ConnectApi.Topics.getRecentlyTalkingAboutTopicsForGroup(comId,grpid).Also, line 38 in your test should be deleted. You're already calling that method when you call the CommunityGroupPage constructor.