Skip to content

Commit

Permalink
Fix post error text. add test. fc2blog#244 fc2blog#249
Browse files Browse the repository at this point in the history
  • Loading branch information
uzulla committed Mar 20, 2021
1 parent 9782de9 commit 15e20fe
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 16 deletions.
16 changes: 8 additions & 8 deletions app/twig_templates/admin/entries/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<th>{{ _('Title') }}</th>
<td>
{{ input(req, 'entry[title]', 'text') }}
{% if error.entry.title %}<p class="error">{{ error.entry.title }}</p>{% endif %}
{% if errors.entry.title %}<p class="error">{{ errors.entry.title }}</p>{% endif %}
</td>
</tr>
</tbody>
Expand All @@ -13,13 +13,13 @@
<h3>{{ _('Body') }}</h3>
<div>
{{ input(req, 'entry[body]', 'textarea', {'id' : 'sys-entry-body'}) }}
{% if error.entry.body %}<p class="error">{{ error.entry.body }}</p>{% endif %}
{% if errors.entry.body %}<p class="error">{{ errors.entry.body }}</p>{% endif %}
</div>

<h3 class="accordion_head" id="sys-accordion-extend">{{ _('Edit a postscript') }}<span>▼{{ _('Click to open/close') }}</span></h3>
<div {{ ifCookie(req, 'js_entry_hide_extend', 'style="visibility: hidden;"') }}>
{{ input(req, 'entry[extend]', 'textarea', {'id' : 'sys-entry-extend'}) }}
{% if error.entry.extend %}<p class="error">{{ error.entry.extend }}</p>{% endif %}
{% if errors.entry.extend %}<p class="error">{{ errors.entry.extend }}</p>{% endif %}
</div>

<h3 class="accordion_head" id="sys-accordion-setting">{{ _('Entry settings') }}<span>▼{{ _('Click to open/close') }}</span></h3>
Expand Down Expand Up @@ -52,21 +52,21 @@
<td>
{{ input(req, 'entry[posted_at]', 'text', {'class' : 'date-time-picker'}) }}
{{ _('Date and time of submission will be set when it is not input') }}<br/>
{% if error.entry.posted_at %}<p class="error">{{ error.entry.posted_at }}</p>{% endif %}
{% if errors.entry.posted_at %}<p class="error">{{ errors.entry.posted_at }}</p>{% endif %}
</td>
</tr>
<tr>
<th>{{ _('Post type') }}</th>
<td>
{{ input(req, 'entry[open_status]', 'radio', {'options' : open_status_list, 'default' : open_status_open}) }}
{% if error.entry.open_status %}<p class="error">{{ error.entry.open_status }}</p>{% endif %}
{% if errors.entry.open_status %}<p class="error">{{ errors.entry.open_status }}</p>{% endif %}
</td>
</tr>
<tr>
<th class="sys-entry-password">{{ _('Set Password') }}</th>
<td class="sys-entry-password">
{{ input(req, 'entry[password]', 'text') }}
{% if error.entry.password %}<p class="error">{{ error.entry.password }}</p>{% endif %}
{% if errors.entry.password %}<p class="error">{{ errors.entry.password }}</p>{% endif %}
<p>
{{ _('They are authenticated with a password of the entire If empty') }}<br/>
<a href="{{ url(req, 'BlogSettings', 'entry_edit') }}" target="_blank">{{ _('Passwords in the whole place') }}</a><br/>
Expand All @@ -82,14 +82,14 @@
<th>{{ _('New paragraph') }}</th>
<td>
{{ input(req, 'entry[auto_linefeed]', 'radio', {'options' : auto_line_feed_list, 'default' : auto_line_feed_use}) }}
{% if error.entry.auto_linefeed %}<p class="error">{{ error.entry.auto_linefeed }}</p>{% endif %}
{% if errors.entry.auto_linefeed %}<p class="error">{{ errors.entry.auto_linefeed }}</p>{% endif %}
</td>
</tr>
<tr>
<th>{{ _('Accept comments') }}</th>
<td>
{{ input(req, 'entry[comment_accepted]', 'radio', {'options' : comment_accepted_list, 'default' : comment_accepted_accepted}) }}
{% if error.entry.comment_accepted %}<p class="error">{{ error.entry.comment_accepted }}</p>{% endif %}
{% if errors.entry.comment_accepted %}<p class="error">{{ errors.entry.comment_accepted }}</p>{% endif %}
</td>
</tr>
</tbody>
Expand Down
16 changes: 8 additions & 8 deletions app/twig_templates/admin/entries/form_sp.twig
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<div class="form_contents common_input_text">
<!--{{ _('Title') }}-->
{{ input(req, 'entry[title]', 'text', {'placeholder' : _('Article Title')}) }}
{% if error.entry.title %}<p class="error">{{ error.entry.title }}</p>{% endif %}
{% if errors.entry.title %}<p class="error">{{ errors.entry.title }}</p>{% endif %}
</div>
</div>

Expand All @@ -94,12 +94,12 @@
</ul>
<div class="content_wrap" style="display: block;">
<div class="edit_area_box">{{ input(req, 'entry[body]', 'textarea', {'id' : 'sys-entry-body','placeholder' : _('Body')}) }}</div>
{% if error.entry.body %}<p class="error">{{ error.entry.body }}</p>{% endif %}
{% if errors.entry.body %}<p class="error">{{ errors.entry.body }}</p>{% endif %}
</div>

<div class="content_wrap nondisplay" style="display: none; ">
<div class="edit_area_box">{{ input(req, 'entry[extend]', 'textarea', {'id' : 'sys-entry-extend','placeholder' : _('Edit a postscript')}) }}</div>
{% if error.entry.extend %}<p class="error">{{ error.entry.extend }}</p>{% endif %}
{% if errors.entry.extend %}<p class="error">{{ errors.entry.extend }}</p>{% endif %}
</div>

<section>
Expand All @@ -110,7 +110,7 @@
<div class="form_contents">
<div class="radio_vertical_box">
{{ input(req, 'entry[open_status]', 'radio', {'options' : open_status_list, 'default' : open_status_open, 'class' : 'radio_vertical_input'}) }}
{% if error.entry.open_status %}<p class="error">{{ error.entry.open_status }}</p>{% endif %}
{% if errors.entry.open_status %}<p class="error">{{ errors.entry.open_status }}</p>{% endif %}
</div>
<div class="sys-entry-password">
<h4>{{ _('Set Password') }}</h4>
Expand All @@ -119,7 +119,7 @@
{{ _('They are authenticated with a password of the entire If empty') }}<br/>
<a href="{{ url(req, 'BlogSettings', 'entry_edit') }}" target="_blank">{{ _('Passwords in the whole place') }}</a><br/>
</p>
{% if error.entry.password %}<p class="error">{{ error.entry.password }}</p>{% endif %}
{% if errors.entry.password %}<p class="error">{{ errors.entry.password }}</p>{% endif %}
</div>
</div><!--/form_contents-->
</div><!--/form_area-->
Expand Down Expand Up @@ -156,7 +156,7 @@
</table>
</div>
{{ input(req, 'entry[posted_at]', 'hidden') }}
{% if error.entry.posted_at %}<p class="error">{{ error.entry.posted_at }}</p>{% endif %}
{% if errors.entry.posted_at %}<p class="error">{{ errors.entry.posted_at }}</p>{% endif %}
</div><!--/form_contents-->
</div><!--/form_area-->
<div class="form_area">
Expand All @@ -165,7 +165,7 @@
<div class="radio_horizontal_box">
{{ input(req, 'entry[comment_accepted]', 'radio', {'options': comment_accepted_list, 'default': comment_accepted_accepted, 'class' : 'common_input_radio'}) }}
</div>
{% if error.entry.comment_accepted %}<p class="error">{{ error.entry.comment_accepted }}</p>{% endif %}
{% if errors.entry.comment_accepted %}<p class="error">{{ errors.entry.comment_accepted }}</p>{% endif %}
</div><!--/form_contents-->
</div><!--/formarea-->
<div class="form_area">
Expand All @@ -174,7 +174,7 @@
<div class="radio_horizontal_box">
{{ input(req, 'entry[auto_linefeed]', 'radio', {'options' : auto_line_feed_list, 'default' : auto_line_feed_use}) }}
</div>
{% if error.entry.auto_linefeed %}<p class="error">{{ error.entry.auto_linefeed }}</p>{% endif %}
{% if errors.entry.auto_linefeed %}<p class="error">{{ errors.entry.auto_linefeed }}</p>{% endif %}
</div><!--/form_contents-->
</div><!--/formarea-->
</div><!--/accordion_inner-->
Expand Down
131 changes: 131 additions & 0 deletions e2e_test/serial_execute_tests/admin_entry_create_delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";
import { Helper } from "../tests/helper";

describe("admin create entry", () => {
let c: Helper;

const admin_id = "testadmin";
const admin_pass = "testadmin";

beforeAll(async () => {
c = new Helper();
await c.init();
});

const start_url = "/admin/";

it("login page", async () => {
let response;
[response] = await Promise.all([
c.waitLoad(),
c.page.goto(c.getBaseUrl() + start_url),
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
await c.page.$eval(
"#id_form input[name='user[login_id]']",
(elm: HTMLInputElement) => (elm.value = "")
);
await c.page.type("#id_form input[name='user[login_id]']", admin_id);
await c.page.$eval(
"#id_form input[name='user[password]']",
(elm: HTMLInputElement) => (elm.value = "")
);
await c.page.type("#id_form input[name='user[password]']", admin_pass);

[response] = await Promise.all([
c.waitLoad(),
await c.page.click("#id_form input[type=submit]"),
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(response.url()).toEqual(c.getBaseUrl() + "/admin/common/notice");
});

it("open 新しく記事を書く", async () => {
let [response] = await Promise.all([
c.waitLoad(),
await c.page.click(
"#left-nav > div:nth-child(1) > ul > li:nth-child(3) > a[href='/admin/entries/create']"
),
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(response.url()).toEqual(
c.getBaseUrl() + "/admin/entries/create"
);
});

it("post entry and fail", async () => {
let [response] = await Promise.all([
c.waitLoad(),
await c.page.click(
"#sys-entry-form-submit"
),
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(response.url()).toEqual(c.getBaseUrl() + "/admin/entries/create");
});

const find_text = async(c, str, selector)=>{
const whole_text = await c.page.$eval(selector, (elm) => elm.textContent);
const match = whole_text.match(new RegExp(str));
return !!match;
}

it("check blank title post error text", async () => {
let [response] = await Promise.all([
c.waitLoad(),
await c.page.click(
"#sys-entry-form-submit"
),
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(response.url()).toEqual(c.getBaseUrl() + "/admin/entries/create");
expect(await find_text(c, "必ず入力してください","#sys-entry-form > table > tbody > tr > td > p")).toEqual(true);
});


it("post and success", async () => {
await c.page.type(
'#sys-entry-form > table > tbody > tr > td > input[type=text]',
"blog post title"
);

let [response] = await Promise.all([
c.waitLoad(),
c.page.click("#sys-entry-form-submit")
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(await find_text(c, "記事を作成しました","#main-contents > div.flash-message.flash-message-info > p")).toEqual(true);
});

it("delete test", async () => {
c.page.on('dialog', async dialog => {
await dialog.accept();
});

let [response] = await Promise.all([
c.waitLoad(),
c.page.click("#sys-list-form > table > tbody > tr:nth-child(1) > td:nth-child(8) > a")
]);

expect(response.status()).toEqual(200);
expect(await c.isNotAnyNoticeOrWarningsFinishWithEndHtmlTag()).toBeTruthy();
expect(await find_text(c, "記事を削除しました","#main-contents > div.flash-message.flash-message-info > p")).toEqual(true);
});

//
afterAll(async () => {
await c.browser.close();
});
});

0 comments on commit 15e20fe

Please sign in to comment.