Skip to content

Commit

Permalink
Changes after review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
petterwildhagen committed Sep 7, 2021
1 parent 527d853 commit 347a6bb
Showing 1 changed file with 64 additions and 53 deletions.
117 changes: 64 additions & 53 deletions frontend/cypress/integration/actions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,58 @@ describe('Actions management', () => {
return user
}

describe('Creating, Editing & Viewing Actions', () => {
beforeEach(() => {
seed = createSeedWithActions(users, { completed: false })
seed.plant()
})
beforeEach(() => {
seed = createSeedWithActions(users, { completed: false })
seed.plant()
})
context('Creating and editing actions', () => {
it('Action can be created', () => {
logInSomeRandomUser()
let actionTestData = createActionTestData(users)
actionsGrid.addActionButton(actionTestData.questionOrder).click()
createActionDialog.titleInput().type(actionTestData.title)
let action = createActionTestData(users)
actionsGrid.addActionButton(action.questionOrder).click()
createActionDialog.titleInput().type(action.title)
createActionDialog.assignedToInput().click()
dropdownSelect.assertSelectValues(
seed.participants.map(p => {
return p.user.name
})
)
dropdownSelect.select(createActionDialog.assignedToInput(), actionTestData.assignedTo.user.name)
createActionDialog.dueDateInput().replace(actionTestData.dueDate.toLocaleDateString(FUSION_DATE_LOCALE))
dropdownSelect.select(createActionDialog.assignedToInput(), action.assignedTo.user.name)
createActionDialog.dueDateInput().replace(action.dueDate.toLocaleDateString(FUSION_DATE_LOCALE))
createActionDialog.priorityInput().click()
dropdownSelect.assertSelectValues(
Object.values(Priority).map(p => {
return mapPriority(p)
})
)
dropdownSelect.select(createActionDialog.priorityInput(), mapPriority(actionTestData.priority))
dropdownSelect.select(createActionDialog.priorityInput(), mapPriority(action.priority))
createActionDialog.body().contains(`Connected to ${seed.name}`).should('exist')
createActionDialog.descriptionInput().type(actionTestData.description)
createActionDialog.descriptionInput().type(action.description)

createActionDialog.createButton().click()
cy.testCacheAndDB(
() => {
createActionDialog.body().should('not.exist')
actionsGrid.actionLink(actionTestData.questionOrder, actionTestData.title).should('exist')
actionsGrid.actionLink(action.questionOrder, action.title).should('exist')
},
() => {
evaluationPage.progressionStepLink(faker.random.arrayElement([Progression.Workshop, Progression.FollowUp])).click()
actionsGrid.actionLink(actionTestData.questionOrder, actionTestData.title).should('exist')
actionsGrid.actionLink(action.questionOrder, action.title).should('exist')
}
)
})

let notesOfSomeAction: Note[]
let someAction: Action
let actionNotes: Note[]
let action: Action
let updatedAction: Action
let newNotes: Note[]

it('Action can be edited', () => {
let user = logInSomeRandomUser()
;({ notesOfSomeAction, someAction } = findActionWithNotes(seed))
actionsGrid.actionLink(someAction.questionOrder, someAction.title).click()
editActionDialog.assertActionValues(someAction, notesOfSomeAction)
;({ updatedAction, newNotes } = createEditTestData(seed, user, someAction))
;({ notesOfSomeAction: actionNotes, someAction: action } = findActionWithNotes(seed))
actionsGrid.actionLink(action.questionOrder, action.title).click()
editActionDialog.assertActionValues(action, actionNotes)
;({ updatedAction, newNotes } = createEditTestData(seed, user, action))
editActionDialog.titleInput().replace(updatedAction.title)
dropdownSelect.select(editActionDialog.assignedToInput(), updatedAction.assignedTo.user.name)
editActionDialog.dueDateInput().replace(updatedAction.dueDate.toLocaleDateString(FUSION_DATE_LOCALE))
Expand All @@ -95,22 +95,24 @@ describe('Actions management', () => {
editActionDialog.close()
cy.testCacheAndDB(() => {
evaluationPage.progressionStepLink(faker.random.arrayElement([Progression.Workshop, Progression.FollowUp])).click()
actionsGrid.actionLink(someAction.questionOrder, updatedAction.title).click()
editActionDialog.assertActionValues(updatedAction, notesOfSomeAction.concat(newNotes))
actionsGrid.actionLink(action.questionOrder, updatedAction.title).click()
editActionDialog.assertActionValues(updatedAction, actionNotes.concat(newNotes))
})
})
const deleteActionFrom = faker.random.arrayElement([Progression.Workshop, Progression.FollowUp])

})
context('Deleting Actions', () => {
const deleteAction = (actionToDelete: Action) => {
actionsGrid.deleteActionButton(actionToDelete.id).click()
confirmationDialog.yesButton().click()
}
const deleteActionFrom = faker.random.arrayElement([Progression.Workshop, Progression.FollowUp])

it('Action can be deleted', () => {
logInSomeRandomUser()
let actions = findSomeActions(seed, 2)
let actionToDelete = actions[0]
let actionToStay = actions[1]
let actionToDelete: Action
let actionToStay: Action
;({ actionToDelete, actionToStay } = getActionToDeleteActionToStay())
deleteAction(actionToDelete)
cy.testCacheAndDB(() => {
evaluationPage.progressionStepLink(deleteActionFrom).click()
Expand All @@ -119,11 +121,18 @@ describe('Actions management', () => {
})
})

it('Action delete may be canceled', () => {
logInSomeRandomUser()
let actions = findSomeActions(seed, 2)
const getActionToDeleteActionToStay = () => {
let actions = faker.random.arrayElements(seed.actions, 2)
let actionToDelete = actions[0]
let actionToStay = actions[1]
return { actionToDelete, actionToStay }
}

it('Action delete may be canceled', () => {
logInSomeRandomUser()
let actionToDelete: Action
let actionToStay: Action
;({ actionToDelete, actionToStay } = getActionToDeleteActionToStay())
actionsGrid.deleteActionButton(actionToDelete.id).click()
confirmationDialog.noButton().click()

Expand All @@ -136,9 +145,9 @@ describe('Actions management', () => {

it('Deleted action can not be deleted again', () => {
logInSomeRandomUser()
let actions = findSomeActions(seed, 2)
let actionToDelete = actions[0]
let actionToStay = actions[1]
let actionToDelete: Action
let actionToStay: Action
;({ actionToDelete, actionToStay } = getActionToDeleteActionToStay())
cy.gql(DELETE_ACTION, {
variables: {
actionId: actionToDelete.id,
Expand Down Expand Up @@ -167,7 +176,9 @@ describe('Actions management', () => {
)
})
})
})

context('Viewing actions', () => {
function getQuestion(action: Action) {
return seed.questions.find(q => q.id === seed.findQuestionId(action.questionOrder))!
}
Expand Down Expand Up @@ -203,7 +214,8 @@ describe('Actions management', () => {
actionsTab.assertActionValues(a, question!)
})
})

})
context('Completing actions', () => {
let newNote: Note

function checkView() {
Expand Down Expand Up @@ -237,38 +249,42 @@ describe('Actions management', () => {
})
}

let actionNotes: Note[]
let action: Action
let updatedAction: Action

it('Action can be completed without writing a reason', () => {
let user = logInSomeRandomUser(Progression.FollowUp)
;({ notesOfSomeAction, someAction } = findActionWithNotes(seed))
;({ updatedAction, newNote } = createCompleteActionData(user, someAction))
actionsGrid.actionLink(someAction.questionOrder, someAction.title).click()
;({ notesOfSomeAction: actionNotes, someAction: action } = findActionWithNotes(seed))
;({ updatedAction, newNote } = createCompleteAction(user, action))
actionsGrid.actionLink(action.questionOrder, action.title).click()
checkView()
openConfirmCompleteView()
confirmAndCheckCompleted()
testCacheInReopenedActionView(updatedAction, notesOfSomeAction.concat(newNote))
testCacheInReopenedActionView(updatedAction, actionNotes.concat(newNote))
})

it('Action can be completed with a reason', () => {
let user = logInSomeRandomUser(Progression.FollowUp)
;({ notesOfSomeAction, someAction } = findActionWithNotes(seed))
;({ updatedAction, newNote } = createCompleteActionData(user, someAction))
actionsGrid.actionLink(someAction.questionOrder, someAction.title).click()
;({ notesOfSomeAction: actionNotes, someAction: action } = findActionWithNotes(seed))
;({ updatedAction, newNote } = createCompleteAction(user, action))
actionsGrid.actionLink(action.questionOrder, action.title).click()
checkView()
openConfirmCompleteView()
editActionDialog.completedReasonInput().replace('Closed because of a good reason')
confirmAndCheckCompleted()
testCacheInReopenedActionView(updatedAction, notesOfSomeAction.concat(newNote))
testCacheInReopenedActionView(updatedAction, actionNotes.concat(newNote))
})

it('Completing Action can be cancelled', () => {
logInSomeRandomUser(Progression.FollowUp)
;({ notesOfSomeAction, someAction } = findActionWithNotes(seed))
actionsGrid.actionLink(someAction.questionOrder, someAction.title).click()
;({ notesOfSomeAction: actionNotes, someAction: action } = findActionWithNotes(seed))
actionsGrid.actionLink(action.questionOrder, action.title).click()
checkView()
openConfirmCompleteView()
editActionDialog.completeActionCancelButton().click()
checkView()
editActionDialog.assertNoClosingMessageInNotes(notesOfSomeAction)
editActionDialog.assertNoClosingMessageInNotes(actionNotes)
})
})
})
Expand All @@ -282,13 +298,10 @@ const findActionWithNotes = (seed: EvaluationSeed) => {
return { notesOfSomeAction, someAction }
}

const findSomeActions = (seed: EvaluationSeed, no: number = 1) => {
return faker.random.arrayElements(seed.actions, no)
}
const createSeedWithActions = (users: User[], actionParameters: Partial<Action>) => {
const seed = new EvaluationSeed({
progression: faker.random.arrayElement(Object.values(Progression)),
users: users,
users,
})

const oneAction = seed.createAction({
Expand Down Expand Up @@ -341,22 +354,20 @@ const createEditTestData = (seed: EvaluationSeed, user: User, existingAction: Ac
return new Note({
text: faker.lorem.words(),
action: updatedAction,
createdBy: new Participant({ user: user }),
createdBy: new Participant({ user }),
})
})

return { updatedAction, newNotes }
}

const createCompleteActionData = (user: User, existingAction: Action) => {
const createCompleteAction = (user: User, existingAction: Action) => {
const updatedAction = { ...existingAction, completed: true }

const newNote = new Note({
text: '',
action: updatedAction,
createdBy: new Participant({ user: user }),
createdBy: new Participant({ user }),
typeName: 'ClosingRemark',
})

return { updatedAction, newNote }
}

0 comments on commit 347a6bb

Please sign in to comment.