From 15e20fed02eac9c4346f22ad46641cc463d05c6e Mon Sep 17 00:00:00 2001 From: uzulla Date: Sat, 20 Mar 2021 14:19:54 +0900 Subject: [PATCH] Fix post error text. add test. #244 #249 --- app/twig_templates/admin/entries/form.twig | 16 +-- app/twig_templates/admin/entries/form_sp.twig | 16 +-- .../admin_entry_create_delete.test.ts | 131 ++++++++++++++++++ 3 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 e2e_test/serial_execute_tests/admin_entry_create_delete.test.ts diff --git a/app/twig_templates/admin/entries/form.twig b/app/twig_templates/admin/entries/form.twig index 14f00924..13c7321b 100644 --- a/app/twig_templates/admin/entries/form.twig +++ b/app/twig_templates/admin/entries/form.twig @@ -4,7 +4,7 @@ {{ _('Title') }} {{ input(req, 'entry[title]', 'text') }} - {% if error.entry.title %}

{{ error.entry.title }}

{% endif %} + {% if errors.entry.title %}

{{ errors.entry.title }}

{% endif %} @@ -13,13 +13,13 @@

{{ _('Body') }}

{{ input(req, 'entry[body]', 'textarea', {'id' : 'sys-entry-body'}) }} - {% if error.entry.body %}

{{ error.entry.body }}

{% endif %} + {% if errors.entry.body %}

{{ errors.entry.body }}

{% endif %}

{{ _('Edit a postscript') }}▼{{ _('Click to open/close') }}

{{ input(req, 'entry[extend]', 'textarea', {'id' : 'sys-entry-extend'}) }} - {% if error.entry.extend %}

{{ error.entry.extend }}

{% endif %} + {% if errors.entry.extend %}

{{ errors.entry.extend }}

{% endif %}

{{ _('Entry settings') }}▼{{ _('Click to open/close') }}

@@ -52,21 +52,21 @@ {{ input(req, 'entry[posted_at]', 'text', {'class' : 'date-time-picker'}) }} {{ _('Date and time of submission will be set when it is not input') }}
- {% if error.entry.posted_at %}

{{ error.entry.posted_at }}

{% endif %} + {% if errors.entry.posted_at %}

{{ errors.entry.posted_at }}

{% endif %} {{ _('Post type') }} {{ input(req, 'entry[open_status]', 'radio', {'options' : open_status_list, 'default' : open_status_open}) }} - {% if error.entry.open_status %}

{{ error.entry.open_status }}

{% endif %} + {% if errors.entry.open_status %}

{{ errors.entry.open_status }}

{% endif %} {{ _('Set Password') }} {{ input(req, 'entry[password]', 'text') }} - {% if error.entry.password %}

{{ error.entry.password }}

{% endif %} + {% if errors.entry.password %}

{{ errors.entry.password }}

{% endif %}

{{ _('They are authenticated with a password of the entire If empty') }}
{{ _('Passwords in the whole place') }}
@@ -82,14 +82,14 @@ {{ _('New paragraph') }} {{ input(req, 'entry[auto_linefeed]', 'radio', {'options' : auto_line_feed_list, 'default' : auto_line_feed_use}) }} - {% if error.entry.auto_linefeed %}

{{ error.entry.auto_linefeed }}

{% endif %} + {% if errors.entry.auto_linefeed %}

{{ errors.entry.auto_linefeed }}

{% endif %} {{ _('Accept comments') }} {{ input(req, 'entry[comment_accepted]', 'radio', {'options' : comment_accepted_list, 'default' : comment_accepted_accepted}) }} - {% if error.entry.comment_accepted %}

{{ error.entry.comment_accepted }}

{% endif %} + {% if errors.entry.comment_accepted %}

{{ errors.entry.comment_accepted }}

{% endif %} diff --git a/app/twig_templates/admin/entries/form_sp.twig b/app/twig_templates/admin/entries/form_sp.twig index a3020704..a8cd26a6 100644 --- a/app/twig_templates/admin/entries/form_sp.twig +++ b/app/twig_templates/admin/entries/form_sp.twig @@ -80,7 +80,7 @@
{{ input(req, 'entry[title]', 'text', {'placeholder' : _('Article Title')}) }} - {% if error.entry.title %}

{{ error.entry.title }}

{% endif %} + {% if errors.entry.title %}

{{ errors.entry.title }}

{% endif %}
@@ -94,12 +94,12 @@
{{ input(req, 'entry[body]', 'textarea', {'id' : 'sys-entry-body','placeholder' : _('Body')}) }}
- {% if error.entry.body %}

{{ error.entry.body }}

{% endif %} + {% if errors.entry.body %}

{{ errors.entry.body }}

{% endif %}
@@ -110,7 +110,7 @@
{{ input(req, 'entry[open_status]', 'radio', {'options' : open_status_list, 'default' : open_status_open, 'class' : 'radio_vertical_input'}) }} - {% if error.entry.open_status %}

{{ error.entry.open_status }}

{% endif %} + {% if errors.entry.open_status %}

{{ errors.entry.open_status }}

{% endif %}

{{ _('Set Password') }}

@@ -119,7 +119,7 @@ {{ _('They are authenticated with a password of the entire If empty') }}
{{ _('Passwords in the whole place') }}

- {% if error.entry.password %}

{{ error.entry.password }}

{% endif %} + {% if errors.entry.password %}

{{ errors.entry.password }}

{% endif %}
@@ -156,7 +156,7 @@ {{ input(req, 'entry[posted_at]', 'hidden') }} - {% if error.entry.posted_at %}

{{ error.entry.posted_at }}

{% endif %} + {% if errors.entry.posted_at %}

{{ errors.entry.posted_at }}

{% endif %}
@@ -165,7 +165,7 @@
{{ input(req, 'entry[comment_accepted]', 'radio', {'options': comment_accepted_list, 'default': comment_accepted_accepted, 'class' : 'common_input_radio'}) }}
- {% if error.entry.comment_accepted %}

{{ error.entry.comment_accepted }}

{% endif %} + {% if errors.entry.comment_accepted %}

{{ errors.entry.comment_accepted }}

{% endif %}
@@ -174,7 +174,7 @@
{{ input(req, 'entry[auto_linefeed]', 'radio', {'options' : auto_line_feed_list, 'default' : auto_line_feed_use}) }}
- {% if error.entry.auto_linefeed %}

{{ error.entry.auto_linefeed }}

{% endif %} + {% if errors.entry.auto_linefeed %}

{{ errors.entry.auto_linefeed }}

{% endif %}
diff --git a/e2e_test/serial_execute_tests/admin_entry_create_delete.test.ts b/e2e_test/serial_execute_tests/admin_entry_create_delete.test.ts new file mode 100644 index 00000000..414d5ed7 --- /dev/null +++ b/e2e_test/serial_execute_tests/admin_entry_create_delete.test.ts @@ -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(); + }); +});