Skip to content

Commit 2b97ac9

Browse files
mariush2Copilot
andauthored
✨ Created fallback version of app icon (#1197)
* ✨ Created fallback version of app icon * Update src/molecules/ApplicationIcon/ApplicationIcon.utils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * ✅ Created tests for fallback app icon * refactor: Move application icon content to separate component * refactor: Remove duplicate types * test: Fixing tests * test: Add test for name not found in application icon new --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 714d70f commit 2b97ac9

35 files changed

Lines changed: 280 additions & 178 deletions

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/molecules/ApplicationIcon/ApplicationIcon.stories.tsx

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { Meta, StoryFn } from '@storybook/react-vite';
1+
import { faker } from '@faker-js/faker';
2+
import { Meta, StoryObj } from '@storybook/react-vite';
23

3-
import { ApplicationIcon, ApplicationIconProps } from './ApplicationIcon';
4+
import { ApplicationIcon } from './ApplicationIcon';
5+
import { VariantShowcase } from 'src/storybook/VariantShowcase';
6+
7+
import { expect } from 'storybook/test';
48

59
const meta: Meta<typeof ApplicationIcon> = {
610
title: 'Molecules/ApplicationIcon',
@@ -40,6 +44,48 @@ const meta: Meta<typeof ApplicationIcon> = {
4044

4145
export default meta;
4246

43-
export const Example: StoryFn<ApplicationIconProps> = (args) => (
44-
<ApplicationIcon {...args} />
45-
);
47+
type Story = StoryObj<typeof ApplicationIcon>;
48+
49+
export const Default: Story = {};
50+
51+
export const Fallback: Story = {
52+
parameters: {
53+
layout: 'centered',
54+
},
55+
render: (args) => (
56+
<VariantShowcase
57+
GenericComponent={ApplicationIcon}
58+
otherProps={args}
59+
rows={[
60+
...Array.from({ length: 5 })
61+
.map(() => faker.book.title())
62+
.map((name) => ({
63+
label: name,
64+
value: {
65+
name,
66+
},
67+
})),
68+
]}
69+
/>
70+
),
71+
};
72+
73+
export const TestFallback: Story = {
74+
tags: ['test-only'],
75+
args: {
76+
name: 'some random app name',
77+
},
78+
play: async ({ canvas }) => {
79+
await expect(canvas.getByText('SR')).toBeInTheDocument();
80+
},
81+
};
82+
83+
export const TestFallbackShort: Story = {
84+
tags: ['test-only'],
85+
args: {
86+
name: 'some',
87+
},
88+
play: async ({ canvas }) => {
89+
await expect(canvas.getByText('S')).toBeInTheDocument();
90+
},
91+
};

src/molecules/ApplicationIcon/ApplicationIcon.test.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
adca,
77
bravos,
88
dasha,
9-
fallback,
109
fluxMaps,
1110
forecastFormatter,
1211
fourDInsight,
@@ -132,17 +131,6 @@ test('Renders correct icon, even with wrong casing', () => {
132131
}
133132
});
134133

135-
test("Renders fallback when name isn't found", () => {
136-
render(
137-
<ApplicationIcon name={'name not found' as ApplicationIconProps['name']} />
138-
);
139-
140-
expect(screen.getByTestId('eds-icon-path')).toHaveAttribute(
141-
'd',
142-
fallback.svgPathData
143-
);
144-
});
145-
146134
test('Renders without shapes when iconOnly=true when single icon', () => {
147135
const { rerender } = render(<ApplicationIcon name="acquire" iconOnly />);
148136

@@ -152,14 +140,6 @@ test('Renders without shapes when iconOnly=true when single icon', () => {
152140
}
153141
});
154142

155-
test('Renders equinor logo as fallback when iconOnly=true', () => {
156-
render(<ApplicationIcon name="hei" iconOnly />);
157-
158-
const path = screen.getByTestId('eds-icon-path');
159-
160-
expect(path).toHaveAttribute('d', fallback.svgPathData);
161-
});
162-
163143
test('App icon with multiple icons renders correctly', () => {
164144
render(<ApplicationIcon name="bravos" />);
165145

src/molecules/ApplicationIcon/ApplicationIcon.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Acquire } from './Icons/Acquire';
44
import { Adca } from './Icons/Adca';
55
import { Bravos } from './Icons/Bravos';
66
import { Dasha } from './Icons/Dasha';
7-
import { Fallback } from './Icons/Fallback';
7+
import { FluxMaps } from './Icons/FluxMaps';
88
import { ForecastFormatter } from './Icons/ForecastFormatter';
99
import { FourDInsight } from './Icons/FourDInsight';
1010
import { InPress } from './Icons/InPress';
@@ -18,7 +18,7 @@ import { Recap } from './Icons/Recap';
1818
import { Sam } from './Icons/Sam';
1919
import { SubsurfacePortal } from './Icons/SubsurfacePortal';
2020
import { AppIconProps } from './ApplicationIcon.types';
21-
import { FluxMaps } from 'src/molecules/ApplicationIcon/Icons/FluxMaps';
21+
import { Fallback } from './Fallback';
2222

2323
export type ApplicationName =
2424
| 'adca'
@@ -100,6 +100,7 @@ export const ApplicationIcon = forwardRef<HTMLDivElement, ApplicationIconProps>(
100100
iconOnly={iconOnly}
101101
withHover={withHover}
102102
grayScale={grayScale}
103+
name={name}
103104
/>
104105
);
105106
return (
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { ShapeProps } from 'src/molecules/ApplicationIcon/ApplicationIconBase/ApplicationIconBase';
2+
3+
export function nameToAcronym(name: string): string {
4+
const split = name.toUpperCase().split(' ');
5+
6+
if (split.length === 1) return name.toUpperCase()[0];
7+
8+
return `${split[0][0]}${split[1][0]}`;
9+
}
10+
11+
export function nameToShapes(name: string) {
12+
const availableShapes: ShapeProps[][] = [
13+
[
14+
{
15+
top: -16,
16+
left: -17,
17+
rotation: 325,
18+
},
19+
{
20+
top: 26,
21+
left: 11,
22+
rotation: 193,
23+
},
24+
],
25+
[
26+
{
27+
top: -31,
28+
left: -17,
29+
rotation: 343,
30+
},
31+
{
32+
top: 42,
33+
left: 32,
34+
rotation: 182,
35+
},
36+
],
37+
[
38+
{
39+
top: -45,
40+
left: -5,
41+
rotation: 25,
42+
},
43+
{
44+
top: 64,
45+
left: -5,
46+
rotation: 5,
47+
},
48+
],
49+
[
50+
{
51+
top: -16,
52+
left: -31,
53+
rotation: 339,
54+
},
55+
{
56+
top: 52,
57+
left: -5,
58+
rotation: 220,
59+
},
60+
],
61+
[
62+
{
63+
top: -16,
64+
left: -17,
65+
rotation: 328,
66+
},
67+
{
68+
top: 26,
69+
left: 11,
70+
rotation: 193,
71+
},
72+
],
73+
[
74+
{
75+
top: -25,
76+
left: -20,
77+
rotation: -5,
78+
},
79+
{
80+
top: 12,
81+
left: 45,
82+
rotation: -70,
83+
},
84+
],
85+
];
86+
87+
const index =
88+
name
89+
.split('')
90+
.map((c) => c.charCodeAt(0))
91+
.reduce((a, b) => a + b, 0) % availableShapes.length;
92+
93+
return availableShapes[index];
94+
}

0 commit comments

Comments
 (0)