Skip to content

Commit

Permalink
test: to simply smoketest
Browse files Browse the repository at this point in the history
  • Loading branch information
shuta13 committed Aug 26, 2022
1 parent 16d37b2 commit b761269
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/core/__tests__/smoke/dev-server/src/plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import EditorJS, {
API,
InlineToolConstructorOptions,
ToolConfig,
} from '@editorjs/editorjs';
import { h, useState, useEffect, createPlugin } from '../../../../src';
import type { PDJSX } from '../../../../src/';
Expand All @@ -10,24 +11,27 @@ const SampleWithHooks = () => {
console.log('render or re-render');

const [show, setShow] = useState(false);
const [value, setValue] = useState('');
const [text, setText] = useState('Ping');

const [api, setApi] = useState<API | null>(null);
const [toRed, setToRed] = useState(false);
const [config, setConfig] = useState<ToolConfig | null>(null);

useEffect(() => {
console.log('[useEffect] show: ', show);
console.log('[useEffect] show changed!: ', show);
}, [show]);

useEffect(() => {
console.log('[useEffect] text: ', text);
}, [text]);
console.log('[useEffect] value changed!: ', value);
}, [value]);

useEffect(() => {
console.log('[useEffect] api: ', api);
console.log('[useEffect] api changed!: ', api);
}, [api]);

const initializer = ({ api, config }: InlineToolConstructorOptions) => {
setApi(api);
setConfig(config);
};

const save = (blockContent: HTMLElement) => {
Expand All @@ -42,13 +46,14 @@ const SampleWithHooks = () => {

const handleChange = (e: Event) => {
if (e.target instanceof HTMLInputElement) {
setText(e.target.value);
setValue(e.target.value);
}
};

const handleSubmit = (e: Event) => {
console.log('[handleSubmit] text: ', text);
setText(value);
console.log('[handleSubmit] api: ', api);
console.log('[handleSubmit] config: ', config);
e.preventDefault();
};

Expand All @@ -64,6 +69,7 @@ const SampleWithHooks = () => {
<div>
<span style={{ cursor: 'pointer' }} onClick={handleClick}>
{text}
{show && <span>'clicked!'</span>}
</span>
<div
style={{
Expand All @@ -80,26 +86,18 @@ const SampleWithHooks = () => {
style={{
width: '100%',
padding: '8px',
color: toRed ? 'red' : 'green',
}}
onSubmit={handleSubmit}
>
<input
style={{ width: '100%' }}
onChange={handleChange}
value={text}
onChangeCapture={handleChange}
value={value}
/>
<input type="submit" value="Submit" />
</form>
</div>
{api && <pre>{api.styles.inlineToolButton}</pre>}
{show && <div>Pong</div>}
<button
onClick={() => setToRed((prevState) => !prevState)}
style={{ color: toRed ? 'red' : 'green' }}
>
BUTTON
</button>
</div>
</tool>
);
Expand Down

0 comments on commit b761269

Please sign in to comment.