Skip to content

Commit 1b46597

Browse files
committed
fix: ui tests
Signed-off-by: Rafael Silva (rafaelsi) <rafaelsi@cisco.com>
1 parent 96857a3 commit 1b46597

4 files changed

Lines changed: 63 additions & 39 deletions

File tree

frontend/README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,7 @@ yarn install
4545

4646
## 🛠 Development Setup
4747

48-
### 1. Generate PWA Assets (Logo Setup)
49-
50-
> **⚠️ IMPORTANT**
51-
> Before starting development, generate the PWA assets from your logo. This step sets up all the necessary icons and splash screens for your app.
52-
53-
```bash
54-
# Generate PWA assets from the logo.svg file
55-
yarn generate-pwa-assets
56-
```
57-
58-
This script will:
59-
60-
- Generate all required PWA icons (favicon, apple-touch-icon, etc.)
61-
- Create properly sized assets from your `public/logo.svg` file
62-
- Set up the visual identity for your Progressive Web App
63-
64-
> **📝 NOTE**
65-
> Make sure you have your custom logo as `public/logo.svg` before running this command.
66-
67-
### 2. Setup Node.js Version
48+
### 1. Setup Node.js Version
6849

6950
```bash
7051
# Install NVM if you haven't already
@@ -78,7 +59,7 @@ nvm install
7859
nvm use
7960
```
8061

81-
### 3. Clone and Install Dependencies
62+
### 2. Clone and Install Dependencies
8263

8364
```bash
8465
# Clone the repository
@@ -89,7 +70,7 @@ cd identity-service/frontend
8970
yarn install
9071
```
9172

92-
### 4. Environment Configuration
73+
### 3. Environment Configuration
9374

9475
Create a `.env` file in the root directory:
9576

@@ -155,7 +136,7 @@ These options control:
155136
- **tabInactivityDuration**: Time in seconds before considering tab inactive
156137
- **syncStorage**: Whether to synchronize authentication state across browser tabs
157138

158-
### 5. Global Configuration Setup
139+
### 4. Global Configuration Setup
159140

160141
Configure the application's global settings by editing `src/config/global.ts`:
161142

@@ -185,6 +166,25 @@ export const globalConfig = {
185166

186167
**Important**: Remove any `<place-holder>` text and update all URLs, email addresses, and company information to match your actual application requirements.
187168

169+
### 5. Generate PWA Assets (Logo Setup)
170+
171+
> **⚠️ IMPORTANT**
172+
> After cloning the repository and configuring your settings, generate the PWA assets from your logo. This step sets up all the necessary icons and splash screens for your app.
173+
174+
```bash
175+
# Generate PWA assets from the logo.svg file
176+
yarn generate-pwa-assets
177+
```
178+
179+
This script will:
180+
181+
- Generate all required PWA icons (favicon, apple-touch-icon, etc.)
182+
- Create properly sized assets from your `public/logo.svg` file
183+
- Set up the visual identity for your Progressive Web App
184+
185+
> **📝 NOTE**
186+
> Make sure you have your custom logo as `public/logo.svg` before running this command.
187+
188188
### 6. Start Development Server
189189

190190
```bash

frontend/src/components/layout/public-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const PublicHeader = ({userSection}: {userSection?: ReactNode}) => {
1717
<div className="w-12">
1818
<img src="/logo.svg" alt="Logo" className="w-full" />
1919
</div>
20-
<Logo className="w-[200px] md:w-[300px] lg:w-full" />
20+
<Logo className="w-[200px] md:w-[300px] lg:w-full" data-testid="header-logo-svg" />
2121
</div>
2222
}
2323
position="fixed"

frontend/src/components/layout/tests/footer.test.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {screen} from '@testing-library/react';
99
import '@testing-library/jest-dom';
1010
import {renderWithClient} from '@/utils/tests';
1111
import {Footer} from '../footer';
12+
import {globalConfig} from '@/config/global';
1213
import userEvent from '@testing-library/user-event';
1314
import {MouseEventHandler, ReactElement, JSXElementConstructor, ReactNode, ReactPortal, Key} from 'react';
1415
import {ClassAttributes, HTMLAttributes} from 'react';
@@ -109,9 +110,19 @@ describe('Footer', () => {
109110
// Check if footer logo is rendered
110111
expect(screen.getByTestId('footer-logo')).toBeInTheDocument();
111112

112-
// Check copyright text
113+
// Check copyright text (should contain year and company name from config)
113114
const currentYear = new Date().getFullYear();
114-
expect(screen.getByText(${currentYear} Cisco Systems, Inc.`)).toBeInTheDocument();
115+
// Target the specific span element that contains the copyright text
116+
expect(
117+
screen.getByText((content, element) => {
118+
if (!element || element.tagName !== 'SPAN') {
119+
return false;
120+
}
121+
const normalizedText = element.textContent?.replace(/\s+/g, ' ').trim() || '';
122+
const expectedText = ${currentYear} ${globalConfig.company.name}`;
123+
return normalizedText.includes(expectedText);
124+
})
125+
).toBeInTheDocument();
115126

116127
// Check if all desktop links are rendered
117128
expect(screen.getByText('support@agntcy.com')).toBeInTheDocument();
@@ -132,9 +143,19 @@ describe('Footer', () => {
132143
// Check if footer logo is still rendered
133144
expect(screen.getByTestId('footer-logo')).toBeInTheDocument();
134145

135-
// Check copyright text is still present
146+
// Check copyright text is still present (should contain year and company name from config)
136147
const currentYear = new Date().getFullYear();
137-
expect(screen.getByText(${currentYear} Cisco Systems, Inc.`)).toBeInTheDocument();
148+
// Target the specific span element that contains the copyright text
149+
expect(
150+
screen.getByText((content, element) => {
151+
if (!element || element.tagName !== 'SPAN') {
152+
return false;
153+
}
154+
const normalizedText = element.textContent?.replace(/\s+/g, ' ').trim() || '';
155+
const expectedText = ${currentYear} ${globalConfig.company.name}`;
156+
return normalizedText.includes(expectedText);
157+
})
158+
).toBeInTheDocument();
138159

139160
// In mobile view, only Cookies link should be present
140161
expect(screen.queryByText('support@agntcy.com')).not.toBeInTheDocument();
@@ -166,8 +187,19 @@ describe('Footer', () => {
166187

167188
renderWithClient(<Footer />);
168189

190+
// Check that copyright contains current year and company name from config
169191
const currentYear = new Date().getFullYear();
170-
expect(screen.getByText(${currentYear} Cisco Systems, Inc.`)).toBeInTheDocument();
192+
// Target the specific span element that contains the copyright text
193+
expect(
194+
screen.getByText((content, element) => {
195+
if (!element || element.tagName !== 'SPAN') {
196+
return false;
197+
}
198+
const normalizedText = element.textContent?.replace(/\s+/g, ' ').trim() || '';
199+
const expectedText = ${currentYear} ${globalConfig.company.name}`;
200+
return normalizedText.includes(expectedText);
201+
})
202+
).toBeInTheDocument();
171203
});
172204

173205
it('has correct link for Terms & Conditions', () => {

frontend/src/components/layout/tests/public-header.test.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,12 @@ describe('PublicHeader', () => {
8383
expect(header).toHaveAttribute('data-use-divider', 'false');
8484
});
8585

86-
it('renders logo with correct link to agntcy.org', () => {
87-
renderWithClient(<PublicHeader />);
88-
89-
const logoLink = screen.getByTestId('router-link');
90-
expect(logoLink).toHaveAttribute('href', 'https://agntcy.org/');
91-
expect(logoLink).toHaveAttribute('target', '_blank');
92-
expect(logoLink).toHaveAttribute('rel', 'noopener noreferrer');
93-
});
94-
9586
it('renders logo with responsive classes', () => {
9687
renderWithClient(<PublicHeader />);
9788

9889
const logoSvg = screen.getByTestId('header-logo-svg');
99-
expect(logoSvg).toHaveClass('w-[250px]', 'md:w-[300px]', 'lg:w-full');
90+
// Check the actual classes used in the component
91+
expect(logoSvg).toHaveClass('w-[200px]', 'md:w-[300px]', 'lg:w-full');
10092
});
10193

10294
it('renders default user section with login and register buttons when no userSection provided', () => {

0 commit comments

Comments
 (0)