/* eslint-disable @stylistic/js/array-element-newline */
import { isAnimatedGif, isAnimatedWebp } from './profile-avatar-image.service';

describe('profile-avatar image animation detection', () => {
  it('detects animated gifs with multiple frames', () => {
    const animatedGif = new Uint8Array([
      0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
      0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
      0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00,
      0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00,
      0x3B
    ]).buffer;

    expect(isAnimatedGif(animatedGif)).toBe(true);
  });

  it('does not mark single-frame gifs as animated', () => {
    const staticGif = new Uint8Array([
      0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
      0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
      0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00,
      0x3B
    ]).buffer;

    expect(isAnimatedGif(staticGif)).toBe(false);
  });

  it('detects animated webp files from the VP8X animation flag', () => {
    const animatedWebp = new Uint8Array([
      0x52, 0x49, 0x46, 0x46, 0x16, 0x00, 0x00, 0x00,
      0x57, 0x45, 0x42, 0x50,
      0x56, 0x50, 0x38, 0x58, 0x0A, 0x00, 0x00, 0x00,
      0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    ]).buffer;

    expect(isAnimatedWebp(animatedWebp)).toBe(true);
  });

  it('does not mark static webp files as animated', () => {
    const staticWebp = new Uint8Array([
      0x52, 0x49, 0x46, 0x46, 0x16, 0x00, 0x00, 0x00,
      0x57, 0x45, 0x42, 0x50,
      0x56, 0x50, 0x38, 0x58, 0x0A, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    ]).buffer;

    expect(isAnimatedWebp(staticWebp)).toBe(false);
  });
});
