1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-03 02:03:53 +00:00

update tests

This commit is contained in:
Jonathan Prusik
2025-10-20 12:40:39 -04:00
parent a15070f093
commit 7c07cbb145
6 changed files with 61 additions and 18 deletions

View File

@@ -148,7 +148,7 @@ describe("context-menu", () => {
const createdMenu = await sut.init();
expect(createdMenu).toBeTruthy();
expect(createSpy).toHaveBeenCalledTimes(10);
expect(createSpy).toHaveBeenCalledTimes(11);
});
it("has menu enabled and has premium", async () => {
@@ -156,7 +156,7 @@ describe("context-menu", () => {
const createdMenu = await sut.init();
expect(createdMenu).toBeTruthy();
expect(createSpy).toHaveBeenCalledTimes(11);
expect(createSpy).toHaveBeenCalledTimes(12);
});
it("has menu enabled and has premium, but card type is restricted", async () => {
@@ -166,7 +166,7 @@ describe("context-menu", () => {
const createdMenu = await sut.init();
expect(createdMenu).toBeTruthy();
expect(createSpy).toHaveBeenCalledTimes(10);
expect(createSpy).toHaveBeenCalledTimes(11);
});
it("has menu enabled, does not have premium, and card type is restricted", async () => {
billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(false));
@@ -174,7 +174,7 @@ describe("context-menu", () => {
const createdMenu = await sut.init();
expect(createdMenu).toBeTruthy();
expect(createSpy).toHaveBeenCalledTimes(9);
expect(createSpy).toHaveBeenCalledTimes(10);
});
});
@@ -283,7 +283,7 @@ describe("context-menu", () => {
await sut.removeBlockedUriMenuItems();
expect(MainContextMenuHandler["remove"]).toHaveBeenCalledTimes(5);
expect(MainContextMenuHandler["remove"]).toHaveBeenCalledTimes(6);
expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_ID);
expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_IDENTITY_ID);
expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_CARD_ID);

View File

@@ -19,7 +19,7 @@ describe("OverlayNotificationsContentService", () => {
beforeEach(() => {
jest.useFakeTimers();
jest.spyOn(utils, "sendExtensionMessage").mockImplementation(jest.fn());
jest.spyOn(utils, "sendExtensionMessage").mockImplementation(async () => null);
domQueryService = mock<DomQueryService>();
domElementVisibilityService = new DomElementVisibilityService();
overlayNotificationsContentService = new OverlayNotificationsContentService();

View File

@@ -747,6 +747,7 @@ describe("AutofillService", () => {
{
skipUsernameOnlyFill: autofillOptions.skipUsernameOnlyFill || false,
onlyEmptyFields: autofillOptions.onlyEmptyFields || false,
pageTargetingRules: {},
fillNewPassword: autofillOptions.fillNewPassword || false,
allowTotpAutofill: autofillOptions.allowTotpAutofill || false,
autoSubmitLogin: autofillOptions.allowTotpAutofill || false,

View File

@@ -431,7 +431,6 @@ export default class AutofillService implements AutofillServiceInterface {
*/
async doAutoFill(options: AutoFillOptions): Promise<string | null> {
const tab = options.tab;
const pageTargetingRules = await this.getPageTagetingRules(tab.url);
if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) {
throw new Error("Nothing to autofill.");
@@ -439,6 +438,7 @@ export default class AutofillService implements AutofillServiceInterface {
let totp: string | null = null;
const pageTargetingRules = await this.getPageTagetingRules(tab.url);
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
const canAccessPremium = await firstValueFrom(
this.billingAccountProfileStateService.hasPremiumFromAnySource$(activeAccount.id),
@@ -765,7 +765,7 @@ export default class AutofillService implements AutofillServiceInterface {
const filledFields: { [id: string]: AutofillField } = {};
const fields = options.cipher.fields;
const pageTargetedFields = Object.keys(
options.pageTargetingRules,
options.pageTargetingRules || {},
) as AutofillFieldQualifierType[];
const pageHasTargetingRules = !!pageTargetedFields.length;

View File

@@ -409,17 +409,57 @@ describe("InsertAutofillContentService", () => {
const scriptAction: FillScript = [action, opid, value];
jest.spyOn(insertAutofillContentService["autofillInsertActions"], action);
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
insertAutofillContentService["runFillScriptAction"](scriptAction, 0);
void insertAutofillContentService["runFillScriptAction"](scriptAction, 0);
jest.advanceTimersByTime(20);
expect(
insertAutofillContentService["autofillInsertActions"][action],
).toHaveBeenCalledWith({
opid,
value,
});
if (action === "fill_by_opid") {
expect(
insertAutofillContentService["autofillInsertActions"][action],
).toHaveBeenCalledWith({
opid,
value,
});
} else {
expect(
insertAutofillContentService["autofillInsertActions"][action],
).toHaveBeenCalledWith({
opid,
});
}
});
});
});
describe("given a valid fill script action and opid", () => {
const fillScriptActions: FillScriptActions[] = [
"fill_by_targeted_field_type",
"click_on_targeted_field_type",
"focus_by_targeted_field_type",
];
fillScriptActions.forEach((action) => {
it(`triggers a ${action} action`, () => {
const fieldType = "username";
const value = "value";
const scriptAction: FillScript = [action, fieldType, value];
jest.spyOn(insertAutofillContentService["autofillInsertActions"], action);
void insertAutofillContentService["runFillScriptAction"](scriptAction, 0);
jest.advanceTimersByTime(20);
if (action === "fill_by_targeted_field_type") {
expect(
insertAutofillContentService["autofillInsertActions"][action],
).toHaveBeenCalledWith({
fieldType,
value,
});
} else {
expect(
insertAutofillContentService["autofillInsertActions"][action],
).toHaveBeenCalledWith({
fieldType,
});
}
});
});
});

View File

@@ -154,7 +154,9 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
private accountService: AccountService,
) {
this.autofillTargetingRulesState = this.stateProvider.getActive(AUTOFILL_TARGETING_RULES);
this.autofillTargetingRules$ = this.autofillTargetingRulesState.state$.pipe(map((x) => (x && Object.keys(x).length) ? x : {}));
this.autofillTargetingRules$ = this.autofillTargetingRulesState.state$.pipe(
map((x) => (x && Object.keys(x).length ? x : {})),
);
this.showFaviconsState = this.stateProvider.getGlobal(SHOW_FAVICONS);
this.showFavicons$ = this.showFaviconsState.state$.pipe(map((x) => x ?? true));