Skip to content

Commit 25aa7d2

Browse files
committed
Fix tests
Signed-off-by: Milos Dzepina <milos@aragon.org>
1 parent 33eb4c4 commit 25aa7d2

3 files changed

Lines changed: 23 additions & 141 deletions

File tree

src/modules/assets/copy/modulesCopy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export const modulesCopy = {
9595
likelyToSucceed: 'Likely to succeed',
9696
likelyToFail: 'Likely to fail',
9797
unknown: 'Unknown',
98+
now: 'Now',
9899
},
99100
proposalDataListItemStatus: {
100101
voted: 'Voted',
Lines changed: 16 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render, screen } from '@testing-library/react';
2-
import userEvent from '@testing-library/user-event';
32
import { DateTime } from 'luxon';
43
import { GukCoreProvider } from '../../../../core';
54
import type { IProposalActionSimulationStructureProps } from './proposalActionSimulationStructure';
@@ -20,6 +19,14 @@ describe('<ProposalActionSimulationStructure /> component', () => {
2019
);
2120
};
2221

22+
it('renders all definition list items', () => {
23+
render(createTestComponent());
24+
25+
expect(screen.getByText('Total actions')).toBeInTheDocument();
26+
expect(screen.getByText('Last simulation')).toBeInTheDocument();
27+
expect(screen.getByText('Executable')).toBeInTheDocument();
28+
});
29+
2330
it('renders the total actions count', () => {
2431
render(createTestComponent({ totalActions: 5 }));
2532
expect(screen.getByText('5 actions')).toBeInTheDocument();
@@ -30,35 +37,23 @@ describe('<ProposalActionSimulationStructure /> component', () => {
3037
expect(screen.getByText('1 action')).toBeInTheDocument();
3138
});
3239

33-
it('renders "No simulation yet" when no last simulation is provided', () => {
40+
it('renders "Never" when no last simulation is provided', () => {
3441
render(createTestComponent());
35-
expect(screen.getByText('No simulation yet')).toBeInTheDocument();
42+
expect(screen.getByText('Never')).toBeInTheDocument();
3643
});
3744

3845
it('renders relative time for recent simulation', () => {
39-
const recentTime = DateTime.now().minus({ minutes: 30 });
46+
const recentTime = DateTime.now().minus({ days: 2 });
4047
render(createTestComponent({ lastSimulation: recentTime }));
41-
expect(screen.getByText('Now')).toBeInTheDocument();
48+
expect(screen.getByText('2 days ago')).toBeInTheDocument();
4249
});
4350

4451
it('renders "Now" for very recent simulation', () => {
45-
const veryRecentTime = DateTime.now().minus({ minutes: 15 });
52+
const veryRecentTime = DateTime.now().minus({ seconds: 30 });
4653
render(createTestComponent({ lastSimulation: veryRecentTime }));
4754
expect(screen.getByText('Now')).toBeInTheDocument();
4855
});
4956

50-
it('renders hours ago for simulation within a day', () => {
51-
const hoursAgo = DateTime.now().minus({ hours: 3 });
52-
render(createTestComponent({ lastSimulation: hoursAgo }));
53-
expect(screen.getByText('3 hours ago')).toBeInTheDocument();
54-
});
55-
56-
it('renders days ago for simulation within a week', () => {
57-
const daysAgo = DateTime.now().minus({ days: 2 });
58-
render(createTestComponent({ lastSimulation: daysAgo }));
59-
expect(screen.getByText('2 days ago')).toBeInTheDocument();
60-
});
61-
6257
it('renders the execution status label', () => {
6358
render(
6459
createTestComponent({
@@ -76,137 +71,18 @@ describe('<ProposalActionSimulationStructure /> component', () => {
7671
}),
7772
);
7873

79-
// Check that the loading text is shown
80-
expect(screen.getByText('Simulating...')).toBeInTheDocument();
81-
82-
// The success icon should not be present during loading
83-
expect(screen.queryByTestId('SUCCESS')).not.toBeInTheDocument();
84-
});
85-
86-
it('renders success icon when executable', () => {
87-
render(
88-
createTestComponent({
89-
status: 'success',
90-
}),
91-
);
92-
expect(screen.getByTestId('SUCCESS')).toBeInTheDocument();
93-
});
94-
95-
it('renders critical icon when failed', () => {
96-
render(
97-
createTestComponent({
98-
status: 'failure',
99-
}),
100-
);
101-
expect(screen.getByTestId('CRITICAL')).toBeInTheDocument();
102-
expect(screen.getByText('Likely to fail')).toBeInTheDocument();
103-
});
104-
105-
it('renders info icon when unknown', () => {
106-
render(
107-
createTestComponent({
108-
status: 'unknown',
109-
}),
110-
);
111-
expect(screen.getByTestId('INFO')).toBeInTheDocument();
112-
expect(screen.getByText('Not simulated')).toBeInTheDocument();
113-
});
114-
115-
it('calls onSimulateAgain when simulate again button is clicked', async () => {
116-
const user = userEvent.setup();
117-
const onSimulateAgain = jest.fn();
118-
119-
render(createTestComponent({ onSimulate: onSimulateAgain }));
120-
121-
const simulateButton = screen.getByRole('button', { name: /simulate again/i });
122-
await user.click(simulateButton);
123-
124-
expect(onSimulateAgain).toHaveBeenCalledTimes(1);
125-
});
126-
127-
it('opens tenderly URL in new window when tenderlyUrl is provided', async () => {
128-
const user = userEvent.setup();
129-
const mockOpen = jest.fn();
130-
const originalOpen = window.open;
131-
window.open = mockOpen;
132-
133-
const tenderlyUrl = 'https://dashboard.tenderly.co/simulation/12345';
134-
render(createTestComponent({ tenderlyUrl }));
135-
136-
const tenderlyButton = screen.getByRole('button', { name: /view on tenderly/i });
137-
await user.click(tenderlyButton);
138-
139-
expect(mockOpen).toHaveBeenCalledWith(tenderlyUrl, '_blank');
140-
141-
window.open = originalOpen;
142-
});
143-
144-
it('shows loading state on simulate again button when isSimulating is true', () => {
145-
render(createTestComponent({ isSimulating: true }));
146-
147-
const simulateButton = screen.getByRole('button', { name: /simulate again/i });
148-
expect(simulateButton).toHaveAttribute('aria-disabled', 'true');
149-
});
150-
151-
it('renders all definition list items', () => {
152-
render(createTestComponent());
153-
154-
expect(screen.getByText('Total actions')).toBeInTheDocument();
155-
expect(screen.getByText('Last simulation')).toBeInTheDocument();
156-
expect(screen.getByText('Executable')).toBeInTheDocument();
157-
});
158-
159-
it('handles string ISO date input', () => {
160-
const isoDate = '2024-01-15T10:30:00Z';
161-
render(createTestComponent({ lastSimulation: isoDate }));
162-
163-
// Should render some form of the date, not "No simulation yet"
164-
expect(screen.queryByText('No simulation yet')).not.toBeInTheDocument();
165-
});
166-
167-
it('handles timestamp number input', () => {
168-
const timestamp = DateTime.now().minus({ hours: 1 }).toMillis();
169-
render(createTestComponent({ lastSimulation: timestamp }));
170-
171-
expect(screen.getByText('1 hour ago')).toBeInTheDocument();
74+
expect(screen.getAllByText('Simulating')).toHaveLength(3);
17275
});
17376

17477
it('shows simulate button by default when isSimulatable is not specified', () => {
17578
render(createTestComponent());
17679

177-
expect(screen.getByRole('button', { name: /simulate again/i })).toBeInTheDocument();
178-
});
179-
180-
it('shows simulate button when isSimulatable is true', () => {
181-
render(createTestComponent({ isSimulatable: true }));
182-
183-
expect(screen.getByRole('button', { name: /simulate again/i })).toBeInTheDocument();
80+
expect(screen.getByText(/simulate/i).closest('button')).toBeInTheDocument();
18481
});
18582

18683
it('hides simulate button when isSimulatable is false', () => {
18784
render(createTestComponent({ isSimulatable: false }));
18885

189-
expect(screen.queryByRole('button', { name: /simulate again/i })).not.toBeInTheDocument();
190-
});
191-
192-
it('always shows tenderly button regardless of isSimulatable value', () => {
193-
render(createTestComponent({ isSimulatable: false, tenderlyUrl: 'https://tenderly.co/test' }));
194-
195-
expect(screen.queryByRole('button', { name: /simulate again/i })).not.toBeInTheDocument();
196-
expect(screen.getByRole('button', { name: /view on tenderly/i })).toBeInTheDocument();
197-
});
198-
199-
it('positions tenderly button on the right when simulate button is not shown', () => {
200-
render(createTestComponent({ isSimulatable: false }));
201-
202-
const tenderlyButton = screen.getByRole('button', { name: /view on tenderly/i });
203-
expect(tenderlyButton).toHaveClass('md:ml-auto');
204-
});
205-
206-
it('does not add ml-auto class to tenderly button when simulate button is shown', () => {
207-
render(createTestComponent({ isSimulatable: true }));
208-
209-
const tenderlyButton = screen.getByRole('button', { name: /view on tenderly/i });
210-
expect(tenderlyButton).not.toHaveClass('md:ml-auto');
86+
expect(screen.queryByText(/simulate/i)).toBeNull();
21187
});
21288
});

src/modules/components/proposal/proposalActionSimulationStructure/proposalActionSimulationStructure.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ export const ProposalActionSimulationStructure: React.FC<IProposalActionSimulati
102102
}
103103

104104
const now = DateTime.now();
105+
const diffInMinutes = now.diff(date, 'minutes').minutes;
105106
const diffInDays = now.diff(date, 'days').days;
106107

108+
if (diffInMinutes < 2) {
109+
return copy.proposalActionSimulationStructure.now;
110+
}
111+
107112
return formatterUtils.formatDate(date, {
108-
format: diffInDays > 1 ? DateFormat.YEAR_MONTH_DAY_TIME : DateFormat.RELATIVE,
113+
format: diffInDays > 3 ? DateFormat.YEAR_MONTH_DAY_TIME : DateFormat.RELATIVE,
109114
});
110115
};
111116

0 commit comments

Comments
 (0)