applied requested changes

This commit is contained in:
zokutyou2@gmail.com 2021-07-21 16:53:52 +09:00
parent 29997bca4b
commit 4f5c615818
7 changed files with 20 additions and 22 deletions

View File

@ -24,6 +24,7 @@ test("OptionsToggle", async () => {
<OptionsToggle name='anticache'>toggle anticache</OptionsToggle>, <OptionsToggle name='anticache'>toggle anticache</OptionsToggle>,
{store} {store}
); );
globalThis.fetch = jest.fn()
expect(asFragment()).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
fireEvent.click(screen.getByText("toggle anticache")); fireEvent.click(screen.getByText("toggle anticache"));

View File

@ -23,11 +23,10 @@ describe('option reducer', () => {
}) })
}) })
let store = mockStore()
describe('option actions', () => { describe('option actions', () => {
it('should be possible to update option', () => { it('should be possible to update option', () => {
let store = mockStore()
let mockResponse = { status: 200 }, let mockResponse = { status: 200 },
promise = Promise.resolve(mockResponse) promise = Promise.resolve(mockResponse)
global.fetch = r => { return promise } global.fetch = r => { return promise }
@ -42,7 +41,8 @@ describe('option actions', () => {
describe('sendUpdate', () => { describe('sendUpdate', () => {
it('should handle error', async () => { it('should handle error', async () => {
let mockResponse = { status: 404, text: "fooerror" }, let store = mockStore()
let mockResponse = { status: 404, text: () => "fooerror" },
promise = Promise.resolve(mockResponse) promise = Promise.resolve(mockResponse)
global.fetch = r => { return promise } global.fetch = r => { return promise }
await store.dispatch(OptionsActions.pureSendUpdate("bar", "error")) await store.dispatch(OptionsActions.pureSendUpdate("bar", "error"))
@ -55,6 +55,7 @@ describe('sendUpdate', () => {
describe('save', () => { describe('save', () => {
it('should dump options', () => { it('should dump options', () => {
let store = mockStore()
global.fetch = jest.fn() global.fetch = jest.fn()
store.dispatch(OptionsActions.save()) store.dispatch(OptionsActions.save())
expect(fetch).toBeCalledWith( expect(fetch).toBeCalledWith(

View File

@ -50,7 +50,6 @@ export default function withContentLoader(View) {
updateContent(props) { updateContent(props) {
if (this.state.request) { if (this.state.request) {
console.log("request:",this.state.request)
this.state.request.abort() this.state.request.abort()
} }
// We have a few special cases where we do not need to make an HTTP request. // We have a few special cases where we do not need to make an HTTP request.

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {formatTimeDelta, formatTimeStamp} from '../../utils' import {formatTimeDelta, formatTimeStamp} from '../../utils'
import { Flow, HTTPMessage } from '../../flow' import { Flow, HTTPMessage, Connection } from '../../flow'
type TimeStampProps = { type TimeStampProps = {
t: number, t: number,
@ -27,15 +27,7 @@ export function TimeStamp({t, deltaTo, title}: TimeStampProps) {
} }
type ConnectionInfoProps = { type ConnectionInfoProps = {
conn: { conn: Connection,
address: string[],
sni: string,
tls_version: string,
cipher_name: string,
alpn_proto_negotiated: string,
ip_address: string[],
source_address: string[],
},
} }
export function ConnectionInfo({conn}: ConnectionInfoProps) { export function ConnectionInfo({conn}: ConnectionInfoProps) {
@ -44,7 +36,7 @@ export function ConnectionInfo({conn}: ConnectionInfoProps) {
<tbody> <tbody>
<tr key="address"> <tr key="address">
<td>Address:</td> <td>Address:</td>
<td>{conn.address.join(':')}</td> <td>{conn.address?.join(':')}</td>
</tr> </tr>
{conn.sni && ( {conn.sni && (
<tr key="sni"> <tr key="sni">

View File

@ -52,7 +52,7 @@ export default class CodeMirror extends React.Component<CodeMirrorProps, CodeMir
} }
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
//this.componentWillReceiveProps = _.debounce(this.componentWillReceiveProps, 0); this.componentWillReceiveProps = _.debounce(this.componentWillReceiveProps, 0);
if (this.props.path) { if (this.props.path) {
console.error('Warning: react-codemirror: the `path` prop has been changed to `name`'); console.error('Warning: react-codemirror: the `path` prop has been changed to `name`');
} }

View File

@ -36,27 +36,27 @@ const reducer: Reducer<OptionsState> = (state = defaultState, action) => {
} }
export default reducer export default reducer
export function pureSendUpdate(option: Option, value) { export function pureSendUpdate(option, value) {
return async dispatch => { return async dispatch => {
try { try {
const response = await fetchApi.put('/options', {[option]: value}); const response = await fetchApi.put('/options', {[option]: value});
if (response.status === 200) { if (response.status === 200) {
dispatch(optionsEditorActions.updateSuccess(option)) dispatch(optionsEditorActions.updateSuccess(option))
} else { } else {
throw await response.text throw await response.text()
} }
} catch (error) { } catch (error) {
return dispatch(optionsEditorActions.updateError(option, error)) dispatch(optionsEditorActions.updateError(option, error))
} }
} }
} }
export function update(name: Option, value: any): AppThunk { let sendUpdate = _.throttle(pureSendUpdate, 500, {leading: true, trailing: true})
let sendUpdate = _.throttle(pureSendUpdate(name, value), 500, {leading: true, trailing: true})
export function update(name: Option, value: any): AppThunk {
return dispatch => { return dispatch => {
dispatch(optionsEditorActions.startUpdate(name, value)) dispatch(optionsEditorActions.startUpdate(name, value))
sendUpdate(); dispatch(sendUpdate(name, value));
} }
} }

View File

@ -34,13 +34,18 @@ export type Address = [string, number];
export interface Connection { export interface Connection {
id: string id: string
ip_address?: string[]
address?: string[]
source_address?: string[]
peername?: Address peername?: Address
sockname?: Address sockname?: Address
tls_established: boolean tls_established: boolean
sni?: string | boolean sni?: string | boolean
cipher?: string cipher?: string
cipher_name?: string
alpn?: string alpn?: string
alpn_proto_negotiated?: string
tls_version?: string tls_version?: string
timestamp_start?: number timestamp_start?: number