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

🍰 2119-Fix Contribution consistent form input validation #2160

Merged
merged 21 commits into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion cypress/integration/common/steps.js
Expand Up @@ -5,9 +5,12 @@ import {
} from "cypress-cucumber-preprocessor/steps";
import helpers from "../../support/helpers";
import { VERSION } from '../../constants/terms-and-conditions-version.js'
import locales from '../../../webapp/locales'
import orderBy from 'lodash/orderBy'

/* global cy */

const languages = orderBy(locales, 'name')
let lastPost = {};

let loginCredentials = {
Expand Down Expand Up @@ -245,6 +248,12 @@ Then("I select a category", () => {
.click();
});

When("I choose {string} as the language for the post", (languageCode) => {
cy.get('.ds-flex-item > .ds-form-item .ds-select ')
.click().get('.ds-select-option')
.eq(languages.findIndex(l => l.code === languageCode)).click()
})

Then("the post shows up on the landing page at position {int}", index => {
cy.openPage("landing");
const selector = `.post-card:nth-child(${index}) > .ds-card-content`;
Expand Down Expand Up @@ -536,4 +545,4 @@ Then("I see only one post with the title {string}", title => {
.find(".post-link")
.should("have.length", 1);
cy.get(".main-container").contains(".post-link", title);
});
});
1 change: 1 addition & 0 deletions cypress/integration/notifications/Mentions.feature
Expand Up @@ -20,6 +20,7 @@ Feature: Notification for a mention
"""
And mention "@matt-rider" in the text
And I select a category
And I choose "en" as the language for the post
And I click on "Save"
When I log out
And I log in with the following credentials:
Expand Down
3 changes: 2 additions & 1 deletion cypress/integration/post/WritePost.feature
Expand Up @@ -17,7 +17,8 @@ Feature: Create a post
Human Connection is a free and open-source social network
for active citizenship.
"""
Then I select a category
And I select a category
And I choose "en" as the language for the post
And I click on "Save"
Then I get redirected to ".../my-first-post"
And the post was saved successfully
Expand Down
13 changes: 10 additions & 3 deletions webapp/components/CategoriesSelect/CategoriesSelect.spec.js
Expand Up @@ -8,10 +8,12 @@ localVue.use(Styleguide)
describe('CategoriesSelect.vue', () => {
let wrapper
let mocks
let provide
let democracyAndPolitics
let environmentAndNature
let consumptionAndSustainablity

const propsData = { model: 'categoryIds' }
const categories = [
{
id: 'cat9',
Expand All @@ -35,14 +37,19 @@ describe('CategoriesSelect.vue', () => {
},
]
beforeEach(() => {
provide = {
$parentForm: {
update: jest.fn(),
},
}
mocks = {
$t: jest.fn(),
}
})

describe('shallowMount', () => {
const Wrapper = () => {
return mount(CategoriesSelect, { mocks, localVue })
return mount(CategoriesSelect, { propsData, mocks, localVue, provide })
}

beforeEach(() => {
Expand All @@ -60,8 +67,8 @@ describe('CategoriesSelect.vue', () => {
expect(wrapper.vm.selectedCategoryIds).toEqual([categories[0].id])
})

it('emits an updateCategories event when the selectedCategoryIds changes', () => {
expect(wrapper.emitted().updateCategories[0][0]).toEqual([categories[0].id])
it('calls $parent.update with selected category ids', () => {
expect(provide.$parentForm.update).toHaveBeenCalledWith('categoryIds', ['cat9'])
})

it('removes categories when clicked a second time', () => {
Expand Down
41 changes: 16 additions & 25 deletions webapp/components/CategoriesSelect/CategoriesSelect.vue
Expand Up @@ -5,6 +5,7 @@
<ds-flex-item>
<ds-button
size="small"
:data-test="categoryButtonsId(category.id)"
@click.prevent="toggleCategory(category.id)"
:primary="isActive(category.id)"
:disabled="isDisabled(category.id)"
Expand All @@ -28,16 +29,23 @@

<script>
import CategoryQuery from '~/graphql/CategoryQuery'
import xor from 'lodash/xor'

export default {
inject: {
$parentForm: {
default: null,
},
},
props: {
existingCategoryIds: { type: Array, default: () => [] },
model: { type: String, required: true },
},
data() {
return {
categories: null,
selectedMax: 3,
selectedCategoryIds: [],
selectedCategoryIds: this.existingCategoryIds,
}
},
computed: {
Expand All @@ -48,39 +56,22 @@ export default {
return this.selectedCount >= this.selectedMax
},
},
watch: {
selectedCategoryIds(categoryIds) {
this.$emit('updateCategories', categoryIds)
},
existingCategoryIds: {
immediate: true,
handler: function(existingCategoryIds) {
if (!existingCategoryIds || !existingCategoryIds.length) {
return
}
this.selectedCategoryIds = existingCategoryIds
},
},
},
methods: {
toggleCategory(id) {
const index = this.selectedCategoryIds.indexOf(id)
if (index > -1) {
this.selectedCategoryIds.splice(index, 1)
} else {
this.selectedCategoryIds.push(id)
this.selectedCategoryIds = xor(this.selectedCategoryIds, [id])
if (this.$parentForm) {
this.$parentForm.update(this.model, this.selectedCategoryIds)
}
},
isActive(id) {
const index = this.selectedCategoryIds.indexOf(id)
if (index > -1) {
return true
}
return false
return this.selectedCategoryIds.includes(id)
},
isDisabled(id) {
return !!(this.reachedMaximum && !this.isActive(id))
},
categoryButtonsId(categoryId) {
return `category-buttons-${categoryId}`
},
},
apollo: {
Category: {
Expand Down