Skip to content

Commit

Permalink
feat: rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tiavina-mika committed Jun 18, 2024
1 parent 068d765 commit 669e966
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/PasswordStrengthInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconButton, TextFieldProps, TextField, Theme, useTheme, List, ListItem,

import VisibilityOff from './icons/VisibilityOff';
import Visibility from './icons/Visibility';
import { getPasswordScoreAndCriteria } from './utils';
import { getPasswordChecklist } from './utils';
import Check from './icons/Check';
import Close from './icons/Close';

Expand Down Expand Up @@ -66,7 +66,7 @@ const PasswordStrengthInput = forwardRef<HTMLDivElement, PasswordStrengthInputP
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;

const result = getPasswordScoreAndCriteria(value, errorMessages);
const result = getPasswordChecklist(value, errorMessages);
console.log(value, result);
const newErrors = result.errorMessages || [];
setErrors(newErrors);
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// import {describe, expect, test} from '@jest/globals';

import { getPasswordScoreAndCriteria } from "../utils";
import { getPasswordChecklist } from "../utils";

// ------------ default options ------------ //
describe('check password', () => {
test('check min length', () => {
const { allChecksPassed, errorMessages } = getPasswordScoreAndCriteria('abcde')
const { allChecksPassed, errorMessages } = getPasswordChecklist('abcde')
expect(allChecksPassed).toBe(false);
const currentPassed = errorMessages.find((error) => error.key === 'lowerCase');
expect(currentPassed?.pass).toBe(true);
});

test('check two passed check', () => {
const { allChecksPassed, errorMessages } = getPasswordScoreAndCriteria('abcde8')
const { allChecksPassed, errorMessages } = getPasswordChecklist('abcde8')
expect(allChecksPassed).toBe(false);
const passedChecks = errorMessages.filter((error) => error.key && ['lowerCase', 'number'].includes(error.key));
expect(passedChecks?.length).toBe(2);
});

test('check all checks passed', () => {
const { allChecksPassed, errorMessages } = getPasswordScoreAndCriteria('abcde8=F')
const { allChecksPassed, errorMessages } = getPasswordChecklist('abcde8=F')
expect(allChecksPassed).toBe(true);
expect(errorMessages?.length).toBe(5);
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ type Checks = {
pass: boolean;
key: keyof ComplexPasswordErrors;
}
type PasswordScoreAndCriteria = {
type PasswordCheckList = {
errorMessages: PasswordsComplexityPass[];
allChecksPassed: boolean;
}
export const getPasswordScoreAndCriteria = (password: string, message?: ErrorMessages): PasswordScoreAndCriteria => {
export const getPasswordChecklist = (password: string, message?: ErrorMessages): PasswordCheckList => {
const {
minLength = "Must be at least 8 characters",
lowerCase = "Must contain at least one lowercase letter",
Expand Down

0 comments on commit 669e966

Please sign in to comment.