/**
 * 各パネル（検索・文書管理・設定）に遷移したときに表示が切り替わることを検証する。
 */

import { waitForAppReady } from '../helpers/wait-for-app.js';

describe('パネル表示', () => {
  before(async function () {
    this.timeout(120000);
    await waitForAppReady(browser);
  });

  it('検索パネルが表示される', async () => {
    const navSearch = await $('button[data-panel="search"]');
    await navSearch.click();
    const panel = await $('#panel-search');
    await panel.waitForDisplayed({ timeout: 5000 });
    await expect(panel).not.toHaveElementClass('hidden');
    const query = await $('#query');
    const searchBtn = await $('.search-btn');
    await expect(query).toBeDisplayed();
    await expect(searchBtn).toBeDisplayed();
  });

  it('文書管理パネルが表示される', async () => {
    const navDocs = await $('button[data-panel="docs"]');
    await navDocs.click();
    const panel = await $('#panel-docs');
    await panel.waitForDisplayed({ timeout: 5000 });
    await expect(panel).not.toHaveElementClass('hidden');
    const addBtn = await $('#docs-add-btn');
    await addBtn.waitForDisplayed({ timeout: 3000 });
    await expect(addBtn).toBeDisplayed();
    const refreshBtn = await $('#docs-refresh-btn');
    await expect(refreshBtn).toBeDisplayed();
    const listArea = await $('#docs-list');
    await expect(listArea).toBeDisplayed();
  });

  it('設定パネルが表示される', async () => {
    const navSettings = await $('button[data-panel="settings"]');
    await navSettings.click();
    const panel = await $('#panel-settings');
    await panel.waitForDisplayed({ timeout: 5000 });
    await expect(panel).not.toHaveElementClass('hidden');
    const form = await $('.settings-form');
    await expect(form).toBeDisplayed();
    const saveBtn = await $('#settings-save-btn');
    await expect(saveBtn).toBeDisplayed();
  });
});
