Skip to content

Commit

Permalink
Add ObjectViewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Jun 26, 2020
1 parent 7b72a4d commit 313e5ea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/driver/cypress/integration/commands/log_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('log options on success', () => {
cy.focused(options)
})

testLog('get', { withinSubject: document.forms[0] }, (options) => {
testLog('get', { withinSubject: null }, (options) => {
cy.get('#a', options)
})

Expand Down
5 changes: 5 additions & 0 deletions packages/reporter/src/commands/commands.scss
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@
white-space: initial;
font-size: 0.85em;
opacity: 0.9;

.object-viewer {
line-height: 1.2;
margin: 4px 8px;
}
}

.command-wrapper .fa-circle {
Expand Down
6 changes: 5 additions & 1 deletion packages/reporter/src/commands/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Markdown from 'markdown-it'

import appState from '../lib/app-state'
import CommandModel from './command-model'
import { ObjectViewer } from './object-viewer'

const md = new Markdown()
const formattedMessage = (message: string) => message ? md.renderInline(message) : ''
Expand All @@ -21,7 +22,10 @@ export const Message = observer(({ model }: MessageProps) => (
dangerouslySetInnerHTML={{ __html: formattedMessage(model.displayMessage || '') }}
/>
{ model.options && Object.keys(model.options).length > 0
? <span className="command-message-options">{JSON.stringify(model.options)}</span>
?
<span className="command-message-options">
<ObjectViewer obj={model.options} />
</span>
: null
}
</span>
Expand Down
28 changes: 28 additions & 0 deletions packages/reporter/src/commands/object-viewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import _ from 'lodash'

interface ObjectViewerProps {
obj: Record<any, any>
}

export const ObjectViewer = ({ obj }: ObjectViewerProps) => {
return (
<div className="object-viewer">
{Object.keys(obj).map((key) => {
return <div>{`- ${key}: ${encode(obj[key])}`}</div>
})}
</div>
)
}

const encode = (val: any) => {
if (_.isObject(val)) {
return JSON.stringify(val).replace(/,"/g, ', "')
}

if (_.isFunction(val)) {
return '[Function]'
}

return val
}

0 comments on commit 313e5ea

Please sign in to comment.