// The profile menu's account section (AccountSwitcher): the current business with its badge, and a
// "Switch account" toggle only for people in more than one business; each business keeps its
// badge colour.
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import { AccountBadge, AccountSwitcher } from './AccountSwitcher';

const admedia = { id: '01a1-admedia', slug: 'admedia', name: 'AdMedia' };
const influential = { id: '01a1-influential', slug: 'influential', name: 'Influential' };

describe('AccountSwitcher', () => {
  it('shows the current account, and a switch toggle only with other accounts', () => {
    const single = renderToStaticMarkup(
      <AccountSwitcher
        current={admedia}
        role="admin"
        memberships={[{ business: admedia, role: 'admin' }]}
        switching={false}
        onSwitch={() => {}}
      />,
    );
    expect(single).toContain('AdMedia');
    expect(single).toContain('admedia · Admin');
    expect(single).not.toContain('Switch account');

    const several = renderToStaticMarkup(
      <AccountSwitcher
        current={admedia}
        role="standard"
        memberships={[
          { business: admedia, role: 'standard' },
          { business: influential, role: 'admin' },
        ]}
        switching={false}
        onSwitch={() => {}}
      />,
    );
    expect(several).toContain('Switch account');
    expect(several).toContain('admedia · Standard');
    // The list opens on click; closed, it is not in the page.
    expect(several).not.toContain('All accounts');
  });

  it('gives a business the same badge colour every time', () => {
    const a = renderToStaticMarkup(<AccountBadge business={influential} />);
    const b = renderToStaticMarkup(<AccountBadge business={{ ...influential }} />);
    expect(a).toBe(b);
    expect(a).toContain('>I<');
  });
});
