Cypress mat-select select command failing - material-ui

Trying to test a select control with Cypress. I found the .select(option) command which seems pretty straight-forward, but cannot get it to work
This is my form:
<form>
<mat-form-field appearance="fill">
<mat-label>Food ingredients</mat-label>
<mat-select [(ngModel)]="selectedValue" name="food">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</form>
This is my test:
cy.get('mat-select').click()
.select('Cauliflower')
but it throws the error "cy.select() can only be called on a <select>"

Angular mat-select isn't a normal <select> element, you can't use the .select() command.
Use .click() instead
cy.get('mat-select').click()
cy.contains('mat-option', 'Cauliflower').click()
This is the runtime HTML
<div class="mat-select-panel-wrap">
<div role="listbox">
<mat-option role="option">
<span class="mat-option-text"> Cabbage </span>
</mat-option>
<mat-option role="option">
<span class="mat-option-text"> Cauliflower </span>
</mat-option>
<mat-option role="option">
<span class="mat-option-text"> Capsicum </span>
</mat-option>
</div>
</div>

Related

Bad Request/form not defined on modal form submit to email - flask

I am trying to submit a modal form with various input data to my email through my flask app, but am getting 400 bad request error or "form is not defined" error because I tried using this line in the function:
form = modal1form(request.form)
Not sure whats wrong here - note: modal is located at /dashboard/projects/#modal1
Thanks
# new project function
#app.route('/dashboard/projects/#modal1form/', methods=["GET","POST"])
def new_project():
try:
if request.method == "POST":
if form.validate() == False:
flash('Invalid! All fields are required.')
return redirect(url_for('new_project'))
else:
msg = Message(request.form['name'], sender='request.form["email"]', recipients=['myemail#gmail.com'])
msg.body = """
From: %s %s \n
%s \n \n %s \n \n %s \n %s \n
%s
""" % (request.form['wtype', 'wpack', 'bts', 'fts', 'comments'])
mail.send(msg)
flash('Congratulations! A new project has been submitted.')
gc.collect()
return render_template('dashboardProjects.html')
elif request.method == 'GET':
return render_template("dashboardProjects.html")
except Exception as e:
return(str(e))
modal form
<div id="modal1" class="modal fade">
<form method="post" action="{{ url_for('new_project') }}" role="form" id="modal1form" name="modal1form">
<div class="form-group text-center">
<label for="name" class="control-label text-center"> Name </label>
<input type="text" class="form-control" name="name" id="name" placeholder="Your Name">
</div>
<div class="form-group text-center">
<label for="email" class="text-center"> Email Address </label>
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email">
</div>
<div class="col-md-3 col-md-offset-1">
<div class="form-group"> <br>
<label for="wtype"> Website Type </label> <br>
<h5 class="form-check-inline">
<input class="form-check-input" type="checkbox" name="wtype" id="wtype1" value="Static"> Static
</h5>
<h5 class="form-check-inline">
<input class="form-check-input" type="checkbox" name="wtype" id="wtype2" value="Blog"> Blog
</h5>
</div>
</div>
<br>
<div class="col-md-4 col-md-offset-1">
<div class="form-group">
<label for="wpack"> Website Package </label> <br>
<h5 class="form-check-inline">
<input class="form-check-input" name="wpack" type="radio" id="wpack2" value="Blog"> Basic
</h5>
<h5 class="form-check-inline">
<input class="form-check-input" name="wpack" type="radio" id="wpack3" value="Ecommerce"> Standard <br>
</h5>
</div>
</div>
<li class="dropdown pull-right list-unstyled" aria-expanded="false" style="position: top;"> <a class="dropdown-toggle" data-toggle="dropdown" role="button" style="font-size: 14px;"> <span class="caret"></span> <label for="template"> <i class="fa fa-cube"></i> Template </label> </a>
<ul class="dropdown-menu list-unstyled">
<li><h5 class="text-center"> <i class="fa fa-cubes"></i> Templates</h5></li>
<li><input name="bts" type="radio"/> Basic Template 1</li>
<li><input name="bts" type="radio"/> Basic Template 2</li>
<li role="separator" class="divider"></li>
<li><input name="fts" type="radio"/> Footer 1</li>
</ul>
</li>
</div>
<div class="form-group text-center"> <br>
<label for="comments"> Other Details </label>
<textarea name="comments" class="form-control" id="comments" placeholder="Additional comments, ideas, requests, questions?"></textarea>
<p class="help-block"> </p>
</div>
</form>
</div>
<div class="modal-footer brick">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success" form="modal1form">Submit</button>
</div>
ERROR 1: form is not defined
If you want to use Flask-WTF, you must create a Form, like this:
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DateRrequired
app = Flask(__name__)
app.config['SECRET_KEY'] = 'a very secret string'
class MyForm(FlaskForm):
name = StringForm('Your Name', validators=[DataRequired()])
submit = SubmitField()
app.route('/', methods=['GET', 'POST'])
def index():
form = MyForm()
if form.validate_on_submit():
name = form.name.data
...
return render_template('index.html', form=form)
Then you need to render the form in HTML template:
<form method="post">
{{ form.name() }}
{{ form.submit() }}
</form>
ERROR 2: 400 Bad request
In Flask, if you get form data by request.form['name'], you must be ensure this input have value, that's why you get the 400 error. Instead, I recommend you to use request.form.get('name', default_value), you can set a default value (as second argument) to avoid 400 error.
More details:
flask.pocoo.org/docs/0.11/patterns/wtforms
Hope it will help you.
Maybe ERROR 3: Bootstrap Modal
You can't open a modal with anchor name, like example.com#MyModal, but other modal plugin can. Check my answer on another question about this.

Bootstrap .form-inline but keep label above fields

<div class="form-inline">
<div class="form-group has-feedback">
<label for="id_first_name">First Name</label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input class="form-control" id="id_first_name" name="first_name" type="text" />
</div>
</div>
<div class="form-group has-feedback">
<label for="id_last_name">Last Name</label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input class="form-control" id="id_last_name" name="last_name" type="text" />
</div>
</div>
</div>
I get a output similar to this: http://i.stack.imgur.com/YKvOY.png
But I want the labels above the fields.
I googled and I see a lot of people have the same problem but exactly the opposite. They have the labels above the fields and want them in the same line. However I tried their code, still not working.
I've created this fiddle demonstrating this using what you provided. form-group should do the trick.

Form submit from Bootstrap 3 and JSP get parameter

I'm new to Bootstrap. But I'm pretty familiar with HTML. The thing is I cannot get parameter values from JSP. The parameters are from HTML page with Bootstrap 3. Here're the code. I don't understand. If I make simple html only page, then I could get the parameters.
<form class="form-horizontal" method="POST" action="makeResv.jsp">
<div class="container">
<div class="row">
<div class="control-group col-md-5">
<label for="checkIn">date1</label>
<div id="date-container">
<div class="input-group date">
<input type="text" id="checkIn" class="form-control"><span
class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="control-group col-md-5">
<label for="checkOut">date2</label>
<div id="date-container">
<div class="input-group date">
<input type="text" id="checkOut" class="form-control"><span
class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-success">search</button>
</div>
</div>
</div>
</form>
In a JSP page, I'm just doing the following.
String checkIn = request.getParameter("checkIn");
String checkOut = request.getParameter("checkOut");
out.println(checkIn + " " + checkOut);
What's wrong with the above HTML code with Bootstrap?? Please give me some advise. Thanks!!
BTW, I'm using datepicker JavaScript library, but I don't think that affect the results. I cannot add the library code here but it works great anyway.
https://github.com/eternicode/bootstrap-datepicker
Bootstrap is same as HTML. The problem you are having is because you do not have any name attribute defined in your input element. You define id but to access submited variables via POST (request.getParameter() function) you need to have name attribute defined:
Replace <input> lines like this:
<input type="text" name="checkIn" id="checkIn" class="form-control">
And
<input type="text" name="checkOut" id="checkOut" class="form-control"><

Float forms inside a well

I want to put 2 forms in a well one next to other. I use twitter-boostrap.
This is my code
<div class="well">
<h3>
Title
</h3>
<form method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="select01">Label1: </label>
<select class="input-mini" id="select01">
(my options)
</select>
</div>
<div class="control-group">
<label class="control-label" for="input01">Label2: </label>
<input class="input-mini" id="input01">
</div>
<div class="control-group">
<label class="control-label" for="select02">Label3: </label>
<select class="input-mini" id="select02">
(myoptions)
</select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
<form method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="input02">Label3: </label>
<input class="input-mini" id="input02">
</div>
<div class="control-group">
<label class="control-label" for="input03">Label4: </label>
<input class="input-mini" id="input03">
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
If I include the forms in divs and add a style with float:left, then my well brake and put my forms out of it. I tried span, divs, form inside a form, but I cannot find a way to put one form next to other without break the well.
Try wrapping your forms in a div to isolate that content from the well:
http://jsfiddle.net/SAdM8/6
<div class="well">
<div style="overflow: hidden;">
... forms ...
</div>
</div>
Like Billy Moat said, you could simply add the overflow property to the well. I prefer to keep Bootstrap elements in their natural state to avoid inadvertent breakage. Either works.

Facebook Style Comment Box

I have tweets and commenting system like this
This is the code block for one set of tweet and its comments and commenting box:
<li class="storyBlock">
<div>
<div class="grid userImageBlockL">
<div class="imgMedium"> <img width="44" height="44" alt="image" src="/bakasura1/files/images/medium/1288170363aca595cabb50.jpg"> </div>
</div>
<div class="grid userContentBlockL">
<div class="userContentHeader">
<h5> Harsha Vantagudi <span class="storyMessage">Testing the Seconds</span></h5>
<span class="user-status-time">6 hours ago</span> <span>Comment Delete</span> </div>
<ul class="commentList">
<li class="commentBlock">
<div>
<div class="grid userImageBlockS">
<div class="imgSmall"> <img width="35" height="35" alt="image" src="/bakasura1/files/images/small/1288170363aca595cabb50.jpg"> </div>
</div>
<div class="grid userContentBlockS alpha omega">
<h5> Harsha Vantagudi <span class="storyMessage">Write your comment...</span></h5>
<span class="user-status-time">27 minutes ago</span> <span>Comment Delete</span></div>
<div class="clear"></div>
</div>
</li>
<li class="commentBlock">
<div>
<div class="grid userImageBlockS">
<div class="imgSmall"> <img width="35" height="35" alt="image" src="/bakasura1/files/images/small/1288170363aca595cabb50.jpg"> </div>
</div>
<div class="grid userContentBlockS alpha omega">
<form accept-charset="utf-8" action="/bakasura1/account/saveComment" method="post">
<div style="display: none;">
<input type="hidden" value="POST" name="_method">
</div>
<input type="hidden" id="StatusMessageReplyPid" value="67" name="data[StatusMessageReply][pid]">
<input type="hidden" id="StatusMessageReplyItemId" value="1" name="data[StatusMessageReply][item_id]">
<input type="hidden" id="StatusMessageReplyCommentersItemId" value="1" name="data[StatusMessageReply][commenters_item_id]">
<textarea id="StatusMessageReplyMessage" name="data[StatusMessageReply][message]">Write your comment...</textarea>
<input type="submit" name="" value="Comment">
</form>
</div>
<div class="clear"></div>
</div>
</li>
</ul>
</div>
<div class="clear"></div>
</div>
</li>
I am a little confused as to how to create an Ajax from submit when the comment is saved the new comment should stack top to bottom. Since there is no unique tweet identifier. I am not sure how to address this problem.
Can some one recommend an easy solution for the same?
http://demos.99points.info/facebook_wallpost_system/
nice demo and tutorial there
Did you try this plugin ,
http://timeago.yarp.com/
this should help