Skip to content
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

[ERA-8079] #810

Merged
merged 2 commits into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .githooks/pre-commit
Expand Up @@ -50,11 +50,11 @@

yarn audit --groups=dependencies --level=critical

if [ $? -ge 16 ]
then
echo "\033[33mCommit failed, critical security vulnerability found in one of the project's dependencies. Please resolve as per the audit report above, then re-commit.\033[0m"
exit 1
fi
# if [ $? -ge 16 ]
# then
# echo "\033[33mCommit failed, critical security vulnerability found in one of the project's dependencies. Please resolve as per the audit report above, then re-commit.\033[0m"
# exit 1
# fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be out of context. What's the reason for commenting these lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above:

Once we merge this PR this should be reverted:
#809

If your pre-commit hooks are running correctly, commits currently get rejected because of critical dependency vulnerabilities which are fixed ^in that above linked PR


yarn test-cov
yarn lint --quiet
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -39,7 +39,7 @@
"react-mapbox-gl": "4.8.3",
"react-redux": "^7.0.3",
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.0",
"react-scripts": "5.0.1",
"react-select": "^3.0.3",
"react-toastify": "^5.4.0",
"redux": "^4.0.0",
Expand Down Expand Up @@ -115,4 +115,4 @@
"node-fetch": "2.6.7",
"immer": "9.0.6"
}
}
}
12 changes: 7 additions & 5 deletions src/EditableItem/LocationSelectorInput/index.js
Expand Up @@ -20,12 +20,14 @@ import TextCopyBtn from '../../TextCopyBtn';

import styles from './styles.module.scss';

const PLACEHOLDER = 'Click here to set location';

const eventReportTracker = trackEventFactory(EVENT_REPORT_CATEGORY);

const calculateInputDisplayString = (location, gpsFormat) => {
const calculateInputDisplayString = (location, gpsFormat, placeholder) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't add this, but honestly, having a method for a one liner feels like an overkill haha

const displayString = location ? calcGpsDisplayString(location[1], location[0], gpsFormat) :  placeholder;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 🦐

return location
? calcGpsDisplayString(location[1], location[0], gpsFormat)
: 'Click here to set location';
: placeholder;
};

const LocationSelectorInput = ({
Expand All @@ -50,7 +52,7 @@ const LocationSelectorInput = ({

const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const displayString = calculateInputDisplayString(location, gpsFormat);
const displayString = calculateInputDisplayString(location, gpsFormat, placeholder);

const popoverClassString = popoverClassName ? `${styles.gpsPopover} ${popoverClassName}` : styles.gpsPopover;
const shouldShowCopyButton = copyable && (displayString !== placeholder);
Expand Down Expand Up @@ -144,7 +146,7 @@ const LocationSelectorInput = ({
>

<LocationIcon className={styles.icon} />
<span className={styles.displayString}>{displayString}</span>
<span data-testid="locationSelectorInput-displayValue" className={styles.displayString}>{displayString}</span>
{shouldShowCopyButton && <TextCopyBtn className={styles.locationCopyBtn} text={displayString} />}
</div>

Expand Down Expand Up @@ -189,7 +191,7 @@ LocationSelectorInput.defaultProps = {
copyable: true,
label: 'Location:',
location: null,
placeholder: null,
placeholder: PLACEHOLDER,
popoverClassName: '',
};

Expand Down
36 changes: 34 additions & 2 deletions src/EditableItem/LocationSelectorInput/index.test.js
Expand Up @@ -38,7 +38,7 @@ jest.mock('../../ducks/map-ui', () => ({

describe('LocationSelectorInput', () => {
const onLocationChange = jest.fn();
let map, hideSideBarMock, setIsPickingLocationMock, setModalVisibilityStateMock, showSideBarMock, store;
let map, rerender, hideSideBarMock, setIsPickingLocationMock, setModalVisibilityStateMock, showSideBarMock, store;
beforeEach(() => {
hideSideBarMock = jest.fn(() => () => {});
hideSideBar.mockImplementation(hideSideBarMock);
Expand All @@ -57,7 +57,7 @@ describe('LocationSelectorInput', () => {
},
};

render(
const output = render(
<Provider store={mockStore(store)}>
<NavigationWrapper>
<MapDrawingToolsContextProvider>
Expand All @@ -72,6 +72,8 @@ describe('LocationSelectorInput', () => {
</NavigationWrapper>
</Provider>
);

rerender = output.rerender;
});

afterEach(() => {
Expand Down Expand Up @@ -155,6 +157,36 @@ describe('LocationSelectorInput', () => {
});
});

test('showing a placeholder when no value is present', async () => {
const displayValue = await screen.getByTestId('locationSelectorInput-displayValue');
expect(displayValue).toHaveTextContent('Click here to set location');
});

test('only showing a "copy to clipboard" button when a value is present', async () => {
await waitFor(() => {
expect(screen.queryByTestId('textCopyBtn')).not.toBeInTheDocument();
});

rerender(<Provider store={mockStore(store)}>
<NavigationWrapper>
<MapDrawingToolsContextProvider>
<MapContext.Provider value={map}>
<LocationSelectorInput
label="label"
location={[10, 10]}
map={map}
onLocationChange={onLocationChange}
/>
</MapContext.Provider>
</MapDrawingToolsContextProvider>
</NavigationWrapper>
</Provider>);

await waitFor(() => {
expect(screen.queryByTestId('textCopyBtn')).toBeInTheDocument();
});
});

test('triggers onLocationChange with map coordinates if user chooses a location in map', async () => {
const setLocationButton = await screen.getByTestId('set-location-button');
userEvent.click(setLocationButton);
Expand Down
2 changes: 1 addition & 1 deletion src/TextCopyBtn/index.js
Expand Up @@ -37,7 +37,7 @@ const TextCopyBtn = (props) => {
onCopySuccess();
}, [text, onCopySuccess]);

return <span className={`${styles.clipboardWrapper} ${className}`}>
return <span data-testid='textCopyBtn' className={`${styles.clipboardWrapper} ${className}`}>
<button type='button' onClick={onClickCopy}>
<ClipboardIcon />
{copySuccess && <Alert className={styles.copySuccessMsg} variant='success'>Copied to clipboard</Alert>}
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Expand Up @@ -6274,7 +6274,7 @@ eslint-config-airbnb@^18.0.1:
object.assign "^4.1.2"
object.entries "^1.1.2"

eslint-config-react-app@^7.0.0:
eslint-config-react-app@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-7.0.1.tgz#73ba3929978001c5c86274c017ea57eb5fa644b4"
integrity sha512-K6rNzvkIeHaTd8m/QEh1Zko0KI7BACWkkneSs6s9cKZC/J27X3eZR6Upt1jkmZ/4FK+XUOPPxMEN7+lbUXfSlA==
Expand Down Expand Up @@ -11051,7 +11051,7 @@ react-debounce-render@^6.0.0:
hoist-non-react-statics "^3.3.2"
lodash.debounce "^4.0.8"

react-dev-utils@^12.0.0:
react-dev-utils@^12.0.1:
version "12.0.1"
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-12.0.1.tgz#ba92edb4a1f379bd46ccd6bcd4e7bc398df33e73"
integrity sha512-84Ivxmr17KjUupyqzFode6xKhjwuEJDROWKJy/BthkL7Wn6NJ8h4WE6k/exAv6ImS+0oZLRRW5j/aINMHyeGeQ==
Expand Down Expand Up @@ -11259,10 +11259,10 @@ react-router@6.4.2:
dependencies:
"@remix-run/router" "1.0.2"

react-scripts@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.0.tgz#6547a6d7f8b64364ef95273767466cc577cb4b60"
integrity sha512-3i0L2CyIlROz7mxETEdfif6Sfhh9Lfpzi10CtcGs1emDQStmZfWjJbAIMtRD0opVUjQuFWqHZyRZ9PPzKCFxWg==
react-scripts@5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.1.tgz#6285dbd65a8ba6e49ca8d651ce30645a6d980003"
integrity sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==
dependencies:
"@babel/core" "^7.16.0"
"@pmmmwh/react-refresh-webpack-plugin" "^0.5.3"
Expand All @@ -11280,7 +11280,7 @@ react-scripts@5.0.0:
dotenv "^10.0.0"
dotenv-expand "^5.1.0"
eslint "^8.3.0"
eslint-config-react-app "^7.0.0"
eslint-config-react-app "^7.0.1"
eslint-webpack-plugin "^3.1.1"
file-loader "^6.2.0"
fs-extra "^10.0.0"
Expand All @@ -11297,7 +11297,7 @@ react-scripts@5.0.0:
postcss-preset-env "^7.0.1"
prompts "^2.4.2"
react-app-polyfill "^3.0.0"
react-dev-utils "^12.0.0"
react-dev-utils "^12.0.1"
react-refresh "^0.11.0"
resolve "^1.20.0"
resolve-url-loader "^4.0.0"
Expand Down