refactor: component manager usecases (#2354)

This commit is contained in:
Mo
2023-07-13 05:46:52 -05:00
committed by GitHub
parent ecc5b5e503
commit 2c68ea1d76
52 changed files with 1454 additions and 1078 deletions

View File

@@ -9,6 +9,7 @@ import { experimentalFeatures } from '../Lists/ExperimentalFeatures'
import { IframeEditors } from '../Lists/IframeEditors'
import { themes } from '../Lists/Themes'
import { nativeEditors } from '../Lists/NativeEditors'
import { IframeComponentFeatureDescription } from './IframeComponentFeatureDescription'
export function GetFeatures(): AnyFeatureDescription[] {
return [
@@ -30,10 +31,14 @@ export function FindNativeTheme(identifier: FeatureIdentifier): ThemeFeatureDesc
return themes().find((t) => t.identifier === identifier)
}
export function GetIframeAndNativeEditors(): EditorFeatureDescription[] {
export function GetIframeAndNativeEditors(): (IframeComponentFeatureDescription | EditorFeatureDescription)[] {
return [...IframeEditors(), ...nativeEditors()]
}
export function GetIframeEditors(): IframeComponentFeatureDescription[] {
return IframeEditors()
}
export function GetSuperNoteFeature(): EditorFeatureDescription {
return FindNativeFeature(FeatureIdentifier.SuperEditor) as EditorFeatureDescription
}

View File

@@ -0,0 +1,63 @@
import { ContentType } from '@standardnotes/domain-core'
import { AnyFeatureDescription } from './AnyFeatureDescription'
import { ComponentArea } from '../Component/ComponentArea'
import {
isThemeFeatureDescription,
isIframeComponentFeatureDescription,
isEditorFeatureDescription,
} from './TypeGuards'
import { ThemeFeatureDescription } from './ThemeFeatureDescription'
import { IframeComponentFeatureDescription } from './IframeComponentFeatureDescription'
describe('TypeGuards', () => {
describe('isThemeFeatureDescription', () => {
it('should return true if feature is ThemeFeatureDescription', () => {
const feature = {
content_type: ContentType.TYPES.Theme,
} as jest.Mocked<ThemeFeatureDescription>
expect(isThemeFeatureDescription(feature)).toBe(true)
})
it('should return false if feature is not ThemeFeatureDescription', () => {
const feature = {
content_type: ContentType.TYPES.Component,
} as jest.Mocked<ThemeFeatureDescription>
expect(isThemeFeatureDescription(feature)).toBe(false)
})
})
describe('isIframeComponentFeatureDescription', () => {
it('should return true if feature is IframeComponentFeatureDescription', () => {
const feature = {
content_type: ContentType.TYPES.Component,
area: ComponentArea.Editor,
} as jest.Mocked<IframeComponentFeatureDescription>
expect(isIframeComponentFeatureDescription(feature)).toBe(true)
})
it('should return false if feature is not IframeComponentFeatureDescription', () => {
const feature = {
content_type: ContentType.TYPES.Theme,
} as jest.Mocked<IframeComponentFeatureDescription>
expect(isIframeComponentFeatureDescription(feature)).toBe(false)
})
})
describe('isEditorFeatureDescription', () => {
it('should return true if feature is EditorFeatureDescription', () => {
const feature = {
note_type: 'test',
area: ComponentArea.Editor,
} as unknown as jest.Mocked<AnyFeatureDescription>
expect(isEditorFeatureDescription(feature)).toBe(true)
})
it('should return false if feature is not EditorFeatureDescription', () => {
const feature = {
content_type: ContentType.TYPES.Theme,
} as jest.Mocked<AnyFeatureDescription>
expect(isEditorFeatureDescription(feature)).toBe(false)
})
})
})