Skip to content

Commit

Permalink
Merge pull request #273 from crossroads/master
Browse files Browse the repository at this point in the history
September2019Release1
  • Loading branch information
abulsayyad123 authored Sep 12, 2019
2 parents 4126e35 + e88f952 commit 178f477
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 94 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_magick (4.9.5)
mini_portile2 (2.3.0)
mini_portile2 (2.4.0)
minitest (5.11.3)
molinillo (0.6.6)
multi_json (1.13.1)
Expand All @@ -161,8 +161,8 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (5.0.2)
netrc (0.11.0)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
os (1.0.1)
plist (3.5.0)
public_suffix (2.0.5)
Expand Down
36 changes: 20 additions & 16 deletions app/routes/offers/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
import AuthorizeRoute from './../authorize';
import AuthorizeRoute from "./../authorize";

export default AuthorizeRoute.extend({

model() {
return this.store.peekAll('offer');
let cachedRecords = this.store.peekAll("offer");
if (cachedRecords.get("length")) {
return cachedRecords;
}
return this.store.findAll("offer");
},

redirect(my_offers) {
var route = this;
switch(my_offers.get('length')) {
case 0 : route.transitionTo('offers.new'); break;
case 1 :
if(my_offers.get('firstObject.state') === 'draft') {
var firstOffer = my_offers.get('firstObject');
if(firstOffer.get('itemCount') === 0) {
route.transitionTo('offer', firstOffer);
switch (my_offers.get("length")) {
case 0:
route.transitionTo("offers.new");
break;
case 1:
if (my_offers.get("firstObject.state") === "draft") {
var firstOffer = my_offers.get("firstObject");
if (firstOffer.get("itemCount") === 0) {
route.transitionTo("offer", firstOffer);
} else {
route.transitionTo('offer.offer_details', firstOffer);
route.transitionTo("offer.offer_details", firstOffer);
}
}
}
},

renderTemplate() {
this.render(); // default template
this.render('appMenuList', {
into: 'offers/index',
outlet: 'appMenuList',
controller: 'application'
this.render("appMenuList", {
into: "offers/index",
outlet: "appMenuList",
controller: "application"
});
}

});
2 changes: 1 addition & 1 deletion app/templates/item/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>

<div class="small-6 columns">
{{#online-button classNames="add_item_link button expand" disabledOverride=disabled disabled=isOfferReviewed offer=model.offer}}{{t "items.add_item.save"}}{{/online-button}}
{{#online-button classNames="add_item_link button expand" tagName="button" disabledOverride=disabled disabled=isOfferReviewed offer=model.offer}}{{t "items.add_item.save"}}{{/online-button}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/offer/ios_notification.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{{#link-to "offer.submit" classNames="button expand secondary"}}{{t "offer.notifications.no"}}{{/link-to}}
</div>
<div class="small-6 columns">
{{#online-button action="sendPushNotification" classNames="button expand"}}{{t "offer.notifications.notify"}}{{/online-button}}
{{#online-button action="sendPushNotification" tagName="button" classNames="button expand"}}{{t "offer.notifications.notify"}}{{/online-button}}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/offer/submit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<div class="btm">
<div class="row">
<div class="small-6 columns">
{{#online-button action="submitOffer" actionArgs=false classNames="button expand secondary"}}{{t "no"}}{{/online-button}}
{{#online-button action="submitOffer" tagName="button" actionArgs=false classNames="button expand secondary"}}{{t "no"}}{{/online-button}}
</div>
<div class="small-6 columns">
{{#online-button action="submitOffer" actionArgs=true classNames="button expand"}}{{t "yes"}}{{/online-button}}
{{#online-button action="submitOffer" actionArgs=true classNames="button expand submit"}}{{t "yes"}}{{/online-button}}
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "goodcity",
"version": "0.16.9",
"version": "0.17.0",
"description": "Small description for goodcity goes here",
"license": "MIT",
"author": "",
Expand Down
61 changes: 39 additions & 22 deletions tests/acceptance/create-offer-test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import Ember from 'ember';
import startApp from '../helpers/start-app';
import { make } from 'ember-data-factory-guy';
import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import { module, test } from 'qunit';
import Ember from "ember";
import startApp from "../helpers/start-app";
import { make } from "ember-data-factory-guy";
import TestHelper from "ember-data-factory-guy/factory-guy-test-helper";
import { module, test } from "qunit";
// import { mockFindAll } from 'ember-data-factory-guy';


var App, container;

module('Create New Offer', {
module("Create New Offer", {
beforeEach: function() {
App = startApp({}, 2);
container = App.__container__;
TestHelper.setup();
},
afterEach: function() {
Em.run(function() { TestHelper.teardown(); });
Ember.run(App, 'destroy');
Em.run(function() {
TestHelper.teardown();
});
Ember.run(App, "destroy");
}
});

Expand All @@ -29,43 +30,59 @@ test("should create new offer", function(assert) {

andThen(function() {
// test: created new offer and redirected to its show page.
assert.equal(currentURL(), '/offers/2');
assert.equal(currentURL(), "/offers/3");

//test: item count zero
assert.equal($.trim(find('.tab-bar-section .title').text()), "Offer items (0)");
assert.equal(
$.trim(find(".tab-bar-section .title").text()),
"Offer items (0)"
);

//test: no items message
assert.equal($.trim($('.no-items').text()), "You don't have any items in this offer yet. Please add your first item!");
assert.equal(
$.trim($(".no-items").text()),
"You don't have any items in this offer yet. Please add your first item!"
);
});
});

test("should redirect to previous empty offer", function(assert) {
assert.expect(4);

var currentUserId = JSON.parse(window.localStorage.currentUserId);
var user = make("user", {id:currentUserId});
make("offer_with_items", {id:1, createdBy:user}); // check offer with items is not returned
make("offer",{"id":5, createdBy:user});

container.lookup("service:messageBox").custom = (message, btn1Text, btn1Callback) => {
var user = make("user", { id: currentUserId });
make("offer_with_items", { id: 1, createdBy: user }); // check offer with items is not returned
make("offer", { id: 5, createdBy: user });

container.lookup("service:messageBox").custom = (
message,
btn1Text,
btn1Callback
) => {
btn1Callback();
};

visit("/offers");

andThen(function() {
assert.equal(currentURL(), '/offers');
assert.equal(currentURL(), "/offers");

click("a:contains('Make a New Donation')");

andThen(function(){
assert.equal(currentURL(), '/offers/5');
andThen(function() {
assert.equal(currentURL(), "/offers/5");

//test: item count zero
assert.equal($.trim(find('.tab-bar-section .title').text()), "Offer items (0)");
assert.equal(
$.trim(find(".tab-bar-section .title").text()),
"Offer items (0)"
);

//test: no items message
assert.equal($.trim(find('.no-items').text()), "You don't have any items in this offer yet. Please add your first item!");
assert.equal(
$.trim(find(".no-items").text()),
"You don't have any items in this offer yet. Please add your first item!"
);
});
});
});
61 changes: 33 additions & 28 deletions tests/acceptance/login-test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
import Ember from 'ember';
import startApp from '../helpers/start-app';
import FactoryGuy from 'ember-data-factory-guy';
import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import '../factories/user_profile';
import { module, test } from 'qunit';
import Ember from "ember";
import startApp from "../helpers/start-app";
import FactoryGuy from "ember-data-factory-guy";
import TestHelper from "ember-data-factory-guy/factory-guy-test-helper";
import "../factories/user_profile";
import { module, test } from "qunit";

var App, hk_user, non_hk_user;

module('Acceptance: Login', {
module("Acceptance: Login", {
beforeEach: function() {
App = startApp();
TestHelper.setup();

hk_user = FactoryGuy.make('with_hk_mobile');
non_hk_user = FactoryGuy.make('with_non_hk_mobile');
hk_user = FactoryGuy.make("with_hk_mobile");
non_hk_user = FactoryGuy.make("with_non_hk_mobile");

App.__container__.lookup("controller:subscriptions").pusher = {
get: function() { return {}; },
get: function() {
return {};
},
wire: function() {}
};
},
afterEach: function() {
Ember.run(function () { TestHelper.teardown(); });
Ember.run(App, 'destroy');
Ember.run(function() {
TestHelper.teardown();
});
Ember.run(App, "destroy");
}
});

test("User able to enter mobile number and get the sms code", function(assert) {
assert.expect(1);

visit("/login");
andThen(function() {
var ele_logout = $("a:contains('Logout')");
if(ele_logout.length > 0){
if (ele_logout.length > 0) {
click(ele_logout[0]);
}
});

andThen(function() {
fillIn('#mobile', hk_user.get("mobile"));
triggerEvent('#mobile', 'blur');
fillIn("#mobile", hk_user.get("mobile"));
triggerEvent("#mobile", "blur");
click("#getsmscode");
});

Expand All @@ -55,24 +58,24 @@ test("User is able to enter sms code and confirm and redirected to offers", func
visit("/authenticate");
andThen(function() {
var ele_logout = $("a:contains('Logout')");
if(ele_logout.length > 0){
if (ele_logout.length > 0) {
click(ele_logout[0]);
}
});

andThen(function() {
visit('/authenticate');
fillIn('#pin', "1234");
triggerEvent('#pin', 'blur');
visit("/authenticate");
fillIn("#pin", "1234");
triggerEvent("#pin", "blur");
});

andThen(function() {
assert.equal(find('#pin').val().length, 4);
assert.equal(find("#pin").val().length, 4);
window.localStorage.authToken = authToken;
click("#submit_pin");
});

andThen(function(){
andThen(function() {
assert.equal(currentURL(), "/offers");
});
});
Expand All @@ -90,25 +93,27 @@ test("Logout clears authToken", function(assert) {
test("User is able to resend the sms code", function(assert) {
assert.expect(1);

$.mockjax({url:"/api/v1/auth/send_pi*",responseText:{
"otp_auth_key" : "/JqONEgEjrZefDV3ZIQsNA=="
}});
$.mockjax({
url: "/api/v1/auth/send_pi*",
responseText: {
otp_auth_key: "/JqONEgEjrZefDV3ZIQsNA=="
}
});

visit("/authenticate");
andThen(function() {
var ele_logout = $("a:contains('Logout')");
if(ele_logout.length > 0){
if (ele_logout.length > 0) {
click(ele_logout[0]);
}
});

andThen(function() {
visit('/authenticate');
visit("/authenticate");
click("#resend-pin");
});

andThen(function() {
assert.equal(window.localStorage.otpAuthKey, '"/JqONEgEjrZefDV3ZIQsNA=="');
});

});
Loading

0 comments on commit 178f477

Please sign in to comment.