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
46 changes: 35 additions & 11 deletions src/components/field/field.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
import { palette } from '@leafygreen-ui/palette';
import { ComponentProps } from 'react';

import { render, screen } from '@/mocks/testing-utils';
import { Field } from '@/components/field/field';
import { DEFAULT_PREVIEW_GROUP_AREA } from '@/utilities/get-preview-group-area';

describe('field', () => {
const DEFAULT_PROPS: ComponentProps<typeof Field> = {
nodeType: 'collection',
name: 'ordersId',
type: 'objectId',
glyphs: ['key', 'link'],
previewGroupArea: DEFAULT_PREVIEW_GROUP_AREA,
spacing: 2,
depth: 1,
};
it('Should have field', () => {
render(
<Field
nodeType={'collection'}
name={'ordersId'}
type={'objectId'}
glyphs={['key', 'link']}
previewGroupArea={DEFAULT_PREVIEW_GROUP_AREA}
spacing={2}
depth={1}
/>,
);
render(<Field {...DEFAULT_PROPS} />);
expect(screen.getByText('ordersId')).toBeInTheDocument();
expect(screen.getByText('objectId')).toBeInTheDocument();
expect(screen.getByRole('img', { name: 'Key Icon' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: 'Link Icon' })).toBeInTheDocument();
});
describe('With glyphs', () => {
it('With disabled', () => {
render(<Field {...DEFAULT_PROPS} variant={'disabled'} />);
expect(screen.getByRole('img', { name: 'Key Icon' })).toHaveAttribute('color', '#889397');
expect(screen.getByRole('img', { name: 'Link Icon' })).toHaveAttribute('color', '#889397');
});
it('With primary', () => {
render(<Field {...DEFAULT_PROPS} variant={'primary'} />);
expect(screen.getByRole('img', { name: 'Key Icon' })).toHaveAttribute('color', palette.blue.base);
expect(screen.getByRole('img', { name: 'Link Icon' })).toHaveAttribute('color', palette.gray.dark1);
});
it('With collection type', () => {
render(<Field {...DEFAULT_PROPS} />);
expect(screen.getByRole('img', { name: 'Key Icon' })).toHaveAttribute('color', palette.green.dark1);
expect(screen.getByRole('img', { name: 'Link Icon' })).toHaveAttribute('color', palette.gray.dark1);
});
it('With table type', () => {
render(<Field {...DEFAULT_PROPS} nodeType={'table'} />);
expect(screen.getByRole('img', { name: 'Key Icon' })).toHaveAttribute('color', palette.purple.base);
expect(screen.getByRole('img', { name: 'Link Icon' })).toHaveAttribute('color', palette.gray.dark1);
});
});
});
2 changes: 1 addition & 1 deletion src/components/field/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const Field = ({
const getIconColor = (glyph: NodeGlyph) => {
if (isDisabled) {
return color[theme].text.disabled.default;
} else if (variant === 'primary') {
} else if (variant === 'primary' && glyph === 'key') {
return palette.blue.base;
} else {
return glyph === 'key' ? getAccent() : internalTheme.node.icon;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line also has a check if the glyph is 'key'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user sets the variant as "primary" then only the key (And no other glyphs) will be blue. If there is no variant, the key defaults back to the accent color (Green for MongoDB, purple for Relational)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I missed that, sleepy day for me

Expand Down
2 changes: 1 addition & 1 deletion src/components/node/node.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const NodeWithPrimaryField: Story = {
name: 'customerId',
type: 'string',
variant: 'primary',
glyphs: ['key'],
glyphs: ['key', 'link'],
},
],
},
Expand Down