Skip to content

Commit

Permalink
chore: fix all tests
Browse files Browse the repository at this point in the history
feat: add lockConnect to QS options for alt connection screen UI
  • Loading branch information
zardoy committed May 8, 2024
1 parent 03b3e56 commit 3046524
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ world chunks have a *yellow* border, hostile mobs have a *red* outline, passive

Press `Y` to set query parameters to url of your current game state.

- `?server=<server_address>` - Display connect screen to the server on load
- `?username=<username>` - Set the username on load
- `?proxy=<proxy_address>` - Set the proxy server address on load
- `?version=<version>` - Set the version on load
- `?ip=<server_address>` - Display connect screen to the server on load
- `?username=<username>` - Set the username for server
- `?proxy=<proxy_address>` - Set the proxy server address to use for server
- `?version=<version>` - Set the version for server
- `?lockConnect=true` - Disable cancel / save buttons, useful for integrates iframes
- `?reconnect=true` - Reconnect to the server on page reloads. Available in **dev mode only** and very useful on server testing.
<!-- - `?password=<password>` - Set the password on load -->
- `?loadSave=<save_name>` - Load the save on load with the specified folder name (not title)
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const setOptions = (options: Partial<AppOptions>) => {
}

it('Loads & renders singleplayer', () => {
cleanVisit('/?singleplayer=1')
visit('/?singleplayer=1')
setOptions({
localServerOptions: {
generation: {
Expand All @@ -52,7 +52,7 @@ it('Loads & renders singleplayer', () => {
testWorldLoad()
})

it.only('Joins to server', () => {
it('Joins to server', () => {
visit('/?ip=localhost&version=1.16.1')
window.localStorage.version = ''
// todo replace with data-test
Expand Down
6 changes: 3 additions & 3 deletions src/react/AddServer.tsx → src/react/AddServerOrConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
const [usernameOverride, setUsernameOverride] = React.useState(initialData?.usernameOverride ?? qsParams?.get('username') ?? '')
const [passwordOverride, setPasswordOverride] = React.useState(initialData?.passwordOverride ?? qsParams?.get('password') ?? '')
const smallWidth = useIsSmallWidth()
const lockConnect = qsParams?.get('lockConnect') === 'true'

return <Screen title={qsParams?.get('ip') ? 'Connect to Server' : title} backdrop>
<form style={{
Expand Down Expand Up @@ -74,10 +75,9 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
<InputWithLabel label="Proxy Override" value={proxyOverride} onChange={({ target: { value } }) => setProxyOverride(value)} placeholder={defaults?.proxyOverride} />
<InputWithLabel label="Username Override" value={usernameOverride} onChange={({ target: { value } }) => setUsernameOverride(value)} placeholder={defaults?.usernameOverride} />
<InputWithLabel label="Password Override" value={passwordOverride} onChange={({ target: { value } }) => setPasswordOverride(value)} /* placeholder='For advanced usage only' */ />
<Button onClick={() => {
{!lockConnect && <><Button onClick={() => {
onBack()
}}>Cancel</Button>
<Button type='submit'>Save</Button>
} }>Cancel</Button><Button type='submit'>Save</Button></>}
{qsParams?.get('ip') && <div style={{ gridColumn: smallWidth ? '' : 'span 2', display: 'flex', justifyContent: 'center' }}>
<Button
data-test-id='connect-qs'
Expand Down
4 changes: 2 additions & 2 deletions src/react/ServersList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react'
import 'iconify-icon'

import { useState } from 'react'
import AddServer from './AddServer'
import AddServerOrConnect from './AddServerOrConnect'
import ServersList from './ServersList'

const meta: Meta<typeof ServersList> = {
Expand All @@ -12,7 +12,7 @@ const meta: Meta<typeof ServersList> = {
const [username, setUsername] = useState('')

return addOpen ?
<AddServer onBack={() => {
<AddServerOrConnect onBack={() => {
setAddOpen(false)
}}
onConfirm={(info) => {
Expand Down
6 changes: 3 additions & 3 deletions src/react/ServersListProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { qsOptions } from '../optionsStorage'
import { ConnectOptions } from '../connect'
import { hideCurrentModal, miscUiState, showModal } from '../globalState'
import ServersList from './ServersList'
import AddServer from './AddServer'
import AddServerOrConnect from './AddServerOrConnect'
import { useDidUpdateEffect } from './utils'
import { useIsModalActive } from './utilsApp'

Expand Down Expand Up @@ -180,7 +180,7 @@ const Inner = () => {

const isEditScreenModal = useIsModalActive('editServer')

useEffect(() => {
useDidUpdateEffect(() => {
if (serverEditScreen && !isEditScreenModal) {
showModal({ reactType: 'editServer' })
}
Expand All @@ -190,7 +190,7 @@ const Inner = () => {
}, [serverEditScreen])

if (isEditScreenModal) {
return <AddServer
return <AddServerOrConnect
defaults={{
proxyOverride: selectedProxy,
usernameOverride: defaultUsername,
Expand Down

0 comments on commit 3046524

Please sign in to comment.