function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Moritz MuellerMoritz Mueller 

Custom list view test class

Hi,

Am struggling to get a test class for the following custom list view and hoping for some input here, apex;
 
public with sharing class RecentTechnicalBulletinsHomePage {
  @AuraEnabled
  public static List<Knowledge__kav> getArticles(){
	return [Select Id, Title, LastModifiedDate From Knowledge__kav Where RecordTypeId = '0121k000000CipgAAC' ORDER BY LastModifiedDate DESC LIMIT 10];
  }
}

Now my test class looks as follows;
 
@isTest
public class RecentTechnicalBulletinsHomePageTest
{
@testSetup
static void createArticle(){
    List<Knowledge__kav> testArt = new List<Knowledge__kav>();
            for(Integer i=0;i<10;i++) {
            testArt.add(new Knowledge__kav(Title = 'TestArt'+i));
        }
    insert testArt;
}
public static testMethod void getListView(){
        
	
     } 
}

I am just not sure what method to look for and what to test really.

Any direction/input is highly appreciated! 
Best Answer chosen by Moritz Mueller
bhanu_prakashbhanu_prakash
Hi,
Mark as best answer, If it resloves !!​
class
public class ListArticleController {
    @AuraEnabled
    public static List <Knowledge__kav> getKnowledgeArticleitem() {
        return [SELECT ArchivedById,ArchivedDate,ArticleArchivedById,ArticleArchivedDate,ArticleCaseAttachCount,ArticleCreatedById,ArticleCreatedDate,ArticleMasterLanguage,ArticleNumber,ArticleTotalViewCount,AssignedById,AssignedToId,AssignmentDate,AssignmentDueDate,AssignmentNote,CreatedById,CreatedDate,FirstPublishedDate,Id,IsDeleted,IsLatestVersion,IsVisibleInApp,IsVisibleInCsp,IsVisibleInPkb,IsVisibleInPrm,KnowledgeArticleId,Language,LastModifiedById,LastModifiedDate,LastPublishedDate,MigratedToFromArticleVersion,OwnerId,PublishStatus,SourceId,Summary,SystemModstamp,Title,UrlName,VersionNumber 
                FROM Knowledge__kav LIMIT 5];
    }
    
}

Test class
 
@isTest
public class ListArticleControllerTest{
   
    static testmethod void createArticle(){
        List<Knowledge__kav> testArt = new List<Knowledge__kav>();
        for(Integer i=0;i<10;i++) {
            testArt.add(new Knowledge__kav(Title = 'TestArt'+i, UrlName ='TestArt'+i ));
        }
        insert testArt;
        
        test.starttest();
        update testArt;
        ListArticleController.getKnowledgeArticleitem();
        test.stopTest();
       
    }

}

Mark as resloved if it helps :) :)​
Thanks, 
Bhanu Prakash
visit ForceLearn.com

All Answers

bhanu_prakashbhanu_prakash
Hi,
Mark as best answer, If it resloves !!​
class
public class ListArticleController {
    @AuraEnabled
    public static List <Knowledge__kav> getKnowledgeArticleitem() {
        return [SELECT ArchivedById,ArchivedDate,ArticleArchivedById,ArticleArchivedDate,ArticleCaseAttachCount,ArticleCreatedById,ArticleCreatedDate,ArticleMasterLanguage,ArticleNumber,ArticleTotalViewCount,AssignedById,AssignedToId,AssignmentDate,AssignmentDueDate,AssignmentNote,CreatedById,CreatedDate,FirstPublishedDate,Id,IsDeleted,IsLatestVersion,IsVisibleInApp,IsVisibleInCsp,IsVisibleInPkb,IsVisibleInPrm,KnowledgeArticleId,Language,LastModifiedById,LastModifiedDate,LastPublishedDate,MigratedToFromArticleVersion,OwnerId,PublishStatus,SourceId,Summary,SystemModstamp,Title,UrlName,VersionNumber 
                FROM Knowledge__kav LIMIT 5];
    }
    
}

Test class
 
@isTest
public class ListArticleControllerTest{
   
    static testmethod void createArticle(){
        List<Knowledge__kav> testArt = new List<Knowledge__kav>();
        for(Integer i=0;i<10;i++) {
            testArt.add(new Knowledge__kav(Title = 'TestArt'+i, UrlName ='TestArt'+i ));
        }
        insert testArt;
        
        test.starttest();
        update testArt;
        ListArticleController.getKnowledgeArticleitem();
        test.stopTest();
       
    }

}

Mark as resloved if it helps :) :)​
Thanks, 
Bhanu Prakash
visit ForceLearn.com
This was selected as the best answer
Moritz MuellerMoritz Mueller
That did work indeed, thanks a bunch. Extemely fast response haha