Skip to content

Commit

Permalink
experimenting with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korbinian90 committed Dec 10, 2023
1 parent 8e94c88 commit 5742258
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
1 change: 1 addition & 0 deletions niivue/src/components/MenuElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const MenuItem = ({ label, onClick, children, visible }: any) => {
<button
class="hover:bg-gray-700 pr-2 rounded-r-md h-6 align-middle"
onClick=${toggle(isOpen)}
data-testid="menu-item-dropdown-${label}"
>
<${DownArrow} />
</button>
Expand Down
42 changes: 31 additions & 11 deletions niivue/src/components/test/App.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, expect, it, test } from 'vitest'
import { render, screen } from '@testing-library/preact'
import { BrowserRouter } from 'react-router-dom'
import { fireEvent, render, screen } from '@testing-library/preact'
import { html } from 'htm/preact'

import { App } from '../App'
Expand All @@ -19,17 +18,38 @@ describe('app', () => {
expect(1 + 2).toBe(expected)
})

test('should display home screen', () => {
// const n = new Niivue()
render(html`<${BrowserRouter}><${App} /></${BrowserRouter}>`)
// App
// test that the component with text "Niivue-ify" is present
// expect(screen.getByText("Niivue-ify")).toBe;
expect(3 + 2).toBe(5)
it('should display home screen', () => {
render(html`<${App} />`)

expect(screen.getByText(/Home/i)).toBeInTheDocument()
expect(screen.getByText(/Add Image/i)).toBeInTheDocument()
expect(screen.getByText(/View/i)).toBeInTheDocument()
expect(screen.getByText(/Bookmarklet/i)).toBeInTheDocument()
expect(screen.getByText(/Drop Files to load images/i)).toBeInTheDocument()
})

it('basic', () => {
it('should load a test image', () => {
render(html`<${App} />`)
expect(screen.getByText(/Niivue-ify/i)).toBeInTheDocument()
const testLink = 'https://niivue.github.io/niivue-demo-images/mni152.nii.gz'
// send a message to load the test image
// window.postMessage(
// {
// type: 'addImage',
// body: {
// data: '',
// uri: testLink,
// },
// },
// '*',
// )

const addImageDropdown = screen.getByTestId('menu-item-dropdown-Add Image')
fireEvent.click(addImageDropdown)
const openExampleImage = screen.getByText(/Example Image/i)
expect(openExampleImage).toBeInTheDocument()

// fireEvent.click(openExampleImage)

// expect(screen.getByText(/Loading/i)).toBeInTheDocument()
})
})
25 changes: 10 additions & 15 deletions niivue/src/components/test/HomeScreen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ import { render } from "@testing-library/preact";
import { html } from "htm/preact";
import { HomeScreen } from "../HomeScreen";

describe("HomeScreen", () => {
it("renders the OpenFromWeb component", () => {
const { getByText } = render(html`<${HomeScreen} />`);
expect(getByText("Open Image from URL")).toBeInTheDocument();
});
describe('HomeScreen', () => {
it('should render the bookmarklet link', () => {
const { getByText } = render(html`<${HomeScreen} />`)
expect(getByText('Niivue-ify')).toBeInTheDocument()
})

it("renders the bookmarklet link", () => {
const { getByText } = render(html`<${HomeScreen} />`);
expect(getByText("Niivue-ify")).toBeInTheDocument();
});

it("renders the test link", () => {
const { getByText } = render(html`<${HomeScreen} />`);
expect(getByText("MNI")).toBeInTheDocument();
});
});
it('should render the test link', () => {
const { getByText } = render(html`<${HomeScreen} />`)
expect(getByText('MNI')).toBeInTheDocument()
})
})

0 comments on commit 5742258

Please sign in to comment.