No more fake text in the publisher

This commit is contained in:
Steffen van Bergerem 2017-01-30 13:19:50 +01:00
parent a04f32adce
commit c4b6b9534c
No known key found for this signature in database
GPG key ID: 315C9787D548DC6B
12 changed files with 43 additions and 91 deletions

View file

@ -6,18 +6,17 @@ app.views.PublisherMention = app.views.SearchBase.extend({
mentionSyntaxTemplate: function(person) { return "@{" + person.handle + "}"; },
events: {
"keydown #status_message_fake_text": "onInputBoxKeyDown",
"input #status_message_fake_text": "onInputBoxInput",
"click #status_message_fake_text": "onInputBoxClick",
"blur #status_message_fake_text": "onInputBoxBlur"
"keydown #status_message_text": "onInputBoxKeyDown",
"input #status_message_text": "onInputBoxInput",
"click #status_message_text": "onInputBoxClick",
"blur #status_message_text": "onInputBoxBlur"
},
initialize: function() {
this.mentionedPeople = [];
// contains the 'fake text' displayed to the user
// also has a data-messageText attribute with the original text
this.inputBox = this.$("#status_message_fake_text");
// has a data-messageText attribute with the original text
this.inputBox = this.$("#status_message_text");
this.typeaheadInput = this.$(".typeahead-mention-box");
this.bindTypeaheadEvents();

View file

@ -18,11 +18,11 @@ app.views.Publisher = Backbone.View.extend({
el : "#publisher",
events : {
"keydown #status_message_fake_text" : "keyDown",
"keydown #status_message_text": "keyDown",
"focus textarea" : "open",
"submit form" : "createStatusMessage",
"click #submit" : "createStatusMessage",
"textchange #status_message_fake_text": "handleTextchange",
"textchange #status_message_text": "handleTextchange",
"click #locator" : "showLocation",
"click #poll_creator" : "togglePollCreator",
"click #hide_location" : "destroyLocation",
@ -35,8 +35,7 @@ app.views.Publisher = Backbone.View.extend({
this.disabled = false;
// init shortcut references to the various elements
this.inputEl = this.$("#status_message_fake_text");
this.hiddenInputEl = this.$("#status_message_text");
this.inputEl = this.$("#status_message_text");
this.wrapperEl = this.$("#publisher_textarea_wrapper");
this.submitEl = this.$("input[type=submit], button#submit");
this.photozoneEl = this.$("#photodropzone");
@ -46,14 +45,6 @@ app.views.Publisher = Backbone.View.extend({
$(window).on("beforeunload", _.bind(this._beforeUnload, this));
$(window).unload(this.clear.bind(this));
// sync textarea content
if( this.hiddenInputEl.val() === "" ) {
this.hiddenInputEl.val( this.inputEl.val() );
}
if( this.inputEl.val() === "" ) {
this.inputEl.val( this.hiddenInputEl.val() );
}
// hide close and preview buttons and manage services link
// in case publisher is standalone
// (e.g. bookmarklet, mentions popup)
@ -175,7 +166,6 @@ app.views.Publisher = Backbone.View.extend({
// inject content into the publisher textarea
setText: function(txt) {
this.inputEl.val(txt);
this.hiddenInputEl.val(txt);
this.prefillText = txt;
this.inputEl.trigger("input");
@ -381,11 +371,10 @@ app.views.Publisher = Backbone.View.extend({
// remove mentions
this.mention.reset();
// clear text(s)
// clear text
this.inputEl.val("");
this.hiddenInputEl.val("");
this.inputEl.trigger("keyup")
.trigger("keydown");
.trigger("keydown");
autosize.update(this.inputEl);
// remove photos
@ -421,7 +410,6 @@ app.views.Publisher = Backbone.View.extend({
// force textchange plugin to update lastValue
this.inputEl.data("lastValue", "");
this.hiddenInputEl.data("lastValue", "");
return this;
},
@ -487,10 +475,8 @@ app.views.Publisher = Backbone.View.extend({
setInputEnabled: function(bool) {
if (bool) {
this.inputEl.removeAttr("disabled");
this.hiddenInputEl.removeAttr("disabled");
} else {
this.inputEl.prop("disabled", true);
this.hiddenInputEl.prop("disabled", true);
}
},
@ -505,7 +491,6 @@ app.views.Publisher = Backbone.View.extend({
handleTextchange: function() {
this.checkSubmitAvailability();
this.hiddenInputEl.val(this.mention.getTextForSubmit());
},
_beforeUnload: function(e) {

View file

@ -21,16 +21,6 @@ module InterimStreamHackinessHelper
end
end
def publisher_hidden_text
if params[:prefill].present?
params[:prefill]
elsif defined?(@stream)
@stream.publisher.prefill
else
nil
end
end
def from_group(post)
if defined?(@stream) && params[:controller] == 'multis'
@stream.post_from_group(post)

View file

@ -6,17 +6,16 @@
.publisher-textarea-wrapper#publisher_textarea_wrapper
.mentions-input-box
- if current_user.getting_started?
= status.text_area :fake_text, :rows => 2, :value => h(publisher_formatted_text),
= status.text_area :text, :rows => 2, :value => h(publisher_formatted_text),
:tabindex => 1, :placeholder => "#{t('contacts.index.start_a_conversation')}...",
"data-title" => popover_with_close_html("1. " + t("shared.public_explain.share")),
"data-content" => t("shared.public_explain.new_user_welcome_message"),
"class" => "form-control"
- else
= status.text_area :fake_text, :rows => 2, :value => h(publisher_formatted_text),
= status.text_area :text, :rows => 2, :value => h(publisher_formatted_text),
:tabindex => 1, :placeholder => "#{t('contacts.index.start_a_conversation')}...",
"class" => "form-control"
%input.typeahead-mention-box.hidden{type: "text"}
= status.hidden_field :text, value: h(publisher_hidden_text), class: "clear_on_submit"
.container-fluid.photodropzone-container#photodropzone_container
%ul#photodropzone

View file

@ -44,7 +44,7 @@ Feature: preview posts in the stream
Given I expand the publisher
And I attach "spec/fixtures/button.png" to the publisher
When I fill in the following:
| status_message_fake_text | Look at this dog |
| status_message_text | Look at this dog |
And I preview the post
Then I should see a "img" within ".md-preview .stream-element .photo_attachments"
And I should see "Look at this dog" within ".md-preview .stream-element"
@ -63,7 +63,7 @@ Feature: preview posts in the stream
Then I should see "Samuel Beckett"
When I expand the publisher
And I fill in the following:
| status_message_fake_text | This preview rocks |
| status_message_text | This preview rocks |
And I preview the post
Then I should see "This preview rocks" in the preview
And I close the publisher
@ -71,11 +71,11 @@ Feature: preview posts in the stream
Scenario: preview a post with the poll
Given I expand the publisher
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| status_message_text | I am eating yogurt |
And I click on selector "#poll_creator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
| status_message_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
And I fill in the following for the options:
| normal |
| not normal |
@ -87,12 +87,12 @@ Feature: preview posts in the stream
Scenario: preview a post with location
Given I expand the publisher
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| status_message_text | I am eating yogurt |
And I allow geolocation
And I click on selector "#locator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| location_address | Some cool place |
| status_message_text | I am eating yogurt |
| location_address | Some cool place |
And I preview the post
Then I should see a ".near-from" within ".md-preview .stream-element"
And I should see "Some cool place" within ".md-preview .stream-element .near-from"

View file

@ -40,8 +40,8 @@ Feature: posting with a poll
Given I expand the publisher
And I click on selector "#poll_creator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
| status_message_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
And I fill in the following for the options:
| normal |
| not normal |
@ -53,8 +53,8 @@ Feature: posting with a poll
Given I expand the publisher
And I click on selector "#poll_creator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
| status_message_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
And I fill in the following for the options:
| normal |
| not normal |
@ -70,8 +70,8 @@ Feature: posting with a poll
Given I expand the publisher
And I click on selector "#poll_creator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
| status_message_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
And I fill in the following for the options:
| normal |
| not normal |
@ -83,8 +83,8 @@ Feature: posting with a poll
Given I expand the publisher
And I click on selector "#poll_creator"
When I fill in the following:
| status_message_fake_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
| status_message_text | I am eating yogurt |
| poll_question | What kind of yogurt do you like? |
And I fill in the following for the options:
| normal |
| |

View file

@ -20,7 +20,7 @@ Feature: posting from the mobile main page
Scenario: post and delete some text
Given I visit the mobile publisher page
And I append "I am eating yogurt" to the mobile publisher
And I append "I am eating yogurt" to the publisher
And I select "Unicorns" from "aspect_ids_"
And I press "Share"
When I go to the stream page
@ -52,7 +52,7 @@ Feature: posting from the mobile main page
Scenario: back out of uploading a picture when another has been attached
Given I visit the mobile publisher page
And I append "I am eating yogurt" to the mobile publisher
And I append "I am eating yogurt" to the publisher
And I attach the file "spec/fixtures/button.gif" to hidden "qqfile" within "#file-upload-publisher"
And I attach the file "spec/fixtures/button.png" to hidden "qqfile" within "#file-upload-publisher"
And I click to delete the first uploaded photo

View file

@ -5,7 +5,7 @@ When /^I press the "([^\"]*)" key somewhere$/ do |key|
end
When /^I press the "([^\"]*)" key in the publisher$/ do |key|
find("#status_message_fake_text").native.send_key(key)
find("#status_message_text").native.send_key(key)
end
Then /^post (\d+) should be highlighted$/ do |position|

View file

@ -33,7 +33,7 @@ Then /^I should not be able to submit the publisher$/ do
end
Then /^I should see "([^"]*)" in the publisher$/ do |text|
expect(page).to have_field("status_message[fake_text]", with: text)
expect(page).to have_field("status_message[text]", with: text)
end
Given /^I have a limited post with text "([^\"]*)" in the aspect "([^"]*)"$/ do |text, aspect_name|
@ -118,10 +118,6 @@ When /^I append "([^"]*)" to the publisher$/ do |text|
append_to_publisher(text)
end
When /^I append "([^"]*)" to the mobile publisher$/ do |text|
append_to_publisher(text, '#status_message_text')
end
When /^I attach "([^"]*)" to the publisher$/ do |path|
upload_file_with_publisher(path)
end

View file

@ -1,21 +1,12 @@
module PublishingCukeHelpers
def write_in_publisher(txt)
fill_in 'status_message_fake_text', with: txt
fill_in "status_message_text", with: txt
end
def append_to_publisher(txt, input_selector='#status_message_fake_text')
status_message_text = find("#status_message_text", visible: false).value
find(input_selector).native.send_key(" #{txt}")
# make sure the other text field got the new contents
if input_selector == "#status_message_fake_text"
begin
expect(page).to have_selector("#status_message_text[value='#{status_message_text} #{txt}']", visible: false)
rescue RSpec::Expectations::ExpectationNotMetError
puts "Value was instead: #{find('#status_message_text', visible: false).value.inspect}"
raise
end
end
def append_to_publisher(txt)
status_message_text = find("#status_message_text").value
find("#status_message_text").native.send_key(" #{txt}")
expect(page).to have_field("status_message[text]", with: "#{status_message_text} #{txt}")
end
def upload_file_with_publisher(path)
@ -33,7 +24,7 @@ module PublishingCukeHelpers
end
def submit_publisher
txt = find("#publisher #status_message_fake_text").value
txt = find("#publisher #status_message_text").value
find("#publisher .btn-primary").click
# wait for the content to appear
expect(find("#main_stream")).to have_content(txt)
@ -45,7 +36,7 @@ module PublishingCukeHelpers
end
def click_publisher
find("#status_message_fake_text").click
find("#status_message_text").click
expect(find("#publisher")).to have_css(".publisher-textarea-wrapper.active")
end

View file

@ -29,23 +29,18 @@ describe("app.views.Bookmarklet", function() {
it("prefills the publisher", function() {
init_bookmarklet(test_data);
expect($.trim(app.publisher.inputEl.val())).not.toEqual("");
expect($.trim(app.publisher.hiddenInputEl.val())).not.toEqual("");
});
it("handles dirty input well", function() {
init_bookmarklet(evil_test_data);
expect($.trim(app.publisher.inputEl.val())).not.toEqual("");
expect($.trim(app.publisher.hiddenInputEl.val())).not.toEqual("");
});
it("allows changing a prefilled publisher", function() {
init_bookmarklet(test_data);
app.publisher.setText(app.publisher.inputEl.val()+"A");
expect(app.publisher.hiddenInputEl.val()).toMatch(/.+A$/);
expect(app.publisher.inputEl.val()).toMatch(/.+A$/);
});
it("keeps the publisher disabled after successful post creation", function() {

View file

@ -82,9 +82,9 @@ describe("app.views.Publisher", function() {
});
it("resets the element's height", function() {
$(this.view.el).find("#status_message_fake_text").height(100);
$(this.view.el).find("#status_message_text").height(100);
this.view.close($.Event());
expect($(this.view.el).find("#status_message_fake_text").attr("style")).not.toContain("height");
expect($(this.view.el).find("#status_message_text").attr("style")).not.toContain("height");
});
it("calls autosize.update", function() {
@ -235,9 +235,7 @@ describe("app.views.Publisher", function() {
describe('#setText', function() {
it("sets the content text", function() {
this.view.setText("FOO bar");
expect(this.view.inputEl.val()).toEqual("FOO bar");
expect(this.view.hiddenInputEl.val()).toEqual("FOO bar");
});
});
@ -248,7 +246,6 @@ describe("app.views.Publisher", function() {
expect(this.view.disabled).toBeTruthy();
expect(this.view.inputEl.prop("disabled")).toBeTruthy();
expect(this.view.hiddenInputEl.prop("disabled")).toBeTruthy();
});
it("disables submitting", function() {