-
Notifications
You must be signed in to change notification settings - Fork 12
feat: added initial view nad rendering field content #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c2cdd7e
feat: initial view added and update field renders
raven-wing c289f52
Field renderers fixes
raven-wing b8f1c43
updated dependencies
raven-wing 2994172
missing file
raven-wing ee488fa
fixes
raven-wing 1215962
fix lint
raven-wing 3bac337
fixes after review
raven-wing f408b11
fix lnting
raven-wing dac541a
less comments
raven-wing 21b646a
back to google
raven-wing ac64cc2
fix wiring
raven-wing e045f5c
remove max zoom
raven-wing 55ef5fc
simplify
raven-wing 8f8f46e
docs fixed
raven-wing a6939b5
fixes after review
raven-wing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
| import React from 'react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { act } from '@testing-library/react'; | ||
| import MapContainer from '../../src/components/Map/Map'; | ||
|
|
||
| jest.mock('../../src/components/Map/MapComponent', () => () => <div data-testid="map-component" />); | ||
| jest.mock('../../src/components/FiltersForm/FiltersForm', () => () => ( | ||
| <div data-testid="filters-form" /> | ||
| )); | ||
| jest.mock('../../src/components/common/AppToaster', () => () => null); | ||
| jest.mock('../../src/services/http/httpService', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| getCategoriesData: jest.fn().mockResolvedValue({ categories: [], defaultChecked: {} }), | ||
| getLocationSchema: jest.fn().mockResolvedValue({}), | ||
| }, | ||
| })); | ||
|
|
||
| // Map.jsx creates its own React root instead of being rendered by a test renderer, | ||
| // so act() has to be told this is an act environment. | ||
| globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
|
|
||
| const renderApp = async () => { | ||
| await act(async () => { | ||
| MapContainer(); | ||
| }); | ||
| }; | ||
|
|
||
| describe('MapWrap placeholders', () => { | ||
| let error; | ||
|
|
||
| // PropTypes' `node` validator does not recognise portals, so every render here | ||
| // warns about FiltersProvider's children (a pre-existing dev-only warning, not | ||
| // something these tests are about). console.error is silenced and asserted on by | ||
| // message instead of by call count. | ||
| beforeEach(() => { | ||
| error = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('renders both portals when the left panel is present', async () => { | ||
| document.body.innerHTML = '<div id="map"></div><div id="filter-form"></div>'; | ||
|
|
||
| await renderApp(); | ||
|
|
||
| expect(document.querySelector('[data-testid="map-component"]')).not.toBeNull(); | ||
| expect(document.querySelector('[data-testid="filters-form"]')).not.toBeNull(); | ||
| }); | ||
|
|
||
| // A deployment with no categories renders no left panel at all, so #filter-form is | ||
| // legitimately missing - the map must still come up rather than the whole app | ||
| // bailing out. | ||
| it('still renders the map when the filters placeholder is missing', async () => { | ||
| document.body.innerHTML = '<div id="map"></div>'; | ||
| await renderApp(); | ||
|
|
||
| expect(document.querySelector('[data-testid="map-component"]')).not.toBeNull(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| expect(document.querySelector('[data-testid="filters-form"]')).toBeNull(); | ||
| expect(error).not.toHaveBeenCalledWith(expect.stringContaining('render the map')); | ||
| }); | ||
|
|
||
| it('renders nothing when the map placeholder is missing', async () => { | ||
| document.body.innerHTML = '<div id="filter-form"></div>'; | ||
| await renderApp(); | ||
|
|
||
| expect(document.querySelector('[data-testid="map-component"]')).toBeNull(); | ||
| expect(document.querySelector('[data-testid="filters-form"]')).toBeNull(); | ||
| expect(error).toHaveBeenCalledWith(expect.stringContaining('render the map')); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,45 @@ | ||
| import mapConfig from '../../src/components/Map/map.config'; | ||
|
|
||
| // The view the frontend opened on before it became configurable, and still the fallback | ||
| // when a deployment ships no window.INITIAL_VIEW. Spelled out rather than imported from | ||
| // the module under test, so a change to it has to be made deliberately here too. | ||
| const DEFAULT_COORDINATES = [51.917, 19.013]; | ||
| const DEFAULT_ZOOM = 7; | ||
| const DEFAULT_MAX_ZOOM = 19; | ||
|
|
||
| describe('mapConfig', () => { | ||
| afterEach(() => { | ||
| delete globalThis.INITIAL_VIEW; | ||
| }); | ||
|
|
||
| it('takes the whole view from the deployment when one is provided', () => { | ||
| globalThis.INITIAL_VIEW = { center: [53.37, 22.89], zoom: 8, max_zoom: 17 }; | ||
|
|
||
| expect(mapConfig.initialMapCoordinates).toEqual([53.37, 22.89]); | ||
| expect(mapConfig.initialMapZoom).toBe(8); | ||
| expect(mapConfig.maxMapZoom).toBe(17); | ||
| }); | ||
|
|
||
| it('falls back to the whole of Poland when the global never arrives', () => { | ||
| expect(mapConfig.initialMapCoordinates).toEqual(DEFAULT_COORDINATES); | ||
| expect(mapConfig.initialMapZoom).toBe(DEFAULT_ZOOM); | ||
| expect(mapConfig.maxMapZoom).toBe(DEFAULT_MAX_ZOOM); | ||
| }); | ||
|
|
||
| it('reads the global when the map mounts, not when the module is imported', () => { | ||
| // The module was imported at the top of this file, before any INITIAL_VIEW | ||
| // existed. A deployment whose template sets the global after the bundle loads | ||
| // must still get its own view rather than the fallback. | ||
| globalThis.INITIAL_VIEW = { center: [10, 20], zoom: 3, max_zoom: 12 }; | ||
|
|
||
| expect(mapConfig.initialMapCoordinates).toEqual([10, 20]); | ||
| }); | ||
|
|
||
| it('keeps a zoom of 0 rather than treating it as absent', () => { | ||
| // Goodmap always sends a complete view, so a zero here is a deliberate | ||
| // whole-world zoom - `||` would quietly replace it with the default. | ||
| globalThis.INITIAL_VIEW = { center: [0, 0], zoom: 0, max_zoom: 19 }; | ||
|
|
||
| expect(mapConfig.initialMapZoom).toBe(0); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.