Skip to content

Commit

Permalink
chore: add test, add server host
Browse files Browse the repository at this point in the history
  • Loading branch information
duyet committed Nov 22, 2023
1 parent b2201c7 commit a88ee95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/error.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'

import { default as ErrorPage } from './error'

describe('<Error />', () => {
it('renders', () => {
const err = new Error('Test error')
const reset = () => console.log('reset')

// Render
cy.mount(<ErrorPage error={err} reset={reset} />)

cy.get('h2').contains('Something went wrong').should('be.visible')

// Check console.log was called
cy.window().then((win) => {
cy.spy(win.console, 'log').as('consoleLog')
cy.get('button').contains('button', 'Try again').click()
cy.get('@consoleLog')
.should('have.been.called')
.and('have.been.calledWith', 'reset')
})
})
})
5 changes: 4 additions & 1 deletion components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Image from 'next/image'

import { Menu } from '@/components/menu'
import { ReloadButton } from '@/components/reload-button'
import { ServerHostname } from '@/components/server-hostname'

export function Header() {
return (
Expand All @@ -18,7 +19,9 @@ export function Header() {
<span className="hidden sm:flex">ClickHouse Monitoring</span>
<span className="flex sm:hidden">Monitoring</span>
</h2>
<p className="text-muted-foreground"></p>
<p className="text-muted-foreground">
<ServerHostname />
</p>
</div>
<div className="flex items-center space-x-2">
<Menu />
Expand Down
7 changes: 7 additions & 0 deletions components/server-hostname.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getHost } from '@/lib/utils'

export function ServerHostname() {
const host = process.env.CLICKHOUSE_HOST

return getHost(host)
}
7 changes: 7 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ export function dedent(str: string) {

return indent > 0 ? str.replace(re, '') : str
}

export function getHost(url?: string) {
if (!url) return ''

const { host } = new URL(url)
return host
}

0 comments on commit a88ee95

Please sign in to comment.