Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,51 @@ describe('<RemoteClusterList />', () => {
});
});

describe('can search', () => {
let table;
let component;
let form;

const remoteClusters = [
{
name: 'simple_remote_cluster',
seeds: ['127.0.0.1:2000', '127.0.0.2:3000'],
},
{
name: 'remote_cluster_with_proxy',
proxyAddress: '192.168.0.1:80',
mode: PROXY_MODE,
},
];

beforeEach(async () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);

await act(async () => {
({ table, component, form } = setup());
});

component.update();
});

test('without any search params it should show all clusters', () => {
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
expect(tableCellsValues.length).toBe(2);
});

test('search by seed works', () => {
form.setInputValue('remoteClusterSearch', 'simple');
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
expect(tableCellsValues.length).toBe(1);
});

test('search by proxyAddress works', () => {
form.setInputValue('remoteClusterSearch', 'proxy');
const { tableCellsValues } = table.getMetaData('remoteClusterListTable');
expect(tableCellsValues.length).toBe(1);
});
});

describe('when there are multiple pages of remote clusters', () => {
let table;
let actions;
Expand All @@ -91,10 +136,18 @@ describe('<RemoteClusterList />', () => {
];

for (let i = 0; i < 29; i++) {
remoteClusters.push({
name: `name${i}`,
seeds: [],
});
if (i % 2 === 0) {
remoteClusters.push({
name: `cluster-${i}`,
seeds: [],
});
} else {
remoteClusters.push({
name: `cluster_with_proxy-${i}`,
proxyAddress: `127.0.0.1:10${i}`,
mode: PROXY_MODE,
});
}
}

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ const getFilteredClusters = (clusters, queryText) => {
const normalizedSearchText = queryText.toLowerCase();

return clusters.filter((cluster) => {
const { name, seeds } = cluster;
const { name, seeds, proxyAddress } = cluster;
const normalizedName = name.toLowerCase();

if (normalizedName.toLowerCase().includes(normalizedSearchText)) {
return true;
}

return seeds.some((seed) => seed.includes(normalizedSearchText));
if (proxyAddress && proxyAddress.toLowerCase().includes(normalizedSearchText)) {
return true;
}

if (seeds) {
return seeds.some((seed) => seed.includes(normalizedSearchText));
}

return false;
});
} else {
return clusters;
Expand Down Expand Up @@ -81,6 +90,11 @@ export class RemoteClusterTable extends Component {
}

onSearch = ({ query }) => {
// There's no need to update the state if there arent any search params
if (!query) {
return;
}

const { clusters } = this.props;
const { text } = query;

Expand Down