mirror of
https://github.com/bitwarden/browser
synced 2026-02-02 17:53:41 +00:00
cleanup
This commit is contained in:
@@ -700,6 +700,11 @@ describe("NotificationBackground", () => {
|
||||
let getAllDecryptedForUrlSpy: jest.SpyInstance;
|
||||
const mockFormattedURI = "archive.org";
|
||||
const mockFormURI = "https://www.archive.org";
|
||||
const expectSkippedCheckingNotification = () => {
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
tab = createChromeTabMock();
|
||||
@@ -749,9 +754,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if the passed url is not valid", async () => {
|
||||
@@ -774,9 +777,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if the user has disabled both the new login and update password notification", async () => {
|
||||
@@ -798,9 +799,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if the user is logged out", async () => {
|
||||
@@ -820,9 +819,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if there is no active account", async () => {
|
||||
@@ -842,9 +839,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if the values for the `password` and `newPassword` fields match (no change)", async () => {
|
||||
@@ -863,9 +858,7 @@ describe("NotificationBackground", () => {
|
||||
|
||||
await notificationBackground.triggerCipherNotification(formEntryData, tab);
|
||||
|
||||
expect(getAllDecryptedForUrlSpy).not.toHaveBeenCalled();
|
||||
expect(pushChangePasswordToQueueSpy).not.toHaveBeenCalled();
|
||||
expect(pushAddLoginToQueueSpy).not.toHaveBeenCalled();
|
||||
expectSkippedCheckingNotification();
|
||||
});
|
||||
|
||||
it("skips checking if a notification should trigger if the vault is locked and there is no value for the `newPassword` field", async () => {
|
||||
|
||||
@@ -800,36 +800,24 @@ export default class NotificationBackground {
|
||||
},
|
||||
);
|
||||
|
||||
let inputScenario = null;
|
||||
// Handle different field fill combinations and determine the input scenario
|
||||
const inputScenariosByKey = {
|
||||
upn: inputScenarios.usernamePasswordNewPassword,
|
||||
un: inputScenarios.usernameNewPassword,
|
||||
up: inputScenarios.usernamePassword,
|
||||
u: inputScenarios.username,
|
||||
pn: inputScenarios.passwordNewPassword,
|
||||
n: inputScenarios.newPassword,
|
||||
p: inputScenarios.password,
|
||||
} as const;
|
||||
|
||||
// Handle different field fill combinations
|
||||
if (currentPasswordFieldHasValue && newPasswordFieldHasValue && usernameFieldHasValue) {
|
||||
inputScenario = inputScenarios.usernamePasswordNewPassword;
|
||||
} else if (newPasswordFieldHasValue && usernameFieldHasValue && !currentPasswordFieldHasValue) {
|
||||
inputScenario = inputScenarios.usernameNewPassword;
|
||||
} else if (
|
||||
usernameFieldHasValue &&
|
||||
!currentPasswordFieldHasValue &&
|
||||
!newPasswordFieldHasValue
|
||||
) {
|
||||
inputScenario = inputScenarios.username;
|
||||
} else if (currentPasswordFieldHasValue && newPasswordFieldHasValue && !usernameFieldHasValue) {
|
||||
inputScenario = inputScenarios.passwordNewPassword;
|
||||
} else if (
|
||||
currentPasswordFieldHasValue &&
|
||||
!newPasswordFieldHasValue &&
|
||||
!usernameFieldHasValue
|
||||
) {
|
||||
inputScenario = inputScenarios.password;
|
||||
} else if (currentPasswordFieldHasValue && usernameFieldHasValue && !newPasswordFieldHasValue) {
|
||||
inputScenario = inputScenarios.usernamePassword;
|
||||
} else if (
|
||||
newPasswordFieldHasValue &&
|
||||
!currentPasswordFieldHasValue &&
|
||||
!usernameFieldHasValue
|
||||
) {
|
||||
inputScenario = inputScenarios.newPassword;
|
||||
}
|
||||
type InputScenarioKeys = keyof typeof inputScenariosByKey;
|
||||
|
||||
const key = ((usernameFieldHasValue ? "u" : "") +
|
||||
(currentPasswordFieldHasValue ? "p" : "") +
|
||||
(newPasswordFieldHasValue ? "n" : "")) as InputScenarioKeys;
|
||||
|
||||
const inputScenario = key in inputScenariosByKey ? inputScenariosByKey[key] : null;
|
||||
|
||||
if (inputScenario) {
|
||||
return await this.handleInputMatchScenario({
|
||||
|
||||
Reference in New Issue
Block a user