|
| 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 | +}); |
0 commit comments