Skip to content

Commit

Permalink
FKS-1145 add menu test for different user roles
Browse files Browse the repository at this point in the history
  • Loading branch information
IngMyr committed Jan 28, 2025
1 parent 0310404 commit a45f33b
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 37 deletions.
6 changes: 5 additions & 1 deletion app/components/app-bar/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export const Menu = ({me, source}: { me: IMeInfo, basePath?: string, source?: st
<>
<ActionMenu.Group label="For tjenesteadministrator">
<ActionMenu.Item
onSelect={() => navigate(SERVICE_ADMIN)}>Ressurser</ActionMenu.Item>
onSelect={() => navigate(SERVICE_ADMIN)}
id="service-admin"
>
Ressurser
</ActionMenu.Item>
{source === "gui" &&
<ActionMenu.Item
onSelect={() => navigate(SERVICE_ADMIN_NEW_APPLICATION_RESOURCE_CREATE)}
Expand Down
68 changes: 68 additions & 0 deletions cypress/e2e/menu/menuItems.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {wait} from "@testing-library/user-event/dist/utils";


describe('Check menu items for', () => {

it('Systemadministrator', () => {
cy.setCookie('cypresstestuser', 'sa')
wait(1000)
cy.getCookie('cypresstestuser').then(cookie => expect(cookie.value).to.be.equal('sa'))

cy.goToHome();
cy.wait(1000)

cy.get("#dropdown-button").should("be.visible")

cy.get("#dropdown-button").click()
cy.get("#define-role").should("be.visible")
})

it('Ressursadministrator', () => {
cy.setCookie('cypresstestuser', 'ra')
wait(1000)
cy.getCookie('cypresstestuser').then(cookie => expect(cookie.value).to.be.equal('ra'))

cy.goToHome();
cy.wait(1000)

cy.get("#dropdown-button").should("be.visible")

cy.get("#dropdown-button").click()
cy.get("#define-role").should("not.exist")
cy.get("#resource-module-admin").should("be.visible")
})

it('Tjenesteadministrator', () => {
cy.setCookie('cypresstestuser', 'ta')
wait(1000)
cy.getCookie('cypresstestuser').then(cookie => expect(cookie.value).to.be.equal('ta'))

cy.goToHome();
cy.wait(1000)

cy.get("#dropdown-button").should("be.visible")

cy.get("#dropdown-button").click()
cy.get("#define-role").should("not.exist")
cy.get("#resource-module-admin").should("not.exist")
cy.get("#service-admin").should("be.visible")
})

it('Tildeler', () => {
cy.setCookie('cypresstestuser', 'td')
wait(1000)
cy.getCookie('cypresstestuser').then(cookie => expect(cookie.value).to.be.equal('td'))

cy.goToHome();
cy.wait(1000)

cy.get("#dropdown-button").should("be.visible")

cy.get("#dropdown-button").click()
cy.get("#define-role").should("not.exist")
cy.get("#resource-module-admin").should("not.exist")
cy.get("#service-admin").should("not.exist")
cy.get("#users").should("be.visible")

})
})
2 changes: 1 addition & 1 deletion cypress/fixtures/authenticatedUser.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"firstName": "Mock",
"firstName": "Mock Sysadmin",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
Expand Down
117 changes: 82 additions & 35 deletions cypress/mocks/handlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,88 @@ import {applicationCategoriesHandlers} from "./handlers/kodeverkHandlers";

export const handlers = [
// Common handlers
http.get('http://localhost:8062/beta/fintlabs-no/api/users/me', () => {
return HttpResponse.json(
{
"firstName": "Mock",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
"roles": [
{
"id": "pa",
"name": "Portaladmin"
},
{
"id": "l",
"name": "Leder"
},
{
"id": "sa",
"name": "Systemadministrator"
},
{
"id": "sb",
"name": "Sluttbruker"
},
{
"id": "ta",
"name": "Tjenesteadministrator"
},
{
"id": "td",
"name": "Tildeler"
}
]
}
)
http.get('http://localhost:8062/beta/fintlabs-no/api/users/me', ({cookies}) => {
if (cookies.cypresstestuser === 'ra') {
return HttpResponse.json(
{
"firstName": "Mock",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
"roles": [
{
"id": "ra",
"name": "Ressursadministrator"
}
]
}
)
} else if (cookies.cypresstestuser === 'ta') {
return HttpResponse.json(
{
"firstName": "Mock",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
"roles": [
{
"id": "ta",
"name": "Tjenesteadministrator"
}
]
}
)
} else if (cookies.cypresstestuser === 'td') {
return HttpResponse.json(
{
"firstName": "Mock",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
"roles": [
{
"id": "td",
"name": "Tildeler"
}
]
}
)
} else {
return HttpResponse.json(
{
"firstName": "Mock",
"lastName": "Name",
"mail": "[email protected]",
"organisationId": "mock.no",
"roles": [
{
"id": "pa",
"name": "Portaladmin"
},
{
"id": "l",
"name": "Leder"
},
{
"id": "sa",
"name": "Systemadministrator"
},
{
"id": "sb",
"name": "Sluttbruker"
},
{
"id": "ta",
"name": "Tjenesteadministrator"
},
{
"id": "td",
"name": "Tildeler"
}
]
}
)
}
}),

http.get('http://localhost:8060/beta/fintlabs-no/api/orgunits', () => {
Expand Down

0 comments on commit a45f33b

Please sign in to comment.