Skip to content

Commit

Permalink
feat(metadata-sidebar): Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kajarosz committed Feb 14, 2025
1 parent 4e03b62 commit cf6cb7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/elements/content-sidebar/MetadataSidebarRedesign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { convertTemplateToTemplateInstance } from './utils/convertTemplateToTemp
import { isExtensionSupportedForMetadataSuggestions } from './utils/isExtensionSupportedForMetadataSuggestions';
import { metadataTaxonomyFetcher, metadataTaxonomyNodeAncestorsFetcher } from './fetchers/metadataTaxonomyFetcher';
import { useMetadataSidebarFilteredTemplates } from './hooks/useMetadataSidebarFilteredTemplates';
import { isFileLargerThan } from './utils/isFileLargerThan';

const MARK_NAME_JS_READY = `${ORIGIN_METADATA_SIDEBAR_REDESIGN}_${EVENT_JS_READY}`;

Expand Down Expand Up @@ -109,7 +110,7 @@ function MetadataSidebarRedesign({
const isBoxAiSuggestionsEnabled: boolean = useFeatureEnabled('metadata.aiSuggestions.enabled');
const isBetaLanguageEnabled: boolean = useFeatureEnabled('metadata.betaLanguage.enabled');

const isLargeFile = file ? file.size > 1000000 : false; // 1 MB = 1000000 bytes
const isLargeFile = isFileLargerThan(file, 1000000); // 1 MB = 1000000 bytes

const [editingTemplate, setEditingTemplate] = React.useState<MetadataTemplateInstance | null>(null);
const [isUnsavedChangesModalOpen, setIsUnsavedChangesModalOpen] = React.useState<boolean>(false);
Expand Down
15 changes: 15 additions & 0 deletions src/elements/content-sidebar/__tests__/isFileLargerThan.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isFileLargerThan } from '../utils/isFileLargerThan';

describe('isFileLargerThan', () => {
test.each([
[{ size: 49 }, 50, false],
[{ size: 50 }, 50, false],
[{ size: 51 }, 50, true],
[{}, 50, false],
[null, 50, false],
])('tete', (file, breakpoint, expected) => {
const result = isFileLargerThan(file, breakpoint);

expect(result).toEqual(expected);
});
});
5 changes: 5 additions & 0 deletions src/elements/content-sidebar/utils/isFileLargerThan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type BoxItem } from '../../../common/types/core';

export function isFileLargerThan(file: BoxItem, breakpoint: number): boolean {
return file ? file.size > breakpoint : false;
}

0 comments on commit cf6cb7b

Please sign in to comment.