Skip to content

Commit

Permalink
100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeamkd committed Jul 2, 2024
1 parent 033edd1 commit 2303518
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
31 changes: 31 additions & 0 deletions packages/abfy/src/__tests__/isVariant.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { isVariant } from "../utils";
import { ABFY_VARIANT } from "../utils/constants";

describe("isVariant function", () => {
it("should return false if the child doesnt have any props property", () => {
const child = React.createElement("div");
const result = isVariant(child);
expect(result).toBe(false);
});

it("should return flase if the child has props but no id", () => {
const child = React.createElement("div", {});
const result = isVariant(child);
expect(result).toBe(false);
});

it("should return false if the child has id prop set to different value", () => {
const child = React.createElement("div", { id: "someRandomValue" });

const result = isVariant(child);
expect(result).toBe(false);
});

it("should return true if the child has id prop set to different value", () => {
const child = React.createElement("div", { id: ABFY_VARIANT });

const result = isVariant(child);
expect(result).toBe(true);
});
});
6 changes: 3 additions & 3 deletions packages/abfy/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export const randomIdGenerator = (prefix?: string | null): string => {

export function getRenderId(): string | null {
try {
const localStorage = sessionStorage.getItem(ABFY_SESSION_STORAGE_KEY);
if (!localStorage) return null;
const storedData = JSON.parse(localStorage) || {};
const sessionData = sessionStorage.getItem(ABFY_SESSION_STORAGE_KEY);
if (!sessionData) return null;
const storedData = JSON.parse(sessionData) || {};
return storedData.renderId || null;
} catch (error) {
logger({
Expand Down
1 change: 0 additions & 1 deletion packages/abfy/src/utils/logger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const logger = (context: LoggerContext) => {
return console.warn(context.message, context.data);
default:
throw Error("Improper Log Input");
break;
}
} else {
if (context.level === LogLevels.ERROR) {
Expand Down

0 comments on commit 2303518

Please sign in to comment.