alchemy_cms 7.0.0.pre.a → 7.0.0.pre.c
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/brakeman-analysis.yml +2 -2
- data/.github/workflows/lint.yml +37 -0
- data/.github/workflows/{ci.yml → test.yml} +8 -8
- data/.gitignore +0 -5
- data/.hound.yml +2 -3
- data/.rubocop.yml +4 -350
- data/.standard.yml +3 -0
- data/CHANGELOG.md +33 -0
- data/Gemfile +3 -2
- data/README.md +10 -12
- data/Rakefile +0 -19
- data/alchemy_cms.gemspec +4 -2
- data/app/assets/config/alchemy_manifest.js +1 -0
- data/app/assets/javascripts/alchemy/admin.js +0 -2
- data/app/assets/javascripts/alchemy/alchemy.dirty.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +5 -12
- data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +6 -1
- data/app/assets/stylesheets/alchemy/base.scss +2 -2
- data/app/components/alchemy/ingredients/audio_view.rb +37 -0
- data/app/components/alchemy/ingredients/base_view.rb +38 -0
- data/app/components/alchemy/ingredients/boolean_view.rb +13 -0
- data/app/components/alchemy/ingredients/datetime_view.rb +22 -0
- data/app/components/alchemy/ingredients/file_view.rb +40 -0
- data/app/components/alchemy/ingredients/headline_view.rb +20 -0
- data/app/components/alchemy/ingredients/html_view.rb +9 -0
- data/app/components/alchemy/ingredients/link_view.rb +25 -0
- data/app/components/alchemy/ingredients/node_view.rb +11 -0
- data/app/components/alchemy/ingredients/page_view.rb +15 -0
- data/app/components/alchemy/ingredients/picture_view.rb +108 -0
- data/app/components/alchemy/ingredients/richtext_view.rb +22 -0
- data/app/components/alchemy/ingredients/select_view.rb +6 -0
- data/app/components/alchemy/ingredients/text_view.rb +41 -0
- data/app/components/alchemy/ingredients/video_view.rb +39 -0
- data/app/controllers/alchemy/admin/attachments_controller.rb +3 -3
- data/app/controllers/alchemy/admin/base_controller.rb +7 -7
- data/app/controllers/alchemy/admin/clipboard_controller.rb +2 -2
- data/app/controllers/alchemy/admin/elements_controller.rb +26 -11
- data/app/controllers/alchemy/admin/languages_controller.rb +1 -1
- data/app/controllers/alchemy/admin/nodes_controller.rb +2 -2
- data/app/controllers/alchemy/admin/pages_controller.rb +10 -10
- data/app/controllers/alchemy/admin/pictures_controller.rb +14 -14
- data/app/controllers/alchemy/admin/resources_controller.rb +27 -28
- data/app/controllers/alchemy/admin/styleguide_controller.rb +1 -0
- data/app/controllers/alchemy/admin/tags_controller.rb +11 -11
- data/app/controllers/alchemy/api/base_controller.rb +2 -2
- data/app/controllers/alchemy/api/elements_controller.rb +11 -11
- data/app/controllers/alchemy/api/ingredients_controller.rb +1 -1
- data/app/controllers/alchemy/api/nodes_controller.rb +1 -1
- data/app/controllers/alchemy/api/pages_controller.rb +11 -11
- data/app/controllers/alchemy/attachments_controller.rb +3 -3
- data/app/controllers/alchemy/base_controller.rb +1 -8
- data/app/controllers/alchemy/messages_controller.rb +9 -9
- data/app/controllers/alchemy/pages_controller.rb +8 -19
- data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +1 -0
- data/app/controllers/concerns/alchemy/admin/uploader_responses.rb +5 -7
- data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +5 -5
- data/app/decorators/alchemy/element_editor.rb +4 -4
- data/app/decorators/alchemy/ingredient_editor.rb +6 -6
- data/app/helpers/alchemy/admin/attachments_helper.rb +1 -1
- data/app/helpers/alchemy/admin/base_helper.rb +21 -22
- data/app/helpers/alchemy/admin/elements_helper.rb +1 -1
- data/app/helpers/alchemy/admin/form_helper.rb +1 -1
- data/app/helpers/alchemy/admin/navigation_helper.rb +7 -7
- data/app/helpers/alchemy/admin/pages_helper.rb +2 -2
- data/app/helpers/alchemy/admin/tags_helper.rb +3 -3
- data/app/helpers/alchemy/base_helper.rb +2 -2
- data/app/helpers/alchemy/elements_block_helper.rb +9 -7
- data/app/helpers/alchemy/elements_helper.rb +12 -12
- data/app/helpers/alchemy/pages_helper.rb +11 -11
- data/app/helpers/alchemy/url_helper.rb +1 -1
- data/{package/src → app/javascript/alchemy_admin}/datepicker.js +1 -0
- data/{package/src → app/javascript/alchemy_admin}/node_tree.js +2 -2
- data/{package/src → app/javascript/alchemy_admin}/page_publication_fields.js +1 -1
- data/{package/src → app/javascript/alchemy_admin}/page_sorter.js +1 -1
- data/{package/src → app/javascript/alchemy_admin}/picture_editors.js +2 -2
- data/{package/src → app/javascript/alchemy_admin}/sitemap.js +4 -4
- data/app/javascript/alchemy_admin/tinymce.js +142 -0
- data/app/javascript/alchemy_admin.js +34 -0
- data/app/mailers/alchemy/messages_mailer.rb +1 -1
- data/app/models/alchemy/attachment.rb +6 -6
- data/app/models/alchemy/base_record.rb +1 -0
- data/app/models/alchemy/eager_loading.rb +6 -6
- data/app/models/alchemy/element/definitions.rb +1 -1
- data/app/models/alchemy/element/element_ingredients.rb +3 -3
- data/app/models/alchemy/element.rb +2 -2
- data/app/models/alchemy/elements_repository.rb +1 -1
- data/app/models/alchemy/image_cropper_settings.rb +2 -2
- data/app/models/alchemy/ingredient.rb +14 -12
- data/app/models/alchemy/ingredient_validator.rb +1 -1
- data/app/models/alchemy/ingredients/datetime.rb +1 -1
- data/app/models/alchemy/ingredients/file.rb +5 -5
- data/app/models/alchemy/ingredients/headline.rb +4 -4
- data/app/models/alchemy/ingredients/picture.rb +27 -9
- data/app/models/alchemy/ingredients/richtext.rb +15 -12
- data/app/models/alchemy/ingredients/text.rb +6 -6
- data/app/models/alchemy/language/code.rb +1 -1
- data/app/models/alchemy/language.rb +4 -4
- data/app/models/alchemy/legacy_page_url.rb +1 -1
- data/app/models/alchemy/node.rb +2 -2
- data/app/models/alchemy/page/page_elements.rb +14 -14
- data/app/models/alchemy/page/page_naming.rb +4 -4
- data/app/models/alchemy/page/page_natures.rb +1 -1
- data/app/models/alchemy/page/page_scopes.rb +5 -5
- data/app/models/alchemy/page.rb +11 -11
- data/app/models/alchemy/picture/calculations.rb +2 -2
- data/app/models/alchemy/picture/transformations.rb +2 -2
- data/app/models/alchemy/picture/url.rb +4 -4
- data/app/models/alchemy/picture.rb +11 -10
- data/app/models/alchemy/picture_thumb/create.rb +1 -1
- data/app/models/alchemy/picture_thumb.rb +1 -1
- data/app/models/alchemy/picture_variant.rb +2 -3
- data/app/models/alchemy/tag.rb +8 -0
- data/app/models/concerns/alchemy/picture_thumbnails.rb +6 -6
- data/app/serializers/alchemy/base_serializer.rb +1 -1
- data/app/serializers/alchemy/page_tree_serializer.rb +7 -7
- data/app/services/alchemy/duplicate_element.rb +3 -3
- data/app/services/alchemy/tag_validations.rb +1 -1
- data/app/views/alchemy/_menubar.html.erb +1 -1
- data/app/views/alchemy/admin/attachments/_replace_button.html.erb +1 -1
- data/app/views/alchemy/admin/attachments/destroy.js.erb +1 -1
- data/app/views/alchemy/admin/elements/_element.html.erb +3 -0
- data/app/views/alchemy/admin/nodes/index.html.erb +4 -2
- data/app/views/alchemy/admin/pages/_page_layout_filter.html.erb +1 -1
- data/app/views/alchemy/admin/pages/edit.html.erb +3 -7
- data/app/views/alchemy/admin/pages/index.html.erb +1 -1
- data/app/views/alchemy/admin/pages/update.js.erb +12 -6
- data/app/views/alchemy/admin/pictures/_infos.html.erb +1 -1
- data/app/views/alchemy/admin/resources/_filter_bar.html.erb +1 -1
- data/app/views/alchemy/admin/styleguide/index.html.erb +1 -1
- data/app/views/alchemy/admin/uploader/_button.html.erb +1 -1
- data/app/views/alchemy/base/permission_denied.js.erb +1 -1
- data/app/views/alchemy/base/redirect.js.erb +1 -1
- data/app/views/alchemy/ingredients/_audio_view.html.erb +1 -14
- data/app/views/alchemy/ingredients/_boolean_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_datetime_view.html.erb +3 -9
- data/app/views/alchemy/ingredients/_file_view.html.erb +3 -16
- data/app/views/alchemy/ingredients/_headline_view.html.erb +4 -10
- data/app/views/alchemy/ingredients/_html_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_link_view.html.erb +4 -9
- data/app/views/alchemy/ingredients/_node_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_page_view.html.erb +1 -4
- data/app/views/alchemy/ingredients/_picture_view.html.erb +4 -5
- data/app/views/alchemy/ingredients/_richtext_editor.html.erb +11 -2
- data/app/views/alchemy/ingredients/_richtext_view.html.erb +3 -3
- data/app/views/alchemy/ingredients/_select_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_text_view.html.erb +3 -19
- data/app/views/alchemy/ingredients/_video_view.html.erb +3 -18
- data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +1 -0
- data/app/views/alchemy/ingredients/shared/_picture_tools.html.erb +1 -0
- data/app/views/layouts/alchemy/admin.html.erb +9 -15
- data/bin/importmap +4 -0
- data/bin/setup +28 -0
- data/bin/start +17 -0
- data/config/brakeman.ignore +0 -46
- data/config/importmap.rb +8 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/dragonfly.rb +1 -0
- data/config/initializers/mime_types.rb +1 -0
- data/config/initializers/mini_profiler.rb +1 -0
- data/config/initializers/simple_form.rb +3 -2
- data/config/locales/alchemy.en.yml +1 -1
- data/config/routes.rb +21 -20
- data/config/spring.rb +1 -0
- data/db/migrate/20230121212637_alchemy_six_point_one.rb +8 -8
- data/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb +6 -0
- data/lib/alchemy/admin/locale.rb +3 -3
- data/lib/alchemy/admin/preview_url.rb +2 -2
- data/lib/alchemy/auth_accessors.rb +1 -1
- data/lib/alchemy/config.rb +1 -1
- data/lib/alchemy/controller_actions.rb +4 -4
- data/lib/alchemy/deprecation.rb +1 -0
- data/lib/alchemy/dragonfly/processors/thumbnail.rb +1 -1
- data/lib/alchemy/element_definition.rb +2 -2
- data/lib/alchemy/engine.rb +16 -1
- data/lib/alchemy/filetypes.rb +7 -7
- data/lib/alchemy/forms/builder.rb +4 -4
- data/lib/alchemy/i18n.rb +6 -4
- data/lib/alchemy/install/tasks.rb +2 -1
- data/lib/alchemy/name_conversions.rb +1 -1
- data/lib/alchemy/page_layout.rb +1 -1
- data/lib/alchemy/permissions.rb +5 -4
- data/lib/alchemy/resource.rb +10 -10
- data/lib/alchemy/resources_helper.rb +7 -7
- data/lib/alchemy/routing_constraints.rb +2 -2
- data/lib/alchemy/seeder.rb +12 -5
- data/lib/alchemy/shell.rb +2 -1
- data/lib/alchemy/taggable.rb +3 -2
- data/lib/alchemy/tasks/tidy.rb +1 -0
- data/lib/alchemy/test_support/capybara_helpers.rb +1 -1
- data/lib/alchemy/test_support/config_stubbing.rb +1 -0
- data/lib/alchemy/test_support/factories/element_factory.rb +4 -0
- data/lib/alchemy/test_support/factories/page_factory.rb +2 -2
- data/lib/alchemy/test_support/having_crop_action_examples.rb +9 -9
- data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +33 -33
- data/lib/alchemy/test_support/integration_helpers.rb +4 -3
- data/lib/alchemy/test_support/shared_contexts.rb +2 -1
- data/lib/alchemy/test_support/shared_dom_ids_examples.rb +9 -9
- data/lib/alchemy/test_support/shared_ingredient_examples.rb +12 -6
- data/lib/alchemy/test_support/shared_uploader_examples.rb +1 -0
- data/lib/alchemy/tinymce.rb +3 -26
- data/lib/alchemy/upgrader/seven_point_zero.rb +13 -23
- data/lib/alchemy/upgrader.rb +1 -11
- data/lib/alchemy/version.rb +1 -1
- data/lib/alchemy.rb +5 -0
- data/lib/alchemy_cms.rb +3 -1
- data/lib/generators/alchemy/base.rb +3 -2
- data/lib/generators/alchemy/elements/elements_generator.rb +2 -1
- data/lib/generators/alchemy/ingredient/ingredient_generator.rb +1 -0
- data/lib/generators/alchemy/install/files/application.html.erb +2 -2
- data/lib/generators/alchemy/install/install_generator.rb +2 -25
- data/lib/generators/alchemy/module/module_generator.rb +1 -0
- data/lib/generators/alchemy/page_layouts/page_layouts_generator.rb +1 -0
- data/lib/generators/alchemy/site_layouts/site_layouts_generator.rb +1 -0
- data/lib/generators/alchemy/views/views_generator.rb +2 -1
- data/lib/tasks/alchemy/thumbnails.rake +5 -5
- data/lib/tasks/alchemy/tidy.rake +1 -0
- data/lib/tasks/alchemy/upgrade.rake +10 -15
- data/package.json +6 -26
- metadata +80 -31
- data/app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee +0 -93
- data/app/presenters/alchemy/picture_view.rb +0 -88
- data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +0 -10
- data/package/admin.js +0 -32
- data/package/dist/admin.js +0 -16
- data/package/dist/admin.js.map +0 -7
- data/package/src/__tests__/i18n.spec.js +0 -93
- data/package/src/utils/__tests__/ajax.spec.js +0 -168
- data/package/src/utils/__tests__/events.spec.js +0 -38
- /data/{package/src → app/javascript/alchemy_admin}/file_editors.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/i18n.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/image_cropper.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/image_loader.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/ingredient_anchor_link.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/translations.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/utils/ajax.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/utils/events.js +0 -0
@@ -1,93 +0,0 @@
|
|
1
|
-
import translate from "../i18n"
|
2
|
-
|
3
|
-
describe("translate", () => {
|
4
|
-
describe("if Alchemy.locale is not set", () => {
|
5
|
-
it("Throws an error", () => {
|
6
|
-
expect(() => {
|
7
|
-
translate("help")
|
8
|
-
}).toThrow("Alchemy.locale is not set")
|
9
|
-
})
|
10
|
-
})
|
11
|
-
|
12
|
-
describe("if Alchemy.locale is set to a known locale", () => {
|
13
|
-
beforeEach(() => {
|
14
|
-
Alchemy.locale = "en"
|
15
|
-
})
|
16
|
-
|
17
|
-
describe("if translation is present", () => {
|
18
|
-
beforeEach(() => {
|
19
|
-
Alchemy.translations = { en: { help: "Help" } }
|
20
|
-
})
|
21
|
-
|
22
|
-
it("Returns translated string", () => {
|
23
|
-
expect(translate("help")).toEqual("Help")
|
24
|
-
})
|
25
|
-
|
26
|
-
describe("if key includes a period", () => {
|
27
|
-
describe("that is translated", () => {
|
28
|
-
beforeEach(() => {
|
29
|
-
Alchemy.translations = { en: { formats: { date: "Y-m-d" } } }
|
30
|
-
})
|
31
|
-
|
32
|
-
it("splits into group", () => {
|
33
|
-
expect(translate("formats.date")).toEqual("Y-m-d")
|
34
|
-
})
|
35
|
-
})
|
36
|
-
|
37
|
-
describe("that is not translated", () => {
|
38
|
-
it("returns key", () => {
|
39
|
-
expect(translate("formats.lala")).toEqual("formats.lala")
|
40
|
-
})
|
41
|
-
})
|
42
|
-
|
43
|
-
describe("that has unknown group", () => {
|
44
|
-
it("returns key", () => {
|
45
|
-
expect(translate("foo.bar")).toEqual("foo.bar")
|
46
|
-
})
|
47
|
-
})
|
48
|
-
})
|
49
|
-
|
50
|
-
describe("if replacement is given", () => {
|
51
|
-
beforeEach(() => {
|
52
|
-
Alchemy.translations = { en: { allowed_chars: "of %{number} chars" } }
|
53
|
-
})
|
54
|
-
|
55
|
-
it("replaces it", () => {
|
56
|
-
expect(translate("allowed_chars", 5)).toEqual("of 5 chars")
|
57
|
-
})
|
58
|
-
})
|
59
|
-
})
|
60
|
-
|
61
|
-
describe("if translation is not present", () => {
|
62
|
-
it("Returns passed string", () => {
|
63
|
-
expect(translate("foo")).toEqual("foo")
|
64
|
-
})
|
65
|
-
})
|
66
|
-
})
|
67
|
-
|
68
|
-
describe("if Alchemy.locale is set to a unknown locale", () => {
|
69
|
-
beforeEach(() => {
|
70
|
-
Alchemy.locale = "kl"
|
71
|
-
})
|
72
|
-
|
73
|
-
it("Returns passed string and logs a warning", () => {
|
74
|
-
const spy = jest.spyOn(console, "warn").mockImplementation(() => {})
|
75
|
-
expect(translate("help")).toEqual("help")
|
76
|
-
expect(spy.mock.calls).toEqual([
|
77
|
-
["Translations for locale kl not found!"]
|
78
|
-
])
|
79
|
-
spy.mockRestore()
|
80
|
-
})
|
81
|
-
})
|
82
|
-
|
83
|
-
describe("if Alchemy.translations is not set", () => {
|
84
|
-
it("Returns passed string and logs a warning", () => {
|
85
|
-
const spy = jest.spyOn(console, "warn").mockImplementation(() => {})
|
86
|
-
expect(translate("help")).toEqual("help")
|
87
|
-
expect(spy.mock.calls).toEqual([
|
88
|
-
["Translations for locale kl not found!"]
|
89
|
-
])
|
90
|
-
spy.mockRestore()
|
91
|
-
})
|
92
|
-
})
|
93
|
-
})
|
@@ -1,168 +0,0 @@
|
|
1
|
-
import xhrMock from "xhr-mock"
|
2
|
-
import { get, patch, post } from "../ajax"
|
3
|
-
|
4
|
-
const token = "s3cr3t"
|
5
|
-
|
6
|
-
beforeEach(() => {
|
7
|
-
document.head.innerHTML = `<meta name="csrf-token" content="${token}">`
|
8
|
-
xhrMock.setup()
|
9
|
-
})
|
10
|
-
|
11
|
-
describe("get", () => {
|
12
|
-
it("sends X-CSRF-TOKEN header", async () => {
|
13
|
-
xhrMock.get("http://localhost/users", (req, res) => {
|
14
|
-
expect(req.header("X-CSRF-TOKEN")).toEqual(token)
|
15
|
-
return res.status(200).body('{"message":"Ok"}')
|
16
|
-
})
|
17
|
-
await get("/users")
|
18
|
-
})
|
19
|
-
|
20
|
-
it("sends Content-Type header", async () => {
|
21
|
-
xhrMock.get("http://localhost/users", (req, res) => {
|
22
|
-
expect(req.header("Content-Type")).toEqual(
|
23
|
-
"application/json; charset=utf-8"
|
24
|
-
)
|
25
|
-
return res.status(200).body('{"message":"Ok"}')
|
26
|
-
})
|
27
|
-
await get("/users")
|
28
|
-
})
|
29
|
-
|
30
|
-
it("sends Accept header", async () => {
|
31
|
-
xhrMock.get("http://localhost/users", (req, res) => {
|
32
|
-
expect(req.header("Accept")).toEqual("application/json")
|
33
|
-
return res.status(200).body('{"message":"Ok"}')
|
34
|
-
})
|
35
|
-
await get("/users")
|
36
|
-
})
|
37
|
-
|
38
|
-
it("returns JSON", async () => {
|
39
|
-
xhrMock.get("http://localhost/users", (_req, res) => {
|
40
|
-
return res.status(200).body('{"email":"mail@example.com"}')
|
41
|
-
})
|
42
|
-
await get("/users").then((res) => {
|
43
|
-
expect(res.data).toEqual({ email: "mail@example.com" })
|
44
|
-
})
|
45
|
-
})
|
46
|
-
|
47
|
-
it("JSON parse errors get rejected", async () => {
|
48
|
-
xhrMock.get("http://localhost/users", (_req, res) => {
|
49
|
-
return res.status(200).body('email => "mail@example.com"')
|
50
|
-
})
|
51
|
-
expect.assertions(1)
|
52
|
-
await get("/users").catch((e) => {
|
53
|
-
expect(e.message).toMatch("Unexpected token")
|
54
|
-
})
|
55
|
-
})
|
56
|
-
|
57
|
-
it("network errors get rejected", async () => {
|
58
|
-
xhrMock.get("http://localhost/users", () => {
|
59
|
-
return Promise.reject(new Error())
|
60
|
-
})
|
61
|
-
expect.assertions(1)
|
62
|
-
await get("/users").catch((e) => {
|
63
|
-
expect(e.message).toEqual("An error occurred during the transaction")
|
64
|
-
})
|
65
|
-
})
|
66
|
-
|
67
|
-
it("server errors get rejected", async () => {
|
68
|
-
xhrMock.get("http://localhost/users", (_req, res) => {
|
69
|
-
return res.status(401).body('{"error":"Unauthorized"}')
|
70
|
-
})
|
71
|
-
expect.assertions(1)
|
72
|
-
await get("/users").catch((e) => {
|
73
|
-
expect(e.error).toEqual("Unauthorized")
|
74
|
-
})
|
75
|
-
})
|
76
|
-
|
77
|
-
it("server errors parsing errors get rejected", async () => {
|
78
|
-
xhrMock.get("http://localhost/users", (_req, res) => {
|
79
|
-
return res.status(401).body("Unauthorized")
|
80
|
-
})
|
81
|
-
expect.assertions(1)
|
82
|
-
await get("/users").catch((e) => {
|
83
|
-
expect(e.message).toMatch("Unexpected token")
|
84
|
-
})
|
85
|
-
})
|
86
|
-
|
87
|
-
it("params get attached as query string", async () => {
|
88
|
-
xhrMock.get("http://localhost/users?name=foo", (_req, res) => {
|
89
|
-
return res.status(200).body(`{"name":"foo"}`)
|
90
|
-
})
|
91
|
-
const { data } = await get("/users", { name: "foo" })
|
92
|
-
expect(data.name).toEqual("foo")
|
93
|
-
})
|
94
|
-
})
|
95
|
-
|
96
|
-
describe("patch", () => {
|
97
|
-
it("sends X-CSRF-TOKEN header", async () => {
|
98
|
-
xhrMock.patch("http://localhost/users", (req, res) => {
|
99
|
-
expect(req.header("X-CSRF-TOKEN")).toEqual(token)
|
100
|
-
return res.status(200).body('{"message":"Ok"}')
|
101
|
-
})
|
102
|
-
await patch("/users")
|
103
|
-
})
|
104
|
-
|
105
|
-
it("sends Content-Type header", async () => {
|
106
|
-
xhrMock.patch("http://localhost/users", (req, res) => {
|
107
|
-
expect(req.header("Content-Type")).toEqual(
|
108
|
-
"application/json; charset=utf-8"
|
109
|
-
)
|
110
|
-
return res.status(200).body('{"message":"Ok"}')
|
111
|
-
})
|
112
|
-
await patch("/users")
|
113
|
-
})
|
114
|
-
|
115
|
-
it("sends Accept header", async () => {
|
116
|
-
xhrMock.patch("http://localhost/users", (req, res) => {
|
117
|
-
expect(req.header("Accept")).toEqual("application/json")
|
118
|
-
return res.status(200).body('{"message":"Ok"}')
|
119
|
-
})
|
120
|
-
await patch("/users")
|
121
|
-
})
|
122
|
-
|
123
|
-
it("sends JSON data", async () => {
|
124
|
-
xhrMock.patch("http://localhost/users", (req, res) => {
|
125
|
-
expect(req.body()).toEqual('{"email":"mail@example.com"}')
|
126
|
-
return res.status(200).body('{"message":"Ok"}')
|
127
|
-
})
|
128
|
-
await patch("/users", { email: "mail@example.com" })
|
129
|
-
})
|
130
|
-
})
|
131
|
-
|
132
|
-
describe("post", () => {
|
133
|
-
it("sends X-CSRF-TOKEN header", async () => {
|
134
|
-
xhrMock.post("http://localhost/users", (req, res) => {
|
135
|
-
expect(req.header("X-CSRF-TOKEN")).toEqual(token)
|
136
|
-
return res.status(200).body('{"message":"Ok"}')
|
137
|
-
})
|
138
|
-
await post("/users")
|
139
|
-
})
|
140
|
-
|
141
|
-
it("sends Content-Type header", async () => {
|
142
|
-
xhrMock.post("http://localhost/users", (req, res) => {
|
143
|
-
expect(req.header("Content-Type")).toEqual(
|
144
|
-
"application/json; charset=utf-8"
|
145
|
-
)
|
146
|
-
return res.status(200).body('{"message":"Ok"}')
|
147
|
-
})
|
148
|
-
await post("/users")
|
149
|
-
})
|
150
|
-
|
151
|
-
it("sends Accept header", async () => {
|
152
|
-
xhrMock.post("http://localhost/users", (req, res) => {
|
153
|
-
expect(req.header("Accept")).toEqual("application/json")
|
154
|
-
return res.status(200).body('{"message":"Ok"}')
|
155
|
-
})
|
156
|
-
await post("/users")
|
157
|
-
})
|
158
|
-
|
159
|
-
it("sends JSON data", async () => {
|
160
|
-
xhrMock.post("http://localhost/users", (req, res) => {
|
161
|
-
expect(req.body()).toEqual('{"email":"mail@example.com"}')
|
162
|
-
return res.status(200).body('{"message":"Ok"}')
|
163
|
-
})
|
164
|
-
await post("/users", { email: "mail@example.com" })
|
165
|
-
})
|
166
|
-
})
|
167
|
-
|
168
|
-
afterEach(() => xhrMock.teardown())
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { on } from "../events"
|
2
|
-
|
3
|
-
describe("on", () => {
|
4
|
-
const callback = jest.fn()
|
5
|
-
|
6
|
-
beforeEach(() => {
|
7
|
-
document.body.innerHTML = `
|
8
|
-
<ul class="list">
|
9
|
-
<li class="first item"><span>One</span></li>
|
10
|
-
<li class="second item">Two</li>
|
11
|
-
</ul>
|
12
|
-
`
|
13
|
-
})
|
14
|
-
|
15
|
-
it("adds event listener to base node", () => {
|
16
|
-
const baseNode = document.querySelector(".list")
|
17
|
-
const spy = jest.spyOn(baseNode, "addEventListener")
|
18
|
-
on("click", ".list", ".item", callback)
|
19
|
-
expect(spy).toHaveBeenCalledWith("click", expect.any(Function))
|
20
|
-
spy.mockReset()
|
21
|
-
})
|
22
|
-
|
23
|
-
it("event triggered on matching child node calls callback", () => {
|
24
|
-
const childNode = document.querySelector(".first.item")
|
25
|
-
on("click", ".list", ".item", callback)
|
26
|
-
childNode.click()
|
27
|
-
expect(callback).toHaveBeenCalledWith(expect.any(MouseEvent))
|
28
|
-
})
|
29
|
-
|
30
|
-
it("event triggered on child of registered target still calls callback", () => {
|
31
|
-
const child = document.querySelector(".first.item span")
|
32
|
-
on("click", ".list", ".item", callback)
|
33
|
-
child.click()
|
34
|
-
expect(callback).toHaveBeenCalledWith(expect.any(MouseEvent))
|
35
|
-
})
|
36
|
-
|
37
|
-
afterEach(() => callback.mockReset())
|
38
|
-
})
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|