/**********************************************************************
 * Copyright (C) 2023-2024 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 ***********************************************************************/

import '@testing-library/jest-dom/vitest';

import { render, screen } from '@testing-library/svelte';
import { expect, test } from 'vitest';

import StatusIcon from './StatusIcon.svelte';

test('Expect starting styling', async () => {
  const status = 'STARTING';
  render(StatusIcon, { status });
  const icon = screen.getByRole('status');
  expect(icon).toBeInTheDocument();
  expect(icon).toHaveAttribute('title', status);

  expect(icon).toHaveClass('bg-[var(--pd-status-starting)]');
  expect(icon).toHaveClass('text-[var(--pd-status-contrast)]');
});

test('Expect running styling', async () => {
  const status = 'RUNNING';
  render(StatusIcon, { status });
  const icon = screen.getByRole('status');
  expect(icon).toBeInTheDocument();
  expect(icon).toHaveAttribute('title', status);

  expect(icon).toHaveClass('bg-[var(--pd-status-running)]');
  expect(icon).toHaveClass('text-[var(--pd-status-contrast)]');
});

test('Expect degraded styling', async () => {
  const status = 'DEGRADED';
  render(StatusIcon, { status });
  const icon = screen.getByRole('status');
  expect(icon).toBeInTheDocument();
  expect(icon).toHaveAttribute('title', status);

  expect(icon).toHaveClass('bg-[var(--pd-status-degraded)]');
  expect(icon).toHaveClass('text-[var(--pd-status-contrast)]');
});

test('Expect deleting styling', async () => {
  const status = 'DELETING';
  render(StatusIcon, { status });
  const icon = screen.getByRole('status');
  expect(icon).toBeInTheDocument();
  expect(icon).toHaveAttribute('title', status);
  expect(icon).not.toHaveAttribute('border');

  const spinner = screen.getByRole('img');
  expect(spinner).toBeInTheDocument();
  expect(spinner).toHaveAttribute('width', '1.4em');
});

test('Expect updating styling', async () => {
  const status = 'UPDATING';
  render(StatusIcon, { status });
  const icon = screen.getByRole('status');
  expect(icon).toBeInTheDocument();
  expect(icon).toHaveAttribute('title', status);
  expect(icon).not.toHaveAttribute('border');

  const spinner = screen.getByRole('img');
  expect(spinner).toBeInTheDocument();
  expect(spinner).toHaveAttribute('width', '1.4em');
});
