Skip to content
Open
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 @@ -42,4 +42,14 @@ describe('MetadataLabels', () => {
`"<div data-testid="label-group" class="co-label-group metadata-labels-group" data-num-labels="10"><span data-testid="label" class="co-m-pod co-m-expand co-label" data-color="blue" data-href="/search?kind=Pod&amp;q=no-value-label"><span class="co-label__key" data-test="label-key">no-value-label</span></span></div>"`,
);
});

it('renders with a custom numLabels', () => {
expect(
renderToStaticMarkup(
<MetadataLabels kind="Deployment" labels={{ app: 'frontend' }} numLabels={3} />,
),
).toMatchInlineSnapshot(
`"<div data-testid="label-group" class="co-label-group metadata-labels-group" data-num-labels="3"><span data-testid="label" class="co-m-deployment co-m-expand co-label" data-color="blue" data-href="/search?kind=Deployment&amp;q=app=frontend"><span class="co-label__key" data-test="label-key">app</span><span class="co-label__eq">=</span><span class="co-label__value">frontend</span></span></div>"`,
);
});
});
38 changes: 36 additions & 2 deletions src/gitops/topology/actions/creators.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getDeleteRolloutAction, editRollout } from './creators';

describe('topology action creators', () => {
it('getDeleteRolloutAction', () => {
it('returns the delete action id and label', () => {
const action = getDeleteRolloutAction(() => {});
expect({ id: action.id, label: action.label }).toMatchInlineSnapshot(`
{
Expand All @@ -11,7 +11,15 @@ describe('topology action creators', () => {
`);
});

it('editRollout', () => {
it('calls the delete modal from the action', () => {
const deleteModal = jest.fn();
const action = getDeleteRolloutAction(deleteModal);
expect(typeof action.cta).toBe('function');
(action.cta as () => void)();
expect(deleteModal).toHaveBeenCalledTimes(1);
});

it('returns the edit action with a yaml href', () => {
const action = editRollout({
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Rollout',
Expand All @@ -27,4 +35,30 @@ describe('topology action creators', () => {
}
`);
});

it('builds the edit href when namespace is missing', () => {
const action = editRollout({
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Rollout',
metadata: { name: 'my-rollout' },
} as any);
expect(action.cta).toMatchInlineSnapshot(`
{
"href": "/ns/undefined/argoproj.io~v1alpha1~Rollout/my-rollout/yaml",
}
`);
});

it('builds the edit href when name is missing', () => {
const action = editRollout({
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Rollout',
metadata: { namespace: 'default' },
} as any);
expect(action.cta).toMatchInlineSnapshot(`
{
"href": "/ns/default/argoproj.io~v1alpha1~Rollout/undefined/yaml",
}
`);
});
});
26 changes: 26 additions & 0 deletions src/gitops/utils/components/ExternalLink/ExternalLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,30 @@ describe('ExternalLink', () => {
`"<a class="co-external-link" href="https://example.com" target="_blank" rel="noopener noreferrer" data-test-id="test-link">Link</a>"`,
);
});

it('renders href and target without text', () => {
expect(renderToStaticMarkup(<ExternalLink href="https://example.com" />)).toMatchInlineSnapshot(
`"<a class="co-external-link" href="https://example.com" target="_blank" rel="noopener noreferrer"></a>"`,
);
});

it('uses children instead of text when both are set', () => {
expect(
renderToStaticMarkup(
<ExternalLink href="https://example.com" text="Ignored">
Visible
</ExternalLink>,
),
).toMatchInlineSnapshot(
`"<a class="co-external-link" href="https://example.com" target="_blank" rel="noopener noreferrer">Visible</a>"`,
);
});

it('renders an empty link when children are empty', () => {
expect(
renderToStaticMarkup(<ExternalLink href="https://example.com">{''}</ExternalLink>),
).toMatchInlineSnapshot(
`"<a class="co-external-link" href="https://example.com" target="_blank" rel="noopener noreferrer"></a>"`,
);
});
});
Loading