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

54 test to delete action #56

Merged
merged 5 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/Actions/Delete/Delete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
<div>
<v-tooltip bottom>
<v-btn
:name="`${UI_NAMES.RESOURCE_DELETE_BUTTON.with({ resourceName: this.resourceName })}`"
@click="onDelete()"
slot="activator"
icon>
<i class="v-icon material-icons">delete</i>
<i class="v-icon material-icons">
{{UI_CONTENT.RESOURCE_DELETE_BUTTON}}
</i>
</v-btn>
<span>Delete</span>
</v-tooltip>
</div>
</template>

<script>
import UI_CONTENT from '@constants/ui.content.default'
import UI_NAMES from '@constants/ui.element.names'

export default {
name: "Delete",

Expand All @@ -31,7 +37,10 @@ export default {
},

data() {
return {}
return {
UI_CONTENT,
UI_NAMES
}
},

methods: {
Expand Down
8 changes: 5 additions & 3 deletions src/components/Actions/EditButton/EditButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-tooltip
bottom>
<v-btn
:name="`${name}`"
:name="`${UI_NAMES.RESOURCE_EDIT_BUTTON.with({ resourceName: this.resourceName })}`"
@click="onEdit()"
slot="activator"
icon>
Expand All @@ -17,7 +17,8 @@
</template>

<script>
import UI_CONTENT from '../../../constants/ui.content.default'
import UI_CONTENT from '@constants/ui.content.default'
import UI_NAMES from '@constants/ui.element.names'

export default {
name: "EditButton",
Expand All @@ -36,7 +37,8 @@ export default {
},
data() {
return {
UI_CONTENT
UI_CONTENT,
UI_NAMES
}
},
methods: {
Expand Down
5 changes: 0 additions & 5 deletions src/components/Actions/Show/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<v-card :name="`${UI_NAMES.RESOURCE_VIEW_CONTAINER.with({ resourceName, view })}`">
<div class="text-xs-center d-flex right" :name="`${UI_NAMES.RESOURCE_VIEW_ACTIONS_CONTAINER.with({ resourceName, view })}`">
<EditButton
:name="editButtonName()"
:resourceId="$route.params.id"
:resourceName="name">
</EditButton>
Expand Down Expand Up @@ -107,10 +106,6 @@ export default {

componentName(field) {
return UI_NAMES.RESOURCE_VIEW_CONTAINER_FIELD.with({ resourceName: this.resourceName, view: this.view, field: this.label(field) })
},

editButtonName() {
return UI_NAMES.RESOURCE_ID_EDIT_BUTTON.with({ resourceName: this.resourceName })
}
},

Expand Down
5 changes: 4 additions & 1 deletion src/constants/ui.content.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export default {
// Create action button
RESOURCE_CREATE_BUTTON: 'add',

// Create action button
// Edit action button
RESOURCE_EDIT_BUTTON: 'edit',

// Delete action button
RESOURCE_DELETE_BUTTON: 'delete',

// Create Save button
CREATE_SUBMIT_BUTTON: 'save',

Expand Down
14 changes: 9 additions & 5 deletions src/constants/ui.element.names.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ export default {
with: ({ resourceName }) => `${resourceName}-create-button`
},
// The button that redirects to a Edit view
RESOURCE_ID_EDIT_BUTTON: {
with: ({ resourceName, index }) => {
return index !== undefined
? `${resourceName}-edit-button-${index}`
: `${resourceName}-edit-button`
RESOURCE_EDIT_BUTTON: {
with: ({ resourceName }) => {
return `${resourceName}-edit-button`
}
},
// A specific container of a Resource field inside an element of List
Expand All @@ -58,5 +56,11 @@ export default {
// The form submit buttons
RESOURCE_VIEW_SUBMIT_BUTTON: {
with: ({ resourceName, view }) => `${resourceName}-${view}-submit-button`
},

RESOURCE_DELETE_BUTTON: {
with: ({ resourceName }) => {
return `${resourceName}-delete-button`
}
}
}
39 changes: 39 additions & 0 deletions tests/e2e/specs/articles/delete.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// https://docs.cypress.io/api/introduction/api.html

const Factory = require('../../factory')
const { queryElementByProp } = require('../../helpers')


const UI_NAMES = require('../../../../src/constants/ui.element.names')
const UI_CONTENT = require('../../../../src/constants/ui.content.default')

describe('Articles: Delete Test', () => {
let article = {}

before('Search the Show view url', () => {
const url = Factory.apiUrl({ route: 'api/articles/' })
cy.request('POST',url , Factory.createArticle())
.then((res) => { article = res.body })
cy.visit('/#/articles')
cy.wait(2000)
})

before('Visits the Show view url', () => {
const url = `articles/show/${article.id}`
cy.visit(`/#/${url}`)
cy.url().should('include', url)
})

it('Press the delete button in the Show view', () => {
const deleteButtonElement = cy.getElement({
constant: UI_NAMES.RESOURCE_DELETE_BUTTON,
constantParams: { resourceName: 'articles' },
elementType: 'button',
elementProp: 'name',
})

deleteButtonElement.should((deleteButton) => {
expect(deleteButton).to.contain(UI_CONTENT.RESOURCE_DELETE_BUTTON)
}).click()
})
})
4 changes: 2 additions & 2 deletions tests/e2e/specs/articles/edit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Articles: Edit Test', () => {
})

before('Click in the Edit button of the Show view', () => {
const editButtonName = UI_NAMES.RESOURCE_ID_EDIT_BUTTON.with({
const editButtonName = UI_NAMES.RESOURCE_EDIT_BUTTON.with({
resourceName: 'articles'
})
const editButtonElement = queryElementByProp({
Expand All @@ -42,7 +42,7 @@ describe('Articles: Edit Test', () => {
}).click()
})

it('Articles Show Edit should render title: Articles', () => {
it('Articles Edit should render title: Articles', () => {
cy.get(editViewDivContainerQuery('RESOURCE_VIEW_CONTAINER')).should((editViewContainer) => {
const editViewTitleContainer = editViewContainer.find(editViewDivContainerQuery('RESOURCE_VIEW_CONTAINER_TITLE'))
const editViewTitleText = UI_CONTENT.RESOURCE_VIEW_TITLE.with({
Expand Down