Gate event create FAB by package quota

This commit is contained in:
Codex Agent
2026-01-20 12:54:16 +01:00
parent 8a456d2c0d
commit 620dfa415a
2 changed files with 187 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { act, fireEvent, render, screen } from '@testing-library/react';
import * as api from '../../api';
const navigateMock = vi.fn();
const authState = {
@@ -62,6 +63,40 @@ vi.mock('../../api', () => ({
settings: {},
},
]),
getTenantPackagesOverview: vi.fn().mockResolvedValue({
packages: [
{
id: 1,
package_id: 1,
package_name: 'Standard',
package_type: 'endcustomer',
included_package_slug: null,
active: true,
used_events: 0,
remaining_events: null,
price: 120,
currency: 'EUR',
purchased_at: null,
expires_at: null,
package_limits: null,
},
],
activePackage: {
id: 1,
package_id: 1,
package_name: 'Standard',
package_type: 'endcustomer',
included_package_slug: null,
active: true,
used_events: 0,
remaining_events: null,
price: 120,
currency: 'EUR',
purchased_at: null,
expires_at: null,
package_limits: null,
},
}),
}));
vi.mock('../../auth/tokens', () => ({
@@ -192,4 +227,52 @@ describe('MobileEventsPage', () => {
expect(screen.getByText('Summer Gala')).toBeInTheDocument();
expect(screen.queryByText('Demo Event')).not.toBeInTheDocument();
});
it('shows the create button when an active package has remaining events', async () => {
render(<MobileEventsPage />);
expect(await screen.findByText('New event')).toBeInTheDocument();
});
it('hides the create button when no remaining events are available', async () => {
vi.mocked(api.getTenantPackagesOverview).mockResolvedValueOnce({
packages: [
{
id: 2,
package_id: 2,
package_name: 'Reseller',
package_type: 'reseller',
included_package_slug: 'standard',
active: true,
used_events: 5,
remaining_events: 0,
price: 240,
currency: 'EUR',
purchased_at: null,
expires_at: null,
package_limits: { max_events_per_year: 5 },
},
],
activePackage: {
id: 2,
package_id: 2,
package_name: 'Reseller',
package_type: 'reseller',
included_package_slug: 'standard',
active: true,
used_events: 5,
remaining_events: 0,
price: 240,
currency: 'EUR',
purchased_at: null,
expires_at: null,
package_limits: { max_events_per_year: 5 },
},
});
render(<MobileEventsPage />);
expect(await screen.findByText('Demo Event')).toBeInTheDocument();
expect(screen.queryByText('New event')).not.toBeInTheDocument();
});
});