Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jeremy/GITC-565/fix Twitter handle feature #9661

Merged
merged 16 commits into from
Nov 5, 2021
16 changes: 12 additions & 4 deletions app/assets/v2/js/grants/_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ Vue.mixin({
if (!vm.form.twitter_handle_1.length) {
vm.$set(vm.errors, 'twitter_handle_1', 'Please enter twitter handle of your project');
}
if (vm.form.twitter_handle_1 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.form.twitter_handle_1)) {
if (vm.form.twitter_handle_1 && !(/^@?[a-zA-Z0-9_]{4,15}$/).test(vm.form.twitter_handle_1)) {
vm.$set(vm.errors, 'twitter_handle_1', 'Please enter a valid twitter handle of your project e.g @humanfund');
}
if (vm.form.twitter_handle_2 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.form.twitter_handle_2)) {
if (vm.form.twitter_handle_2 && !(/^@?[a-zA-Z0-9_]{4,15}$/).test(vm.form.twitter_handle_2)) {
vm.$set(vm.errors, 'twitter_handle_2', 'Please enter your twitter handle e.g @georgecostanza');
}

Expand Down Expand Up @@ -277,7 +277,15 @@ Vue.mixin({
_alert(err.message, 'danger');
}
});
}
},
handleTwitterUsername(event) {
const inputField = event.target;
const matchResult = inputField.value.match(/https:\/\/twitter.com\/(\w{4,15})/);

const extracted = matchResult ? `@${matchResult[1]}` : inputField.value;

this.$set(this.form, inputField.id, extracted);
},
},
watch: {
deep: true,
Expand Down Expand Up @@ -378,7 +386,7 @@ if (document.getElementById('gc-new-grant')) {
]
},
theme: 'snow',
placeholder: 'Give a detailed desciription about your Grant'
placeholder: 'Give a detailed description about your Grant'
}
};
},
Expand Down
4 changes: 2 additions & 2 deletions app/grants/templates/grants/_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ <h1 class="text-center font-title-xl">Create a Grant</h1>
<label class="font-caption letter-spacing text-black-60 text-uppercase" for="twitter_handle_1">Project Twitter Handle</label>
<span class="font-smaller-6 badge badge-greylight text-capitalize ml-2">Required</span>

<input id="twitter_handle_1" v-model="form.twitter_handle_1" name="twitter_handle_1" class="form__input form__input-lg" maxlength="20" type="text" placeholder="humanfund" required/>
<input id="twitter_handle_1" v-model="form.twitter_handle_1" @blur.prevent="handleTwitterUsername" name="twitter_handle_1" class="form__input form__input-lg" type="text" placeholder="humanfund" required/>

<div class="text-danger" v-if="errors.twitter_handle_1">
[[errors.twitter_handle_1]]
Expand All @@ -166,7 +166,7 @@ <h1 class="text-center font-title-xl">Create a Grant</h1>
<div class="col-12 mb-3">
<label class="font-caption letter-spacing text-black-60 text-uppercase" for="twitter_handle_2">Your Twitter Handle</label>

<input id="twitter_handle_2" v-model="form.twitter_handle_2" name="twitter_handle_2" class="form__input form__input-lg" maxlength="20" type="text" placeholder="georgecostanza"/>
<input id="twitter_handle_2" v-model="form.twitter_handle_2" @blur.prevent="handleTwitterUsername" name="twitter_handle_2" class="form__input form__input-lg" type="text" placeholder="georgecostanza"/>

<div class="text-danger" v-if="errors.twitter_handle_2">
[[errors.twitter_handle_2]]
Expand Down
13 changes: 13 additions & 0 deletions cypress/integration/grants/test_grant_creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ describe('Creating a new grant', () => {
});

describe('creation:success - required fields only', () => {
it('extracts the user\'s Twitter handle when the full Twitter URL is entered into the form', () => {
const orgTwitterURL = 'https://twitter.com/gitcoin'
const userTwitterURL = 'https://twitter.com/gitcoinbot'

cy.visit('grants/new');

cy.get('input[name=twitter_handle_1]').type(orgTwitterURL).blur();
cy.get('input[name=twitter_handle_2]').type(userTwitterURL).blur();

cy.get('input[name=twitter_handle_1]').should('have.value', '@gitcoin');
cy.get('input[name=twitter_handle_2]').should('have.value', '@gitcoinbot');
});

it('submits a grant for review', () => {
cy.visit('grants/new');

Expand Down