Skip to content

Commit 0ddb082

Browse files
authored
fix(compass-schema): fix map rendering + add e2e tests COMPASS-6131 (#3479)
1 parent 70df442 commit 0ddb082

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

packages/compass-e2e-tests/helpers/insert-data.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,16 @@ export async function createNumbersCollection(): Promise<void> {
8787
.collection('numbers')
8888
.insertMany([...Array(1000).keys()].map((i) => ({ i, j: 0 })));
8989
}
90+
91+
export async function createGeospatialCollection(): Promise<void> {
92+
const db = client.db('test');
93+
94+
const lon = () => Math.random() * 360 - 180;
95+
const lat = () => Math.random() * 180 - 90;
96+
97+
await db.collection('geospatial').insertMany(
98+
[...Array(1000).keys()].map(() => ({
99+
location: { type: 'Point', coordinates: [lon(), lat()] },
100+
}))
101+
);
102+
}

packages/compass-e2e-tests/tests/collection-schema-tab.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { CompassBrowser } from '../helpers/compass-browser';
33
import { beforeTests, afterTests, afterTest } from '../helpers/compass';
44
import type { Compass } from '../helpers/compass';
55
import * as Selectors from '../helpers/selectors';
6-
import { createNumbersCollection } from '../helpers/insert-data';
6+
import {
7+
createGeospatialCollection,
8+
createNumbersCollection,
9+
} from '../helpers/insert-data';
710

811
const { expect } = chai;
912

@@ -18,8 +21,8 @@ describe('Collection schema tab', function () {
1821

1922
beforeEach(async function () {
2023
await createNumbersCollection();
24+
await createGeospatialCollection();
2125
await browser.connectWithConnectionString('mongodb://localhost:27091/test');
22-
await browser.navigateToCollectionTab('test', 'numbers', 'Schema');
2326
});
2427

2528
after(async function () {
@@ -31,6 +34,7 @@ describe('Collection schema tab', function () {
3134
});
3235

3336
it('analyzes a schema', async function () {
37+
await browser.navigateToCollectionTab('test', 'numbers', 'Schema');
3438
await browser.clickVisible(Selectors.AnalyzeSchemaButton);
3539

3640
const element = await browser.$(Selectors.SchemaFieldList);
@@ -60,6 +64,39 @@ describe('Collection schema tab', function () {
6064
expect(fieldTypes).to.deep.equal(['objectid', 'int32', 'int32']);
6165
});
6266

67+
for (const enableMaps of [true, false]) {
68+
it(`can analyze coordinates for a schema (enableMaps = ${enableMaps})`, async function () {
69+
await browser.setFeature('enableMaps', enableMaps);
70+
await browser.navigateToCollectionTab('test', 'geospatial', 'Schema');
71+
await browser.clickVisible(Selectors.AnalyzeSchemaButton);
72+
73+
const element = await browser.$(Selectors.SchemaFieldList);
74+
await element.waitForDisplayed();
75+
76+
const schemaFieldNameElement = await browser.$$(
77+
Selectors.SchemaFieldName
78+
);
79+
const fieldNames = (
80+
await Promise.all(schemaFieldNameElement.map((el) => el.getText()))
81+
).map((text) => text.trim());
82+
expect(fieldNames).to.deep.equal(['_id', 'location']);
83+
84+
const schemaFieldTypeListElement = await browser.$$(
85+
Selectors.SchemaFieldTypeList
86+
);
87+
const fieldTypes = (
88+
await Promise.all(schemaFieldTypeListElement.map((el) => el.getText()))
89+
).map((text) => text.trim());
90+
expect(fieldTypes).to.deep.equal([
91+
'objectid',
92+
enableMaps ? 'coordinates' : 'document',
93+
]);
94+
await browser
95+
.$('.leaflet-container')
96+
.waitForDisplayed({ reverse: !enableMaps });
97+
});
98+
}
99+
63100
it('analyzes the schema with a query');
64101
it('can reset the query');
65102
it('can create a geoquery from a map');

packages/compass-schema/src/components/field/field.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Field extends Component {
127127
getSemanticType(type) {
128128
// check if the type represents geo coordinates, if privacy settings allow
129129

130-
if (this.enableMaps) {
130+
if (this.state.enableMaps) {
131131
const coords = detectCoordinates(type);
132132
if (coords) {
133133
type.name = 'Coordinates';

0 commit comments

Comments
 (0)