@@ -35,7 +35,9 @@ import {
3535 resourceTypeV5DefaultDto ,
3636 TEST_RESOURCE_TYPE_V5_STANDALONE_NOTE ,
3737 TEST_RESOURCE_TYPE_V5_STANDALONE_PIN_CODE ,
38+ TEST_RESOURCE_TYPE_V5_CUSTOM_FIELDS ,
3839} from "./resourceTypeEntity.test.data" ;
40+ import ResourceTypeEntity from "./resourceTypeEntity" ;
3941import CollectionValidationError from "../../entity/abstract/collectionValidationError" ;
4042import { v4 as uuid } from "uuid" ;
4143import {
@@ -183,6 +185,38 @@ describe("ResourceTypesCollection", () => {
183185 } ) ;
184186 } ) ;
185187
188+ describe ( "::filterByQuickAccessResourceTypes" , ( ) => {
189+ it ( "should keep the password, TOTP, PIN code, note and custom fields resource types." , ( ) => {
190+ expect . assertions ( 12 ) ;
191+ const resourceTypes = new ResourceTypesCollection ( resourceTypesCollectionDto ( ) ) ;
192+ resourceTypes . filterByQuickAccessResourceTypes ( ) ;
193+ expect ( resourceTypes ) . toHaveLength ( 11 ) ;
194+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_PASSWORD_STRING ) ) . toBeTruthy ( ) ;
195+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION ) ) . toBeTruthy ( ) ;
196+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP ) ) . toBeTruthy ( ) ;
197+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_TOTP ) ) . toBeTruthy ( ) ;
198+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_DEFAULT ) ) . toBeTruthy ( ) ;
199+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_PASSWORD_STRING ) ) . toBeTruthy ( ) ;
200+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_DEFAULT_TOTP ) ) . toBeTruthy ( ) ;
201+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_TOTP ) ) . toBeTruthy ( ) ;
202+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_STANDALONE_PIN_CODE ) ) . toBeTruthy ( ) ;
203+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_STANDALONE_NOTE ) ) . toBeTruthy ( ) ;
204+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_CUSTOM_FIELDS ) ) . toBeTruthy ( ) ;
205+ } ) ;
206+
207+ it ( "should drop the resource types the quick access does not support." , ( ) => {
208+ expect . assertions ( 2 ) ;
209+ const spy = jest . spyOn ( ResourceTypeEntity . prototype , "isSupportedByQuickAccess" ) . mockImplementation ( function ( ) {
210+ return ! this . isStandaloneNote ( ) ;
211+ } ) ;
212+ const resourceTypes = new ResourceTypesCollection ( resourceTypesCollectionDto ( ) ) ;
213+ resourceTypes . filterByQuickAccessResourceTypes ( ) ;
214+ expect ( resourceTypes ) . toHaveLength ( 10 ) ;
215+ expect ( resourceTypes . getFirstById ( TEST_RESOURCE_TYPE_V5_STANDALONE_NOTE ) ) . toBeUndefined ( ) ;
216+ spy . mockRestore ( ) ;
217+ } ) ;
218+ } ) ;
219+
186220 describe ( "::filterByResourceTypeVersion" , ( ) => {
187221 it ( "should filter the collection by resources types by the version 4." , ( ) => {
188222 expect . assertions ( 9 ) ;
0 commit comments