Skip to content

Commit 30f864f

Browse files
committed
wip
1 parent 00edc68 commit 30f864f

File tree

3 files changed

+117
-67
lines changed

3 files changed

+117
-67
lines changed

packages/compass-global-writes/src/components/shard-zones-table.tsx

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,14 @@ import {
1717
type LGTableDataType,
1818
getFilteredRowModel,
1919
type LgTableRowType,
20-
Subtitle,
21-
Body,
22-
spacing,
23-
Link,
2420
} from '@mongodb-js/compass-components';
2521
import type { ShardZoneData } from '../store/reducer';
26-
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
22+
import { ShardZonesDescription } from './shard-zones-description';
2723

2824
const containerStyles = css({
2925
height: '400px',
3026
});
3127

32-
const paragraphStyles = css({
33-
display: 'flex',
34-
flexDirection: 'column',
35-
gap: spacing[100],
36-
});
37-
3828
interface ShardZoneRow {
3929
locationName: string;
4030
zone: string;
@@ -138,42 +128,11 @@ export function ShardZonesTable({
138128
[tableRef]
139129
);
140130

141-
const { atlasMetadata } = useConnectionInfo();
142-
143131
const { rows } = table.getRowModel();
144132

145133
return (
146134
<>
147-
<Subtitle>Location Codes</Subtitle>
148-
<div className={paragraphStyles}>
149-
<Body>
150-
Each document’s first field should include an ISO 3166-1 Alpha-2 code
151-
for the location it belongs to.
152-
</Body>
153-
<Body>
154-
We also support ISO 3166-2 subdivision codes for countries containing
155-
a cloud provider data center (both ISO 3166-1 and ISO 3166-2 codes may
156-
be used for these countries). All valid country codes and the zones to
157-
which they map are listed in the table below. Additionally, you can
158-
view a list of all location codes{' '}
159-
<Link href="/static/atlas/country_iso_codes.txt">here</Link>.
160-
</Body>
161-
<Body>
162-
{atlasMetadata?.projectId && atlasMetadata?.clusterName && (
163-
<>
164-
Locations’ zone mapping can be changed by navigating to this
165-
clusters{' '}
166-
<Link
167-
href={`/v2/${atlasMetadata?.projectId}#/clusters/edit/${atlasMetadata?.clusterName}`}
168-
>
169-
Edit Configuration
170-
</Link>{' '}
171-
page and clicking the Configure Location Mappings’ link above the
172-
map.
173-
</>
174-
)}
175-
</Body>
176-
</div>
135+
<ShardZonesDescription />
177136
<SearchInput
178137
value={searchText}
179138
onChange={handleSearchTextChange}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import React from 'react';
2+
import { expect } from 'chai';
3+
import { screen, userEvent } from '@mongodb-js/testing-library-compass';
4+
import {
5+
IncompleteShardingSetup,
6+
type IncompleteShardingSetupProps,
7+
} from './incomplete-sharding-setup';
8+
import Sinon from 'sinon';
9+
import { renderWithStore } from '../../../tests/create-store';
10+
import { type ConnectionInfo } from '@mongodb-js/compass-connections/provider';
11+
import { type ShardZoneData } from '../../store/reducer';
12+
13+
describe.only('IncompleteShardingSetup', function () {
14+
const shardZones: ShardZoneData[] = [
15+
{
16+
zoneId: '45893084',
17+
country: 'Germany',
18+
readableName: 'Germany',
19+
isoCode: 'DE',
20+
typeOneIsoCode: 'DE',
21+
zoneName: 'EMEA',
22+
zoneLocations: ['Frankfurt'],
23+
},
24+
];
25+
const baseProps: IncompleteShardingSetupProps = {
26+
namespace: 'db1.coll1',
27+
shardZones,
28+
shardKey: {
29+
fields: [
30+
{ type: 'RANGE', name: 'location' },
31+
{ type: 'HASHED', name: 'secondary' },
32+
],
33+
isUnique: false,
34+
},
35+
isSubmittingForSharding: false,
36+
onResume: () => {},
37+
};
38+
39+
const connectionInfo = {
40+
id: 'testConnection',
41+
connectionOptions: {
42+
connectionString: 'mongodb://test',
43+
},
44+
atlasMetadata: {
45+
projectId: 'project1',
46+
clusterName: 'myCluster',
47+
} as ConnectionInfo['atlasMetadata'],
48+
};
49+
50+
function renderWithProps(
51+
props?: Partial<IncompleteShardingSetupProps>,
52+
options?: Parameters<typeof renderWithStore>[1]
53+
) {
54+
return renderWithStore(
55+
<IncompleteShardingSetup {...baseProps} {...props} />,
56+
{
57+
connectionInfo,
58+
...options,
59+
}
60+
);
61+
}
62+
63+
it('Shows description', async function () {
64+
await renderWithProps();
65+
66+
expect(screen.findByText(/your configuration is incomplete/)).to.be.exist;
67+
expect(screen.findByText(/Please enable Global Writes/)).to.be.exist;
68+
});
69+
70+
it('Provides button to resume managed namespace', async function () {
71+
const onResume = Sinon.spy();
72+
await renderWithProps({ onResume });
73+
74+
const btn = await screen.findByRole<HTMLButtonElement>('button', {
75+
name: /Enable Global Writes/,
76+
});
77+
expect(btn).to.be.visible;
78+
79+
userEvent.click(btn);
80+
81+
expect(onResume).to.have.been.calledOnce;
82+
});
83+
84+
it('Manage btn is disabled when the action is in progress', async function () {
85+
const onResume = Sinon.spy();
86+
await renderWithProps({ onResume, isSubmittingForSharding: true });
87+
88+
const btn = await screen.findByTestId<HTMLButtonElement>(
89+
'manage-collection-button'
90+
);
91+
expect(btn).to.be.visible;
92+
expect(btn.getAttribute('aria-disabled')).to.equal('true');
93+
94+
userEvent.click(btn);
95+
96+
expect(onResume).not.to.have.been.called;
97+
});
98+
99+
it('Describes the shardKey', async function () {
100+
await renderWithProps();
101+
102+
const title = await screen.findByTestId(
103+
'existing-shardkey-description-title'
104+
);
105+
expect(title).to.be.visible;
106+
expect(title.textContent).to.equal(
107+
`${baseProps.namespace} is configured with the following shard key:`
108+
);
109+
const list = await screen.findByTestId(
110+
'existing-shardkey-description-content'
111+
);
112+
expect(list).to.be.visible;
113+
expect(list.textContent).to.contain(`"location", "secondary"`);
114+
});
115+
});

packages/compass-global-writes/src/components/states/shard-key-correct.spec.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,6 @@ describe('ShardKeyCorrect', function () {
7676
expect(onUnmanageNamespace).not.to.have.been.called;
7777
});
7878

79-
it('Provides link to Edit Configuration', async function () {
80-
const connectionInfo = {
81-
id: 'testConnection',
82-
connectionOptions: {
83-
connectionString: 'mongodb://test',
84-
},
85-
atlasMetadata: {
86-
projectId: 'project1',
87-
clusterName: 'myCluster',
88-
} as ConnectionInfo['atlasMetadata'],
89-
};
90-
await renderWithProps(undefined, {
91-
connectionInfo,
92-
});
93-
94-
const link = await screen.findByRole('link', {
95-
name: /Edit Configuration/,
96-
});
97-
const expectedHref = `/v2/${connectionInfo.atlasMetadata?.projectId}#/clusters/edit/${connectionInfo.atlasMetadata?.clusterName}`;
98-
99-
expect(link).to.be.visible;
100-
expect(link).to.have.attribute('href', expectedHref);
101-
});
102-
10379
it('Describes the shardKey', async function () {
10480
await renderWithProps();
10581

0 commit comments

Comments
 (0)