// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import * as sinon from 'sinon';
import type { BrowserWindow } from 'electron';

import { toggleMaximizedBrowserWindow } from '../../util/toggleMaximizedBrowserWindow.std.ts';

describe('toggleMaximizedBrowserWindow', () => {
  const createFakeWindow = () => ({
    isMaximized: sinon.stub(),
    unmaximize: sinon.spy(),
    maximize: sinon.spy(),
  });

  it('maximizes an unmaximized window', () => {
    const browserWindow = createFakeWindow();
    browserWindow.isMaximized.returns(false);

    // oxlint-disable-next-line typescript/no-explicit-any
    toggleMaximizedBrowserWindow(browserWindow as any as BrowserWindow);

    sinon.assert.calledOnce(browserWindow.maximize);
    sinon.assert.notCalled(browserWindow.unmaximize);
  });

  it('unmaximizes a maximized window', () => {
    const browserWindow = createFakeWindow();
    browserWindow.isMaximized.returns(true);

    // oxlint-disable-next-line typescript/no-explicit-any
    toggleMaximizedBrowserWindow(browserWindow as any as BrowserWindow);

    sinon.assert.notCalled(browserWindow.maximize);
    sinon.assert.calledOnce(browserWindow.unmaximize);
  });
});
