PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.19
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.19
1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 All 182 releases
disco / backend / views / components / Analytics / __tests__ / pages / CustomerDetails.test.jsx

CustomerDetails.test.jsx in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.19, at backend/views/components/Analytics/__tests__/pages/CustomerDetails.test.jsx

111 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import '@testing-library/jest-dom';
2 import { screen } from '@testing-library/react';
3 import CustomerDetails from '../../pages/CustomerDetails';
4 import { createMockCustomer, renderWithProviders } from '../setup/helpers';
5
6 beforeAll(() => {
7 global.DISCO = { ...global.DISCO, base_currency: '$' };
8 });
9
10 jest.mock('../../features/customers/customersApi', () => ({
11 useGetCustomerQuery: jest.fn(),
12 useGetOrdersQuery: jest.fn(),
13 useGetProductsQuery: jest.fn(),
14 }));
15
16 // Mock embedded tables to isolate tests
17 jest.mock('../../components/customers/CustomerOrdersTable', () => {
18 return function MockCustomerOrdersTable() {
19 return <div data-testid="customer-orders-table">Orders Table</div>;
20 };
21 });
22
23 const {
24 useGetCustomerQuery,
25 } = require('../../features/customers/customersApi');
26
27 // Mock react-router useParams
28 jest.mock('react-router', () => ({
29 ...jest.requireActual('react-router'),
30 useParams: () => ({ customerId: '1' }),
31 }));
32
33 const mockCustomer = createMockCustomer({
34 id: 1,
35 name: 'Jane Smith',
36 email: '[email protected]',
37 state: 'New York',
38 campaigns: [{ name: 'Summer Sale' }],
39 orders: 5,
40 total_spent: 1250.0,
41 });
42
43 describe('CustomerDetails', () => {
44 afterEach(() => {
45 jest.clearAllMocks();
46 });
47
48 describe('Rendering', () => {
49 it('renders customer name and details', () => {
50 useGetCustomerQuery.mockReturnValue({
51 data: { data: mockCustomer },
52 isLoading: false,
53 });
54 renderWithProviders(<CustomerDetails />);
55
56 expect(screen.getByText('Jane Smith')).toBeInTheDocument();
57 expect(screen.getByText('[email protected]')).toBeInTheDocument();
58 expect(screen.getByText('New York')).toBeInTheDocument();
59 });
60
61 it('renders customer metrics', () => {
62 useGetCustomerQuery.mockReturnValue({
63 data: { data: mockCustomer },
64 isLoading: false,
65 });
66 renderWithProviders(<CustomerDetails />);
67
68 expect(screen.getByText('Total Spent')).toBeInTheDocument();
69 expect(screen.getByText('$1,250.00')).toBeInTheDocument();
70 });
71 });
72
73 describe('Loading states', () => {
74 it('shows skeleton loading state', () => {
75 useGetCustomerQuery.mockReturnValue({
76 data: undefined,
77 isLoading: true,
78 });
79 const { container } = renderWithProviders(<CustomerDetails />);
80
81 const pulseElements = container.querySelectorAll(
82 '.disco\\:animate-pulse'
83 );
84 expect(pulseElements.length).toBeGreaterThan(0);
85 });
86 });
87
88 describe('Customer not found', () => {
89 it('shows CustomerNotFound when customer is null', () => {
90 useGetCustomerQuery.mockReturnValue({
91 data: { data: null },
92 isLoading: false,
93 });
94 renderWithProviders(<CustomerDetails />);
95
96 expect(screen.getByText('Customer not found')).toBeInTheDocument();
97 expect(screen.getByText('Back to Customers')).toBeInTheDocument();
98 });
99
100 it('shows CustomerNotFound when data is empty', () => {
101 useGetCustomerQuery.mockReturnValue({
102 data: {},
103 isLoading: false,
104 });
105 renderWithProviders(<CustomerDetails />);
106
107 expect(screen.getByText('Customer not found')).toBeInTheDocument();
108 });
109 });
110 });
111