Files
chatwoot/spec/presenters/reports/time_format_presenter_spec.rb
Pranav cb42be8e65 feat(v4): Update the report pages to show aggregate values (#10766)
This PR updates the report pages for agents, inboxes, and teams by
replacing charts with aggregate values (under a feature flag). Users can
click on any item to view more details if needed. Most users seem to
prefer aggregate values, so this change will likely stay.

The PR also includes a few fixes:

- The summary reports now use the same logic for both the front-end and
CSV exports.
- Fixed an issue where a single quote was being added to values with
hyphens in CSV files. Now, ‘n/a’ is used when no value is available.
- Fixed a bug where the average value was calculated incorrectly when
multiple accounts were present.

These changes should make reports easier to use and more consistent.

### Agents:

<img width="1438" alt="Screenshot 2025-01-26 at 10 47 18 AM"
src="https://github.com/user-attachments/assets/bf2fcebc-6207-4701-9703-5c2110b7b8a0"
/>

### Inboxes
<img width="1438" alt="Screenshot 2025-01-26 at 10 47 10 AM"
src="https://github.com/user-attachments/assets/b83e1cf2-fd14-4e8e-8dcd-9033404a9f22"
/>


### Teams: 
<img width="1436" alt="Screenshot 2025-01-26 at 10 47 01 AM"
src="https://github.com/user-attachments/assets/96b1ce07-f557-42ca-8143-546a111d6458"
/>

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
2025-01-28 09:19:18 +05:30

78 lines
2.3 KiB
Ruby

require 'rails_helper'
RSpec.describe Reports::TimeFormatPresenter do
describe '#format' do
context 'when formatting days' do
it 'formats single day correctly' do
expect(described_class.new(86_400).format).to eq '1 day'
end
it 'formats multiple days correctly' do
expect(described_class.new(172_800).format).to eq '2 days'
end
it 'includes seconds with days correctly' do
expect(described_class.new(86_401).format).to eq '1 day 1 second'
end
it 'includes hours with days correctly' do
expect(described_class.new(93_600).format).to eq '1 day 2 hours'
end
it 'includes minutes with days correctly' do
expect(described_class.new(86_461).format).to eq '1 day 1 minute'
end
end
context 'when formatting hours' do
it 'formats single hour correctly' do
expect(described_class.new(3600).format).to eq '1 hour'
end
it 'formats multiple hours correctly' do
expect(described_class.new(7200).format).to eq '2 hours'
end
it 'includes seconds with hours correctly' do
expect(described_class.new(3601).format).to eq '1 hour 1 second'
end
it 'includes minutes with hours correctly' do
expect(described_class.new(3660).format).to eq '1 hour 1 minute'
end
end
context 'when formatting minutes' do
it 'formats single minute correctly' do
expect(described_class.new(60).format).to eq '1 minute'
end
it 'formats multiple minutes correctly' do
expect(described_class.new(120).format).to eq '2 minutes'
end
it 'includes seconds with minutes correctly' do
expect(described_class.new(62).format).to eq '1 minute 2 seconds'
end
end
context 'when formatting seconds' do
it 'formats multiple seconds correctly' do
expect(described_class.new(56).format).to eq '56 seconds'
end
it 'handles floating-point seconds by truncating to the nearest lower second' do
expect(described_class.new(55.2).format).to eq '55 seconds'
end
it 'formats single second correctly' do
expect(described_class.new(1).format).to eq '1 second'
end
it 'formats nil second correctly' do
expect(described_class.new.format).to eq 'N/A'
end
end
end
end