Newer
Older
TelosDB / tests / e2e / specs / settings-autostart.spec.js
/**
 * 設定パネル「ログイン時自動起動」の E2E テスト(計画 auto_start に基づく)。
 * テストファースト: 表示・トグル・保存・永続化を検証する。
 *
 * 実行: npm run test:e2e
 * このスペックのみ: npx wdio run wdio.conf.js --spec tests/e2e/specs/settings-autostart.spec.js
 */

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

const openSettingsPanel = 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');
};

describe('設定パネル ログイン時自動起動', () => {
  before(async function () {
    this.timeout(120000);
    await waitForAppReady(browser);
  });

  it('設定パネルに「ログイン時自動起動」の枠とチェックボックスが表示される', async () => {
    await openSettingsPanel();
    const legends = await $$('legend');
    const autostartLegend = await Promise.all(Array.from(legends).map(async (el) => ({ el, text: await el.getText() }))).then((arr) => arr.find((x) => x.text === 'ログイン時自動起動'));
    expect(autostartLegend).toBeDefined();
    await expect(autostartLegend.el).toBeDisplayed();
    const checkbox = await $('#setting-run-on-login');
    await expect(checkbox).toBeDisplayed();
  });

  it('ログイン時自動起動をオンにして保存すると「保存しました」が表示される', async () => {
    await openSettingsPanel();
    const checkbox = await $('#setting-run-on-login');
    const saveBtn = await $('#settings-save-btn');
    await expect(checkbox).toBeDisplayed();
    await expect(saveBtn).toBeDisplayed();
    if (!(await checkbox.isSelected())) await checkbox.click();
    await saveBtn.click();
    const feedback = await $('#settings-feedback');
    await expect(feedback).toHaveText('保存しました');
  });

  it('オンで保存後、いったん検索パネルに切り替えてから設定を再表示するとトグルがオンのままである', async () => {
    await openSettingsPanel();
    const checkbox = await $('#setting-run-on-login');
    if (!(await checkbox.isSelected())) await checkbox.click();
    await (await $('#settings-save-btn')).click();
    await browser.pause(500);
    await (await $('button[data-panel="search"]')).click();
    await browser.pause(300);
    await openSettingsPanel();
    const checkboxAgain = await $('#setting-run-on-login');
    await expect(checkboxAgain).toBeDisplayed();
    await expect(checkboxAgain).toBeSelected();
  });

  it('オフで保存後、いったん検索パネルに切り替えてから設定を再表示するとトグルがオフのままである', async () => {
    await openSettingsPanel();
    const checkbox = await $('#setting-run-on-login');
    if (await checkbox.isSelected()) await checkbox.click();
    await (await $('#settings-save-btn')).click();
    await browser.pause(500);
    await (await $('button[data-panel="search"]')).click();
    await browser.pause(300);
    await openSettingsPanel();
    const checkboxAgain = await $('#setting-run-on-login');
    await expect(checkboxAgain).toBeDisplayed();
    await expect(checkboxAgain).not.toBeSelected();
  });
});