-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b256f91
commit e271523
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import {Provider} from "react-redux"; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import CoordinateDisplayer from '../../components/CoordinateDisplayer'; | ||
|
||
const mockStore = configureStore(); | ||
|
||
test('current coordinates are shown', () => { | ||
const store = mockStore({ | ||
map: { projection: 'EPSG:4326' }, | ||
mousePosition: { position: { coordinate: [123, 456] } } | ||
}); | ||
|
||
render( | ||
<Provider store={store}> | ||
<CoordinateDisplayer displaycrs={'EPSG:4326'} /> | ||
</Provider> | ||
); | ||
|
||
expect(screen.getByRole('textbox')).toHaveValue('123.0000 456.0000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import {Provider} from "react-redux"; | ||
|
||
import {act, fireEvent, render, screen} from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import SearchBox from '../../components/SearchBox'; | ||
|
||
const mockStore = configureStore(); | ||
|
||
const searchProviders = { | ||
testing: { | ||
onSearch: (text, searchParams, callback) => callback({ | ||
results: [ | ||
{ | ||
id: 'layer1', | ||
title: 'Layer 1', | ||
items: [ | ||
{ | ||
id: 'item1', | ||
text: 'Item 1' | ||
}, | ||
{ | ||
id: 'item2', | ||
text: 'Item 2' | ||
} | ||
] | ||
}, | ||
{ | ||
id: 'layer2', | ||
title: 'Layer 2', | ||
items: [ | ||
{ | ||
id: 'item3', | ||
text: 'Item 3' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line | ||
const Search = SearchBox(searchProviders); | ||
|
||
test('search results are visible', () => { | ||
const store = mockStore({ | ||
map: { projection: 'EPSG:4326' }, | ||
layers: { flat: [] }, | ||
theme: { current: { searchProviders: ['testing'] } } | ||
}); | ||
|
||
const searchOptions = { | ||
allowSearchFilters: false | ||
}; | ||
|
||
render( | ||
<Provider store={store}> | ||
<Search searchOptions={searchOptions} /> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByRole('input'); | ||
expect(input).toHaveValue(''); | ||
|
||
fireEvent.change(input, { target: { value: 'Test' } }); | ||
act(() => input.focus()); | ||
|
||
expect(input).toHaveValue('Test'); | ||
expect(screen.getByText('Layer 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Layer 2')).toBeInTheDocument(); | ||
expect(screen.getByText('Item 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Item 2')).toBeInTheDocument(); | ||
expect(screen.getByText('Item 3')).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import {Provider} from "react-redux"; | ||
|
||
import {render} from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import StandardApp from "../../components/StandardApp"; | ||
|
||
const mockStore = configureStore(); | ||
|
||
test('app is running w/o plugins', () => { | ||
const store = mockStore({}); | ||
|
||
const appConfig = { | ||
initialState: { | ||
defaultState: {} | ||
}, | ||
pluginsDef: { | ||
plugins: {} | ||
} | ||
}; | ||
|
||
render( | ||
<Provider store={store}> | ||
<StandardApp appConfig={appConfig} /> | ||
</Provider> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
import LocaleUtils from "../utils/LocaleUtils"; | ||
import MapUtils from "../utils/MapUtils"; | ||
import MockMap from "./mocks/MockMap"; | ||
|
||
import '@testing-library/jest-dom'; | ||
|
||
// Mock translation function, just return the message key | ||
LocaleUtils.tr = (key) => key; | ||
LocaleUtils.lang = () => 'en'; | ||
|
||
// Mock the Map object globally | ||
MapUtils.registerHook(MapUtils.GET_MAP, new MockMap()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default class MockMap { | ||
addLayer = () => null; | ||
removeLayer = () => null; | ||
getViewport = () => document.createElement('div'); | ||
} |