Skip to content

Commit bab4502

Browse files
Correctly show active/passive for an active-active domain in metadata (#999)
Show active cluster(s) based on activeClustersByRegion for an active-active domain, in Domain Metadata
1 parent 06032eb commit bab4502

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

src/views/domain-page/domain-page-metadata-clusters/__tests__/domain-page-metadata-clusters.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ import {
44
mockDomainDescription,
55
mockDomainDescriptionSingleCluster,
66
} from '../../__fixtures__/domain-description';
7+
import * as isActiveClusterModule from '../../helpers/is-active-cluster';
78
import DomainPageMetadataClusters from '../domain-page-metadata-clusters';
89

10+
jest.mock('../../helpers/is-active-cluster', () => ({
11+
__esModule: true,
12+
default: jest.fn().mockReturnValue(false),
13+
}));
14+
915
describe(DomainPageMetadataClusters.name, () => {
16+
beforeEach(() => {
17+
jest.clearAllMocks();
18+
});
19+
1020
it('renders plain text for single cluster', async () => {
1121
render(
1222
<DomainPageMetadataClusters {...mockDomainDescriptionSingleCluster} />
@@ -17,6 +27,11 @@ describe(DomainPageMetadataClusters.name, () => {
1727
});
1828

1929
it('renders active/passive labels and links for multiple clusters', () => {
30+
jest
31+
.spyOn(isActiveClusterModule, 'default')
32+
.mockReturnValueOnce(true) // cluster_1 is active
33+
.mockReturnValueOnce(false); // cluster_2 is passive
34+
2035
const { container } = render(
2136
<DomainPageMetadataClusters {...mockDomainDescription} />
2237
);

src/views/domain-page/domain-page-metadata-clusters/domain-page-metadata-clusters.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import Link from '@/components/link/link';
44

55
import { type DomainDescription } from '../domain-page.types';
6+
import isActiveCluster from '../helpers/is-active-cluster';
67

78
import { styled } from './domain-page-metadata-clusters.styles';
89

@@ -17,10 +18,13 @@ export default function DomainPageMetadataClusters(
1718
return (
1819
<styled.ClusterTextContainer>
1920
{domainDescription.clusters.map((cluster, index) => {
20-
const replicationStatusLabel =
21-
cluster.clusterName === domainDescription.activeClusterName
22-
? 'active'
23-
: 'passive';
21+
const replicationStatusLabel = isActiveCluster(
22+
domainDescription,
23+
cluster.clusterName
24+
)
25+
? 'active'
26+
: 'passive';
27+
2428
return (
2529
<React.Fragment key={cluster.clusterName}>
2630
<Link
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { getDomainObj } from '@/views/domains-page/__fixtures__/domains';
2+
import { mockActiveActiveDomain } from '@/views/shared/active-active/__fixtures__/active-active-domain';
3+
4+
import isActiveCluster from '../is-active-cluster';
5+
6+
jest.mock('@/views/shared/active-active/helpers/is-active-active-domain');
7+
8+
describe(isActiveCluster.name, () => {
9+
it('should return true when cluster is in activeClusters.regionToCluster for active-active domain', () => {
10+
expect(isActiveCluster(mockActiveActiveDomain, 'cluster0')).toBe(true);
11+
expect(isActiveCluster(mockActiveActiveDomain, 'cluster1')).toBe(true);
12+
});
13+
14+
it('should return false when cluster is not in activeClusters.regionToCluster for active-active domain', () => {
15+
const domain = mockActiveActiveDomain;
16+
const cluster = 'non-existent-cluster';
17+
18+
const result = isActiveCluster(domain, cluster);
19+
20+
expect(result).toBe(false);
21+
});
22+
23+
it('should return true when cluster matches activeClusterName for active-passive domain', () => {
24+
const domain = getDomainObj({
25+
id: 'test-domain-id',
26+
name: 'test-domain',
27+
activeClusterName: 'cluster_1',
28+
activeClusters: null,
29+
});
30+
const cluster = 'cluster_1';
31+
32+
const result = isActiveCluster(domain, cluster);
33+
34+
expect(result).toBe(true);
35+
});
36+
37+
it('should return false when cluster does not match activeClusterName for regular domain', () => {
38+
const domain = getDomainObj({
39+
id: 'test-domain-id',
40+
name: 'test-domain',
41+
activeClusterName: 'cluster_1',
42+
activeClusters: null,
43+
});
44+
const cluster = 'cluster_2';
45+
46+
const result = isActiveCluster(domain, cluster);
47+
48+
expect(result).toBe(false);
49+
});
50+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import isActiveActiveDomain from '@/views/shared/active-active/helpers/is-active-active-domain';
2+
3+
import { type DomainDescription } from '../domain-page.types';
4+
5+
export default function isActiveCluster(
6+
domain: DomainDescription,
7+
cluster: string
8+
) {
9+
if (isActiveActiveDomain(domain)) {
10+
return (
11+
Object.values(domain.activeClusters.regionToCluster).find(
12+
(activeClusterInfo) => activeClusterInfo.activeClusterName === cluster
13+
) !== undefined
14+
);
15+
}
16+
17+
return cluster === domain.activeClusterName;
18+
}

0 commit comments

Comments
 (0)