Skip to content

Commit 3a79d1d

Browse files
committed
minimal test fail message
Signed-off-by: shmck <[email protected]>
1 parent e9b4c5d commit 3a79d1d

File tree

8 files changed

+87
-110
lines changed

8 files changed

+87
-110
lines changed

web-app/src/components/ProcessMessages/TestMessage.tsx

-46
This file was deleted.

web-app/src/components/ProcessMessages/index.tsx

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import Message from '../Message'
22
import * as React from 'react'
33
import * as T from 'typings'
4-
import Button from '../Button'
54
import { css, jsx } from '@emotion/core'
6-
import TestMessage from './TestMessage'
75

86
interface Props {
9-
testStatus?: T.TestStatus | null
107
processes: T.ProcessEvent[]
11-
onOpenLogs?: (channel: string) => void
128
}
139

1410
const styles = {
@@ -19,22 +15,7 @@ const styles = {
1915
}
2016

2117
// display a list of active processes
22-
const ProcessMessages = ({ processes, testStatus, onOpenLogs }: Props) => {
23-
if (testStatus) {
24-
return (
25-
<TestMessage {...testStatus}>
26-
{testStatus.type === 'warning' ? (
27-
<Button
28-
onClick={() => onOpenLogs && onOpenLogs('CodeRoad (Tests)')}
29-
type="normal"
30-
style={{ marginTop: '0.8rem' }}
31-
>
32-
Open Logs
33-
</Button>
34-
) : null}
35-
</TestMessage>
36-
)
37-
}
18+
const ProcessMessages = ({ processes }: Props) => {
3819
if (!processes.length) {
3920
return null
4021
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as React from 'react'
2+
import Icon from '../Icon'
3+
import { css, jsx } from '@emotion/core'
4+
5+
const styles = {
6+
container: {
7+
backgroundColor: '#fff3e0',
8+
padding: '0.5rem',
9+
animationDuration: '0.3s',
10+
animationTimingFunction: 'ease-in-out',
11+
borderTopLeftRadius: '4px',
12+
borderTopRightRadius: '4px',
13+
color: 'rgb(51, 51, 51)',
14+
fontSize: '0.8rem',
15+
},
16+
icon: {
17+
color: '#ff9300',
18+
},
19+
content: {
20+
marginLeft: '0.5rem',
21+
},
22+
}
23+
24+
interface Props {
25+
message?: string
26+
}
27+
28+
const TestMessage = (props: Props) => {
29+
const [visible, setVisible] = React.useState(true)
30+
31+
React.useEffect(() => {
32+
setVisible(true)
33+
const timeout = setTimeout(() => {
34+
setVisible(false)
35+
}, 4500)
36+
return () => {
37+
clearTimeout(timeout)
38+
}
39+
}, [props.message])
40+
41+
return visible && props.message ? (
42+
<div css={styles.container}>
43+
<Icon type="warning" style={styles.icon} size="xs" />
44+
<span css={styles.content}>{props.message}</span>
45+
</div>
46+
) : null
47+
}
48+
49+
export default TestMessage

web-app/src/containers/Tutorial/components/Level.tsx

+21-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Icon from '../../../components/Icon'
77
import Button from '../../../components/Button'
88
import Markdown from '../../../components/Markdown'
99
import ProcessMessages from '../../../components/ProcessMessages'
10+
import TestMessage from '../../../components/TestMessage'
1011
import ContentMenu from './ContentMenu'
1112
import Step from './Step'
1213
import { DISPLAY_RUN_TEST_BUTTON } from '../../../environment'
@@ -58,15 +59,17 @@ const styles = {
5859
processes: {
5960
padding: '0 1rem',
6061
position: 'fixed' as 'fixed',
61-
bottom: '4rem',
62+
bottom: '2rem',
6263
left: 0,
6364
right: 0,
65+
top: 'auto',
6466
},
65-
nux: {
66-
position: 'fixed' as 'fixed',
67+
testMessage: {
68+
position: 'absolute' as 'absolute',
69+
top: 'auto',
6770
bottom: '2rem',
68-
left: 0,
69-
right: 0,
71+
left: '5px',
72+
right: '5px',
7073
},
7174
footer: {
7275
display: 'flex' as 'flex',
@@ -119,8 +122,6 @@ const Level = ({
119122
}: Props) => {
120123
const level: TT.Level = tutorial.levels[index]
121124

122-
console.log(level)
123-
124125
const [title, setTitle] = React.useState<string>(level.title)
125126
const [content, setContent] = React.useState<string>(level.content)
126127

@@ -230,13 +231,20 @@ const Level = ({
230231

231232
<div ref={pageBottomRef} />
232233

233-
{((testStatus && testStatus.type !== 'hidden') || processes.length > 0) && (
234-
<div css={styles.processes}>
235-
<ProcessMessages processes={processes} testStatus={testStatus} onOpenLogs={onOpenLogs} />
236-
</div>
237-
)}
238-
239234
<div css={styles.footer}>
235+
{/* Process Modal */}
236+
{processes.length > 0 && (
237+
<div css={styles.processes}>
238+
<ProcessMessages processes={processes} />
239+
</div>
240+
)}
241+
{/* Test Fail Modal */}
242+
{testStatus && testStatus.type === 'warning' && (
243+
<div css={styles.testMessage}>
244+
<TestMessage message={testStatus.title} />
245+
</div>
246+
)}
247+
240248
{DISPLAY_RUN_TEST_BUTTON && status !== 'COMPLETE' ? (
241249
<Button type="primary" onClick={onRunTest} disabled={processes.length > 0}>
242250
Run

web-app/src/containers/Tutorial/components/Step.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ interface Props {
1111
status: T.ProgressStatus
1212
subtasks: { name: string; pass: boolean }[] | null
1313
hints?: string[]
14-
hintIndex?: number
15-
setHintIndex?(value: number): void
14+
hintIndex: number
15+
setHintIndex(value: number): void
1616
onLoadSolution(): void
1717
}
1818

web-app/stories/Commands.stories.tsx

-29
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ storiesOf('Components', module)
1414
.addDecorator(SideBarDecorator)
1515
.add('Processes', () => (
1616
<ProcessMessages
17-
testStatus={null}
1817
processes={[
1918
{
2019
title: 'npm install',
@@ -27,31 +26,3 @@ storiesOf('Components', module)
2726
]}
2827
/>
2928
))
30-
.add('Test Start', () => (
31-
<ProcessMessages
32-
testStatus={{
33-
type: 'loading',
34-
title: 'Test running...',
35-
}}
36-
processes={[]}
37-
/>
38-
))
39-
.add('Test Pass', () => (
40-
<ProcessMessages
41-
testStatus={{
42-
type: 'success',
43-
title: 'Success!',
44-
}}
45-
processes={[]}
46-
/>
47-
))
48-
.add('Test Fail', () => (
49-
<ProcessMessages
50-
testStatus={{
51-
type: 'warning',
52-
title: 'Fail!',
53-
content: 'Test failed for some reason',
54-
}}
55-
processes={[]}
56-
/>
57-
))

web-app/stories/Step.stories.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ storiesOf('Step', module)
6565
status="ACTIVE"
6666
onLoadSolution={action('onLoadSolution')}
6767
subtasks={null}
68+
hintIndex={0}
69+
setHintIndex={action('setHintIndex')}
6870
/>
6971
))
7072
.add('Step Markdown', () => (
@@ -74,6 +76,8 @@ storiesOf('Step', module)
7476
status={select('mode', { ACTIVE: 'ACTIVE', COMPLETE: 'COMPLETE', INCOMPLETE: 'INCOMPLETE' }, 'ACTIVE', 'step')}
7577
onLoadSolution={action('onLoadSolution')}
7678
subtasks={null}
79+
hintIndex={0}
80+
setHintIndex={action('setHintIndex')}
7781
/>
7882
))
7983
.add('Substasks', () => (
@@ -96,6 +100,8 @@ storiesOf('Step', module)
96100
pass: false,
97101
},
98102
]}
103+
hintIndex={0}
104+
setHintIndex={action('setHintIndex')}
99105
/>
100106
))
101107
.add('Hints', () => (

web-app/stories/Tests.stories.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { storiesOf } from '@storybook/react'
2+
import React from 'react'
3+
import TestMessage from '../src/components/TestMessage'
4+
import SideBarDecorator from './utils/SideBarDecorator'
5+
6+
storiesOf('Test Message', module)
7+
.addDecorator(SideBarDecorator)
8+
.add('Fail', () => <TestMessage content={'Test failed for some reason'} />)

0 commit comments

Comments
 (0)