-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
586 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { | ||
setSchemaCurrentDefinitionName, | ||
SET_SCHEMA_CURRENT_DEFINITION_NAME | ||
} from '../../../../src/schema/data/actions'; | ||
|
||
describe( 'schema data store actions', () => { | ||
it( 'should export setSchemaCurrentDefinitionName()', () => { | ||
expect( setSchemaCurrentDefinitionName( 'foo' ) ).to.deep.equal( { | ||
type: SET_SCHEMA_CURRENT_DEFINITION_NAME, | ||
currentSchemaDefinitionName: 'foo' | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* global document, window */ | ||
|
||
import TestEditor from '../../../utils/testeditor'; | ||
import schemaReducer from '../../../../src/schema/data/reducer'; | ||
|
||
import { | ||
setSchemaCurrentDefinitionName | ||
} from '../../../../src/schema/data/actions'; | ||
|
||
import { | ||
setActiveTab, | ||
setEditors, | ||
setCurrentEditorName | ||
} from '../../../../src/data/actions'; | ||
|
||
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; | ||
|
||
describe( 'schema data store reducer', () => { | ||
let editorA, editorB; | ||
let elementA, elementB; | ||
let globalState, schemaState; | ||
|
||
beforeEach( async () => { | ||
window.localStorage.clear(); | ||
|
||
elementA = document.createElement( 'div' ); | ||
elementB = document.createElement( 'div' ); | ||
document.body.appendChild( elementA ); | ||
document.body.appendChild( elementB ); | ||
|
||
editorA = await TestEditor.create( elementA, { | ||
plugins: [ Paragraph ], | ||
initialData: '<p>foo</p>' | ||
} ); | ||
|
||
editorB = await TestEditor.create( elementB ); | ||
|
||
globalState = { | ||
currentEditorName: 'a', | ||
editors: new Map( [ | ||
[ 'a', editorA ], | ||
[ 'b', editorB ] | ||
] ), | ||
ui: { | ||
activeTab: 'Schema' | ||
} | ||
}; | ||
|
||
schemaState = schemaReducer( globalState, null, {} ); | ||
} ); | ||
|
||
afterEach( async () => { | ||
await editorA.destroy(); | ||
await editorB.destroy(); | ||
} ); | ||
|
||
it( 'should not create a state if ui#activeTab is different than "Schema"', () => { | ||
globalState.ui.activeTab = 'Model'; | ||
|
||
schemaState = schemaReducer( globalState, null, {} ); | ||
|
||
expect( schemaState ).to.be.null; | ||
} ); | ||
|
||
it( 'should create a default state if no schema state was passed to the reducer', () => { | ||
schemaState = schemaReducer( globalState, null, {} ); | ||
|
||
expect( schemaState ).to.have.property( 'treeDefinition' ); | ||
expect( schemaState ).to.have.property( 'currentSchemaDefinitionName' ); | ||
expect( schemaState ).to.have.property( 'currentSchemaDefinition' ); | ||
} ); | ||
|
||
it( 'should pass through when no action was passed to the reducer', () => { | ||
schemaState = schemaReducer( globalState, { | ||
treeDefinition: [ 'foo' ], | ||
currentSchemaDefinitionName: 'bar', | ||
currentSchemaDefinition: 'baz' | ||
}, {} ); | ||
|
||
expect( schemaState.treeDefinition ).to.deep.equal( [ 'foo' ] ); | ||
expect( schemaState.currentSchemaDefinitionName ).to.equal( 'bar' ); | ||
expect( schemaState.currentSchemaDefinition ).to.equal( 'baz' ); | ||
} ); | ||
|
||
describe( 'application state', () => { | ||
describe( '#currentSchemaDefinitionName', () => { | ||
it( 'should be reset on setEditors() action', () => { | ||
schemaState.currentSchemaDefinitionName = 'paragraph'; | ||
schemaState = schemaReducer( globalState, schemaState, setEditors( new Map( [ [ 'b', editorB ] ] ) ) ); | ||
|
||
expect( schemaState.currentSchemaDefinitionName ).to.be.null; | ||
} ); | ||
|
||
it( 'should be reset on setCurrentEditorName() action', () => { | ||
schemaState.currentSchemaDefinitionName = null; | ||
schemaState = schemaReducer( globalState, schemaState, setCurrentEditorName( 'b' ) ); | ||
|
||
expect( schemaState.currentSchemaDefinitionName ).to.be.null; | ||
} ); | ||
|
||
it( 'should be set on setSchemaCurrentDefinitionName() action', () => { | ||
schemaState.currentSchemaDefinitionName = null; | ||
schemaState = schemaReducer( globalState, schemaState, setSchemaCurrentDefinitionName( 'paragraph' ) ); | ||
|
||
expect( schemaState.currentSchemaDefinitionName ).to.equal( 'paragraph' ); | ||
} ); | ||
} ); | ||
|
||
describe( '#currentSchemaDefinition', () => { | ||
it( 'should be reset on setEditors() action', () => { | ||
schemaState.currentSchemaDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setEditors( new Map( [ [ 'b', editorB ] ] ) ) ); | ||
|
||
expect( schemaState.currentSchemaDefinition ).to.be.null; | ||
} ); | ||
|
||
it( 'should be reset on setCurrentEditorName() action', () => { | ||
schemaState.currentSchemaDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setCurrentEditorName( 'b' ) ); | ||
|
||
expect( schemaState.currentSchemaDefinition ).to.be.null; | ||
} ); | ||
|
||
it( 'should be set on setSchemaCurrentDefinitionName() action', () => { | ||
schemaState.currentSchemaDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setSchemaCurrentDefinitionName( 'paragraph' ) ); | ||
|
||
expect( schemaState.currentSchemaDefinition ).to.be.an( 'object' ); | ||
} ); | ||
|
||
it( 'should be set on setActiveTab() action', () => { | ||
schemaState.currentSchemaDefinitionName = 'paragraph'; | ||
schemaState.currentSchemaDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setActiveTab( 'Schema' ) ); | ||
|
||
expect( schemaState.currentSchemaDefinition ).to.be.an( 'object' ); | ||
} ); | ||
} ); | ||
|
||
describe( '#treeDefinition', () => { | ||
it( 'should be empty if there are no editors', () => { | ||
schemaState.treeDefinition = null; | ||
|
||
globalState.editors = new Map(); | ||
globalState.currentEditorName = null; | ||
|
||
schemaState = schemaReducer( globalState, schemaState, setEditors( new Map() ) ); | ||
|
||
expect( schemaState.treeDefinition ).to.be.an( 'array' ); | ||
expect( schemaState.treeDefinition ).to.have.length( 0 ); | ||
} ); | ||
|
||
it( 'should be set on setEditors() action', () => { | ||
schemaState.treeDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setEditors( new Map( [ [ 'b', editorB ] ] ) ) ); | ||
|
||
expect( schemaState.treeDefinition ).to.be.an( 'array' ); | ||
} ); | ||
|
||
it( 'should be set on setCurrentEditorName() action', () => { | ||
schemaState.treeDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setCurrentEditorName( 'b' ) ); | ||
|
||
expect( schemaState.treeDefinition ).to.be.an( 'array' ); | ||
} ); | ||
|
||
it( 'should be set on setActiveTab() action', () => { | ||
schemaState.treeDefinition = null; | ||
schemaState = schemaReducer( globalState, schemaState, setActiveTab( 'Commands' ) ); | ||
|
||
expect( schemaState.treeDefinition ).to.be.an( 'array' ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* global document, window */ | ||
|
||
import React from 'react'; | ||
import TestEditor from '../../utils/testeditor'; | ||
import { createStore } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import SchemaPane from '../../../src/schema/pane'; | ||
import SchemaTree from '../../../src/schema/tree'; | ||
import SchemaDefinitionInspector from '../../../src/schema/schemadefinitioninspector'; | ||
|
||
describe( '<SchemaPane />', () => { | ||
let editor, wrapper, element, store; | ||
|
||
beforeEach( () => { | ||
window.localStorage.clear(); | ||
|
||
element = document.createElement( 'div' ); | ||
document.body.appendChild( element ); | ||
|
||
return TestEditor.create( element ).then( newEditor => { | ||
editor = newEditor; | ||
|
||
store = createStore( state => state, { | ||
editors: new Map( [ [ 'test-editor', editor ] ] ), | ||
currentEditorName: 'test-editor', | ||
ui: { | ||
activeTab: 'Schema' | ||
}, | ||
schema: { | ||
} | ||
} ); | ||
|
||
wrapper = mount( <Provider store={store}><SchemaPane /></Provider> ); | ||
} ); | ||
} ); | ||
|
||
afterEach( () => { | ||
wrapper.unmount(); | ||
element.remove(); | ||
|
||
return editor.destroy(); | ||
} ); | ||
|
||
describe( 'render()', () => { | ||
it( 'renders a placeholder when no props#currentEditorName', () => { | ||
store = createStore( state => state, { | ||
currentEditorName: null, | ||
model: { | ||
ui: {} | ||
} | ||
} ); | ||
|
||
const wrapper = mount( <Provider store={store}><SchemaPane /></Provider> ); | ||
|
||
expect( wrapper.text() ).to.match( /^Nothing to show/ ); | ||
|
||
wrapper.unmount(); | ||
} ); | ||
|
||
it( 'should render <Tabs>', () => { | ||
const tabs = wrapper.find( 'Tabs' ); | ||
|
||
expect( tabs ).to.have.length( 1 ); | ||
expect( tabs.props().activeTab ).to.equal( 'Inspect' ); | ||
} ); | ||
|
||
it( 'should render a <SchemaTree/>', () => { | ||
expect( wrapper.find( SchemaTree ) ).to.have.length( 1 ); | ||
} ); | ||
|
||
it( 'should render a <SchemaDefinitionInspector/>', () => { | ||
expect( wrapper.find( SchemaDefinitionInspector ) ).to.have.length( 1 ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.