generated from bcgov/vue-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 2
CFFRI-6006 - Manage users component tests #822
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3e14dbd
added manage user tests
saibannur-cgi ac5d091
fixed github sonar issues
saibannur-cgi c87bf74
Merge branch 'main' into cffri-6006-test-manage-users
saibannur-cgi d8c635a
fixed failing tests from main changes
saibannur-cgi 34ef13d
added add user dialog tests
saibannur-cgi 0996a37
Merge branch 'main' into cffri-6006-test-manage-users
saibannur-cgi 4c1cefc
move manage user related tests to separate folder
saibannur-cgi 5a1eeb7
added prop passing
saibannur-cgi 205c849
added remove and edit user tests
saibannur-cgi dfb53ba
finished manage user tests
saibannur-cgi b42c9fa
fix sonar issues
saibannur-cgi 94f104a
remove redundant code
saibannur-cgi 143c6fe
pr requested changes
saibannur-cgi d4911b7
fixed typo
saibannur-cgi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
frontend/tests/cypress/component/accountMgmt/AddUserDialog.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import AddUserDialog from '@/components/accountMgmt/AddUserDialog.vue'; | ||
import vuetify from '@/plugins/vuetify'; | ||
import { ApiRoutes } from '@/utils/constants.js'; | ||
|
||
function mountWithPinia(initialState = {}, dataOverride = {}) { | ||
cy.setupPinia({ initialState, stubActions: false }).then((pinia) => { | ||
const pushStub = cy.stub(); | ||
cy.mount(AddUserDialog, { | ||
global: { | ||
plugins: [pinia, vuetify], | ||
}, | ||
data() { | ||
return { | ||
...dataOverride, | ||
}; | ||
}, | ||
}); | ||
cy.wrap(pushStub).as('routerPush'); | ||
}); | ||
} | ||
|
||
describe('<AddUserDialog />', () => { | ||
beforeEach(() => { | ||
cy.viewport(1020, 1000); | ||
}); | ||
|
||
context('Step One', () => { | ||
it('should render step one', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('p', 'What type of user are you adding?'); | ||
}); | ||
|
||
it('should render portal user options', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('p', 'What level of portal access should this user have?'); | ||
}); | ||
|
||
it('should not render admin options for read only portal user', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('p', 'Which facilities should this user have access to?').should('not.be.visible'); | ||
}); | ||
|
||
it('should render cancel button', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('button', 'Cancel'); | ||
}); | ||
|
||
it('should not render back button', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('button', 'Back').should('not.exist'); | ||
}); | ||
}); | ||
|
||
context('Step Two', () => { | ||
it('should render next button and navigate to step two', () => { | ||
mountWithPinia({}, { dialog: true }); | ||
cy.contains('button', 'Next').click(); | ||
cy.contains('p', 'What type of user are you adding?').should('not.be.visible'); | ||
}); | ||
|
||
it('should disable `Add` button when inputs are blank', () => { | ||
const userFields = { | ||
firstName: '', | ||
lastName: '', | ||
email: '', | ||
telephone: '', | ||
bceid: '', | ||
}; | ||
mountWithPinia({}, { dialog: true, userFields }); | ||
cy.contains('button', 'Next').click(); | ||
cy.contains('button', 'Add').should('have.css', 'pointer-events', 'none'); | ||
}); | ||
|
||
it('should disable `Add` button when some are blank', () => { | ||
const userFields = { | ||
firstName: 'John', | ||
lastName: '', | ||
email: '', | ||
telephone: '', | ||
bceid: '1001', | ||
}; | ||
mountWithPinia({}, { dialog: true, userFields }); | ||
cy.contains('button', 'Next').click(); | ||
cy.contains('button', 'Add').should('have.css', 'pointer-events', 'none'); | ||
}); | ||
|
||
it('should call addUser method when `Add` button is clicked', () => { | ||
cy.intercept('POST', `${ApiRoutes.CONTACTS}`, { | ||
statusCode: 200, | ||
}).as('addUserRequest'); | ||
|
||
const userFields = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: 'john.doe@test.com', | ||
telephone: '250-999-9999', | ||
bceid: '1001', | ||
}; | ||
|
||
mountWithPinia({}, { dialog: true, userFields }); | ||
|
||
cy.spy(AddUserDialog.methods, 'addUser').as('addUserSpy'); | ||
|
||
cy.contains('button', 'Next').click(); | ||
cy.contains('button', 'Add').click(); | ||
|
||
cy.get('@addUserSpy').should('have.been.calledOnce'); | ||
cy.wait('@addUserRequest').its('request').should('have.property', 'method', 'POST'); | ||
cy.contains('p', 'User Added Successfully'); | ||
cy.contains('button', 'Return to Manage Users').click(); | ||
cy.contains('p', 'User Added Successfully').should('not.be.visible'); | ||
}); | ||
}); | ||
}); |
178 changes: 178 additions & 0 deletions
178
frontend/tests/cypress/component/accountMgmt/EditUserDialog.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import EditUserDialog from '@/components/accountMgmt/EditUserDialog.vue'; | ||
import vuetify from '@/plugins/vuetify'; | ||
import { useAuthStore } from '@/store/auth'; | ||
import { ApiRoutes, ROLES } from '@/utils/constants.js'; | ||
import { PERMISSIONS } from '@/utils/constants/permissions.js'; | ||
|
||
const organizationId = '1234'; | ||
const mockUser = { | ||
contactId: 123, | ||
firstName: 'Test', | ||
lastName: 'User', | ||
bceid: 'testuser', | ||
email: 'test@example.com', | ||
telephone: '123-456-7890', | ||
role: { roleNumber: 1 }, | ||
facilities: [], | ||
}; | ||
const adminUser = { | ||
contactId: 123, | ||
firstName: 'Test', | ||
lastName: 'User', | ||
bceid: 'testuser', | ||
email: 'test@example.com', | ||
telephone: '123-456-7890', | ||
role: { roleNumber: ROLES.FAC_ADMIN_ADVANCED }, | ||
facilities: [], | ||
}; | ||
const facilityResponse = [ | ||
{ | ||
facilityName: 'Test-Facility1', | ||
facilityId: '777', | ||
}, | ||
{ | ||
facilityName: 'Test-Facility2', | ||
facilityId: '888', | ||
}, | ||
{ | ||
facilityName: 'Test-Facility3', | ||
facilityId: '999', | ||
}, | ||
]; | ||
|
||
function mountWithPinia(user, initialState = {}) { | ||
cy.setupPinia({ initialState, stubActions: false }).then((pinia) => { | ||
const pushStub = cy.stub(); | ||
const onContactUpdated = cy.spy().as('contactUpdatedSpy'); | ||
const onCloseEditDialog = cy.spy().as('closeEditDialogSpy'); | ||
|
||
cy.mount(EditUserDialog, { | ||
global: { | ||
plugins: [pinia, vuetify], | ||
}, | ||
data() { | ||
return { | ||
dialogOpen: true, | ||
}; | ||
}, | ||
attrs: { | ||
'onContact-updated': onContactUpdated, | ||
'onClose-edit-dialog': onCloseEditDialog, | ||
}, | ||
props: { | ||
user: user ?? mockUser, | ||
}, | ||
}).then(({ component }) => { | ||
component.loadEditUserData(); | ||
}); | ||
|
||
cy.wrap(pushStub).as('routerPush'); | ||
}); | ||
} | ||
|
||
describe('<EditUserDialog />', () => { | ||
beforeEach(() => { | ||
globalThis.localStorage.setItem('jwtToken', 'mocked-jwt-token'); | ||
cy.viewport(1200, 1500); | ||
}); | ||
|
||
afterEach(() => { | ||
globalThis.localStorage.removeItem('jwtToken'); | ||
}); | ||
|
||
it('should mount the dialog and display inputs for user without edit permissions', () => { | ||
mountWithPinia(); | ||
cy.contains('h3', 'Edit User'); | ||
|
||
cy.get('form input').should('have.length', 5); | ||
|
||
cy.get('form input').eq(0).prev('label').should('have.text', 'First Name'); | ||
cy.get('form input').eq(1).prev('label').should('have.text', 'Last Name'); | ||
cy.get('form input').eq(2).prev('label').should('have.text', 'Business BCeID'); | ||
cy.get('form input').eq(3).prev('label').should('have.text', 'Phone Number'); | ||
cy.get('form input').eq(4).prev('label').should('have.text', 'Email Address'); | ||
}); | ||
|
||
it('should load the users prior data', () => { | ||
mountWithPinia(); | ||
cy.get('form input').eq(0).should('have.value', mockUser.firstName); | ||
cy.get('form input').eq(1).should('have.value', mockUser.lastName); | ||
cy.get('form input').eq(2).should('have.value', mockUser.bceid).shou; | ||
cy.get('form input').eq(3).should('have.value', mockUser.telephone); | ||
cy.get('form input').eq(4).should('have.value', mockUser.email); | ||
}); | ||
|
||
it('should disable bceid input', () => { | ||
mountWithPinia(); | ||
cy.get('form input').eq(2).should('have.value', mockUser.bceid).should('have.css', 'pointer-events', 'none'); | ||
}); | ||
|
||
it('should render user role input for users with edit permission', () => { | ||
mountWithPinia(null, { | ||
auth: { | ||
isAuthenticated: true, | ||
userInfo: { | ||
serverTime: new Date(), | ||
}, | ||
}, | ||
}); | ||
|
||
cy.then(() => { | ||
const authStore = useAuthStore(); | ||
authStore.permissions = [PERMISSIONS.EDIT_USERS]; | ||
}); | ||
|
||
cy.contains('label', 'User Role'); | ||
cy.get('form input').eq(5).should('have.value', mockUser.role.roleNumber); | ||
}); | ||
|
||
it('should render facilities options', () => { | ||
cy.intercept('GET', `${ApiRoutes.ORGANIZATION}/${organizationId}/facilities`, { | ||
statusCode: 200, | ||
body: facilityResponse, | ||
}); | ||
|
||
mountWithPinia(adminUser, { | ||
auth: { | ||
isAuthenticated: true, | ||
userInfo: { | ||
serverTime: new Date(), | ||
}, | ||
}, | ||
organization: { | ||
organizationId, | ||
}, | ||
}); | ||
|
||
cy.then(() => { | ||
const authStore = useAuthStore(); | ||
authStore.permissions = [PERMISSIONS.EDIT_USERS]; | ||
}); | ||
|
||
cy.contains('label', 'Facilities'); | ||
}); | ||
|
||
it('should update user on clicking `Update` button', () => { | ||
cy.intercept('PATCH', `${ApiRoutes.CONTACTS}/${mockUser.contactId}`, { | ||
statusCode: 200, | ||
body: {}, | ||
}); | ||
|
||
mountWithPinia(); | ||
|
||
cy.contains('button', 'Update').click(); | ||
cy.get('@contactUpdatedSpy').should('have.been.calledOnce'); | ||
}); | ||
|
||
it('should disable `Update` button when inputs are empty', () => { | ||
mountWithPinia({}, { firstName: 'John' }); | ||
cy.contains('button', 'Update').should('have.css', 'pointer-events', 'none'); | ||
}); | ||
|
||
it('should close dialog', () => { | ||
mountWithPinia(); | ||
cy.contains('button', 'Cancel').click(); | ||
cy.contains('Edit User').should('not.be.visible'); | ||
cy.get('@closeEditDialogSpy').should('have.been.calledOnce'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.