Skip to content

Commit

Permalink
Merge pull request #1108 from nanasess/fix-holiday
Browse files Browse the repository at this point in the history
定休日を未入力で登録した場合のシステムエラーを修正
  • Loading branch information
nanasess authored Dec 26, 2024
2 parents 03fa814 + 4a1a061 commit 1a66910
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
8 changes: 6 additions & 2 deletions data/class/pages/admin/basis/LC_Page_Admin_Basis_Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function action()
// 編集処理
case 'edit':
$this->arrErr = $this->lfCheckError($objFormParam, $objHoliday);
if (!SC_Utils_Ex::isBlank($this->arrErr['holiday_id'])) {
if (!SC_Utils_Ex::isBlank($this->arrErr['holiday_id'] ?? '')) {
trigger_error('', E_USER_ERROR);

return;
Expand Down Expand Up @@ -201,7 +201,11 @@ public function lfCheckError(&$objFormParam, SC_Helper_Holiday_Ex &$objHoliday)
if ($arrForm['month'] == 2 && $arrForm['day'] == 29) {
$valid_date = true;
} else {
$valid_date = checkdate($arrForm['month'], $arrForm['day'], date('Y'));
if (SC_Utils_Ex::isBlank($arrForm['month']) || SC_Utils_Ex::isBlank($arrForm['day'])) {
$valid_date = false;
} else {
$valid_date = checkdate($arrForm['month'], $arrForm['day'], date('Y'));
}
}
if (!$valid_date) {
$arrErr['date'] = '※ 妥当な日付ではありません。<br />';
Expand Down
62 changes: 62 additions & 0 deletions e2e-tests/test/admin/basis/holiday.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { test, expect } from '../../../fixtures/admin_login.fixture';
import { ADMIN_DIR } from '../../../config/default.config';
import { faker } from '@faker-js/faker/locale/ja';

const url = `/${ ADMIN_DIR }/basis/holiday.php`;
test.describe('定休日管理画面のテストをします', () => {

test('定休日管理画面のテストをします', async ( { adminLoginPage, page }) => {
await page.goto(url);
await expect(page.locator('h1')).toContainText(//);
});

test('エラーハンドリングのテストをします', async ( { adminLoginPage, page }) => {
await page.goto(url);
expect(page.getByRole('row', { name: 'タイトル' }).getByRole('textbox')).toBeEmpty();
await expect(page.getByRole('row', { name: '日付' }).locator('select[name=month]')).toHaveValue('');
await expect(page.getByRole('row', { name: '日付' }).locator('select[name=day]')).toHaveValue('');
await page.getByRole('link', { name: 'この内容で登録する' }).click();
await expect(page.getByText('タイトルが入力されていません。')).toBeVisible();
await expect(page.getByText('妥当な日付ではありません。')).toBeVisible();
});

test('定休日の登録をします', async ( { adminLoginPage, page }) => {
page.on('dialog', dialog => dialog.accept());
await page.goto(url);

const title = faker.lorem.sentence();
await test.step('登録処理をします', async () => {
await page.getByRole('row', { name: 'タイトル' }).getByRole('textbox').fill(title);
await page.getByRole('row', { name: '日付' }).locator('select[name=month]').selectOption({ value: String(faker.number.int({ min: 1, max: 12 })) });
await page.getByRole('row', { name: '日付' }).locator('select[name=day]').selectOption({ value: String(faker.number.int({ min: 1, max: 28 })) });

await page.getByRole('link', { name: 'この内容で登録する' }).click();
await expect(page.locator('table.list')).toContainText(title);
});
await test.step('登録処理をします', async () => {
await page.getByRole('row', { name: 'タイトル' }).getByRole('textbox').fill(title);
await page.getByRole('row', { name: '日付' }).locator('select[name=month]').selectOption({ value: String(faker.number.int({ min: 1, max: 12 })) });
await page.getByRole('row', { name: '日付' }).locator('select[name=day]').selectOption({ value: String(faker.number.int({ min: 1, max: 28 })) });

await page.getByRole('link', { name: 'この内容で登録する' }).click();
await expect(page.locator('table.list')).toContainText(title);
});

await test.step('編集をします', async () => {
await page.goto(url);
await page.getByRole('row', { name: title }).getByRole('link', { name: '編集' }).click();
await page.getByRole('row', { name: 'タイトル' }).getByRole('textbox').fill(`${title}を編集`);
await page.getByRole('row', { name: '日付' }).locator('select[name=month]').selectOption({ value: String(faker.number.int({ min: 1, max: 12 })) });
await page.getByRole('row', { name: '日付' }).locator('select[name=day]').selectOption({ value: String(faker.number.int({ min: 1, max: 28 })) });

await page.getByRole('link', { name: 'この内容で登録する' }).click();
await expect(page.locator('table.list')).toContainText(`${title}を編集`);
});

await test.step('削除をします', async () => {
await page.goto(url);
await page.getByRole('row', { name: `${title}を編集` }).getByRole('link', { name: '削除' }).click();
await expect(page.locator('table.list')).not.toContainText(`${title}を編集`);
});
});
});

0 comments on commit 1a66910

Please sign in to comment.