Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Qpixel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Answers
Qpixel
Commits
d25afd6c
Commit
d25afd6c
authored
Aug 2, 2023
by
Taico Aerts
Browse files
Options
Downloads
Patches
Plain Diff
Add basic post creation test
parent
27a3c09b
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!51
Upgrade to latest qpixel
,
!50
Update to latest codidact changes
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/application_system_test_case.rb
+38
-0
38 additions, 0 deletions
test/application_system_test_case.rb
test/system/post_test.rb
+27
-0
27 additions, 0 deletions
test/system/post_test.rb
with
65 additions
and
0 deletions
test/application_system_test_case.rb
+
38
−
0
View file @
d25afd6c
...
@@ -62,4 +62,42 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
...
@@ -62,4 +62,42 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
users
(
user_or_fixture
)
users
(
user_or_fixture
)
end
end
end
end
# In the post form, this method will select the given tag.
#
# @param tag_name [String] the name of the tag
# @param create_new [Boolean] whether creating a new tag is allowed (default false)
def
post_form_select_tag
(
tag_name
,
create_new
=
false
)
# First enter the tag name into the select2 search field for the tag
within
find_field
(
'Tags (at least one):'
).
find
(
:xpath
,
'..'
)
do
find
(
'.select2-search__field'
).
fill_in
(
with:
tag_name
)
end
# Get the first item listed that is not the "Searching..." item
first_option
=
find
(
'#select2-post_tags_cache-results li:first-child'
)
{
|
el
|
el
.
text
!=
'Searching…'
}
if
first_option
.
first
(
'span'
).
text
==
tag_name
# If the text matches the tag name, first check whether we are creating a new tag.
# If so, confirm that we are allowed to. If all is good, actually click on the item.
if
create_new
||
!
first_option
.
text
.
include?
(
'Create new tag'
)
first_option
.
click
else
raise
"Expected to find tag with the name
#{
tag_name
}
, "
\
'but could not select it from options without creating a new tag.'
end
elsif
create_new
# The first item returned is not the tag we were looking for (another tag partial match + not existing)
# If we are allowed to create a tag, select the last option from the list, which is always the tag creation.
last_option
=
find
(
'#select2-post_tags_cache-results li:last-child'
)
if
last_option
.
first
(
'span'
).
text
==
tag_name
last_option
.
click
else
raise
"Tried to select tag
#{
tag_name
}
for creation, but it does not seem to be a presented option."
end
else
# The first item returned is not the tag we were looking for, and we are not allowed to create a tag.
raise
"Expected to find tag with the name
#{
tag_name
}
, "
\
'but could not select it from options without creating a new tag.'
end
end
end
end
This diff is collapsed.
Click to expand it.
test/system/post_test.rb
0 → 100644
+
27
−
0
View file @
d25afd6c
require
'application_system_test_case'
class
PostTest
<
ApplicationSystemTestCase
test
'Not-signed in user cannot create a post'
do
visit
root_url
click_on
'Create Post'
assert_current_path
new_user_session_url
end
test
'Signed in user can create a post'
do
category
=
categories
(
:meta
)
log_in
:standard_user
visit
category_path
(
category
)
click_on
'Create Post'
fill_in
'Body'
,
with:
"When running QPixel, users are generally supposed to be able to create posts.
\n
"
\
'Does that actually work?'
fill_in
'Summarize your post with a title:'
,
with:
'Can a signed-in user create a post?'
post_form_select_tag
tags
(
:faq
).
name
click_on
"Save Post in
#{
category
.
name
}
a"
end
# TODO: Post validations
# TODO: Sort urls
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment