Skip to content

Commit dd05372

Browse files
committed
PB-54921 - Browser extension - toolbar badge counts notes and custom fields suggested for the current tab
1 parent 0063fb4 commit dd05372

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/shared/models/entity/resourceType/resourceTypesCollection.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ class ResourceTypesCollection extends EntityV2Collection {
131131
);
132132
}
133133

134+
/**
135+
* Filter by resource types supported by the quick access.
136+
* @return {void} The function alters the collection itself.
137+
*/
138+
filterByQuickAccessResourceTypes() {
139+
this.filterByCallback((resourceType) => resourceType.isSupportedByQuickAccess());
140+
}
141+
134142
/**
135143
* Filter by resource type version.
136144
* @param {string} version the version used to filter the resource types

‎src/shared/models/entity/resourceType/resourceTypesCollection.test.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
3941
import CollectionValidationError from "../../entity/abstract/collectionValidationError";
4042
import { v4 as uuid } from "uuid";
4143
import {
@@ -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

Comments
 (0)