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

test: add unit tests for component light #1489

Merged
merged 4 commits into from
Aug 20, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Feat(camera): maxBounds/(min|max)ZoomLevel can be updated dynamically ([#1462](h
Refactor(example): clean up folder structure ([#1464](https://github.com/react-native-mapbox-gl/maps/pull/1464))
Fix lineGradient showing wrong colors ([#1471](https://github.com/react-native-mapbox-gl/maps/pull/1471))
Support tintColor on Android ([#1465](https://github.com/react-native-mapbox-gl/maps/pull/1465))
Feat(android): dynamically update tintColor & add example ([#1469](https://github.com/react-native-mapbox-gl/maps/pull/1469)
Docs: make background in example pngs transparent ([#1483](https://github.com/react-native-mapbox-gl/maps/pull/1483)
Examples: align install steps with yarn, ignore created env files ([#1484](https://github.com/react-native-mapbox-gl/maps/pull/1484)
Style: run yarn lint ([#1486](https://github.com/react-native-mapbox-gl/maps/pull/1486)
Feat(android): dynamically update tintColor & add example ([#1469](https://github.com/react-native-mapbox-gl/maps/pull/1469))
Docs: make background in example pngs transparent ([#1483](https://github.com/react-native-mapbox-gl/maps/pull/1483))
Examples: align install steps with yarn, ignore created env files ([#1484](https://github.com/react-native-mapbox-gl/maps/pull/1484))
Style: run yarn lint ([#1486](https://github.com/react-native-mapbox-gl/maps/pull/1486))
Test: add unit tests for component light ([#1489](https://github.com/react-native-mapbox-gl/maps/pull/1489))

---

Expand Down
39 changes: 39 additions & 0 deletions __tests__/components/Light.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import {render} from '@testing-library/react-native';

import Light from '../../javascript/components/Light';

export const NATIVE_MODULE_NAME = 'RCTMGLLight';

describe('Light', () => {
test('renders correctly', () => {
const {queryByTestId} = render(<Light />);
const light = queryByTestId('rctmglLight');
expect(light).toBeDefined();
});

test('renders correctly with custom styles', () => {
const testStyles = {
position: [1234, 1234, 1234],
color: '#FA0000', // === ProcessedTestColor
anchor: 'map',
intensity: 1,
};
const processedTestColor = 4294574080;

const {queryByTestId} = render(<Light style={testStyles} />);

const customStyles = queryByTestId('rctmglLight').props.reactStyle;
const {anchor} = customStyles;
const {color} = customStyles;
const {position} = customStyles;
const {intensity} = customStyles;

expect(anchor.stylevalue.value).toStrictEqual(testStyles.anchor);
expect(color.stylevalue.value).toStrictEqual(processedTestColor);
expect(intensity.stylevalue.value).toStrictEqual(testStyles.intensity);
expect(position.stylevalue.value[0].value).toStrictEqual(
testStyles.position[0],
);
});
});
53 changes: 27 additions & 26 deletions example/src/examples/LineLayer/GradientLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ import sheet from '../../styles/sheet';
import BaseExamplePropTypes from '../common/BaseExamplePropTypes';
import Page from '../common/Page';

const styles = {
lineLayer: {
lineColor: 'red',
lineCap: 'round',
lineJoin: 'round',
lineWidth: 14,
lineGradient: [
'interpolate',
['linear'],
['line-progress'],
0,
'blue',
0.1,
'royalblue',
0.3,
'cyan',
0.5,
'lime',
0.7,
'yellow',
1,
'red',
],
},
};

class GradientLine extends React.Component {
static propTypes = {
...BaseExamplePropTypes,
Expand Down Expand Up @@ -47,32 +73,7 @@ class GradientLine extends React.Component {
],
},
}}>
<MapboxGL.LineLayer
id="layer1"
style={{
lineColor: 'red',
lineCap: 'round',
lineJoin: 'round',
lineWidth: 14,
lineGradient: [
'interpolate',
['linear'],
['line-progress'],
0,
'blue',
0.1,
'royalblue',
0.3,
'cyan',
0.5,
'lime',
0.7,
'yellow',
1,
'red',
],
}}
/>
<MapboxGL.LineLayer id="layer1" style={styles.lineLayer} />
</MapboxGL.ShapeSource>
</MapboxGL.MapView>
</Page>
Expand Down
1 change: 1 addition & 0 deletions javascript/components/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Light extends AbstractLayer {
return (
<RCTMGLLight
ref="nativeLight"
testID="rctmglLight"
{...this.props}
style={undefined}
reactStyle={this.getStyle()}
Expand Down