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 6b945e0
Showing 1 changed file with 53 additions and 42 deletions.
95 changes: 53 additions & 42 deletions frontend/cypress/integration/actions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ 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)
Expand Down Expand Up @@ -70,17 +70,17 @@ describe('Actions management', () => {
)
})

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,9 +298,6 @@ 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)),
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 }),
typeName: 'ClosingRemark',
})

return { updatedAction, newNote }
}

0 comments on commit 6b945e0

Please sign in to comment.