Skip to content

Commit

Permalink
Merge pull request #4675 from UniversityOfHelsinkiCS/material-ui
Browse files Browse the repository at this point in the history
Material UI: Navigation bar
  • Loading branch information
rikurauhala authored Nov 11, 2024
2 parents b4e176a + eb60d1b commit b17b119
Show file tree
Hide file tree
Showing 16 changed files with 1,380 additions and 287 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/Course_statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ describe('Course Statistics tests', () => {

it('Some features of Course Statistics are hidden for courseStatistics-users without other rights', () => {
cy.init('/coursestatistics', 'onlycoursestatistics')
cy.get('[data-cy=navbar-courseStatistics]').click()
cy.get('[data-cy=nav-bar-button-courseStatistics]').click()
cy.get('[data-cy=course-code-input]').type('TKT10002')
cy.contains('tr', 'TKT10002').click()
cy.contains('Filter statistics by study programmes').should('not.exist')
Expand Down
100 changes: 59 additions & 41 deletions cypress/e2e/Users.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
/// <reference types="cypress" />

const visibleLinks = {
norights: ['University', 'Faculties', 'Special populations', 'Give feedback', 'Logout'],
onlycoursestatistics: ['University', 'Courses', 'Special populations', 'Give feedback', 'Logout'],
norights: ['University', 'Faculties', 'Special populations', 'Feedback'],
onlycoursestatistics: ['University', 'Courses', 'Special populations', 'Feedback'],
}

visibleLinks.basic = [...visibleLinks.onlycoursestatistics, 'Faculties', 'Programmes', 'Students']
visibleLinks.admin = [...visibleLinks.basic, 'Teachers', 'Users', 'Updater']
visibleLinks.admin = [...visibleLinks.basic, 'Teachers', 'Admin']

const hasVisibleItems = visibleItems => {
cy.get('[data-cy=nav-bar]').children().should('have.length', visibleItems)
}

const containsLinks = links => {
cy.get('[data-cy=nav-bar]').within(() => {
for (const link of links) {
cy.contains(link)
}
})
}

const userButtonWorks = (username, mocking = false) => {
cy.get('[data-cy=nav-bar-user-button]').click()
cy.contains(mocking ? `Mocking as ${username}` : `Logged in as ${username}`)
cy.contains('Language')
cy.contains('suomi')
cy.contains('English')
cy.contains('svenska')
cy.contains(mocking ? 'Stop mocking' : 'Log out')
}

describe('Users tests', () => {
describe('Using user with just grp-oodikone-user, no other rights', () => {
describe('Using as user with just grp-oodikone-user, no other rights', () => {
it('shows correct tabs', () => {
cy.init('', 'norights')
cy.get('[data-cy=navBar]').children().should('have.length', 7)
cy.get('[data-cy=navBar]').within(() => {
for (const link of visibleLinks.norights) {
cy.contains(link)
}
})
hasVisibleItems(7)
containsLinks(visibleLinks.norights)
userButtonWorks('norights')
})
})

describe('Using as coursestatistics user', () => {
it('shows correct tabs', () => {
cy.init('', 'onlycoursestatistics')
cy.get('[data-cy=navBar]').children().should('have.length', 7)
cy.get('[data-cy=navBar]').within(() => {
for (const link of visibleLinks.onlycoursestatistics) {
cy.contains(link)
}
})
hasVisibleItems(7)
containsLinks(visibleLinks.onlycoursestatistics)
userButtonWorks('onlycoursestatistics')
})
})

describe('Using as basic user', () => {
it('shows correct tabs', () => {
cy.init('')
cy.get('[data-cy=navBar]').children().should('have.length', 10)
cy.get('[data-cy=navBar]').within(() => {
for (const link of visibleLinks.basic) {
cy.contains(link)
}
})
hasVisibleItems(10)
containsLinks(visibleLinks.basic)
userButtonWorks('basic')
})
})

Expand All @@ -51,27 +64,32 @@ describe('Users tests', () => {
})

it('should see more stuff than others', () => {
cy.get('[data-cy=navBar]').children().should('have.length', 13)
cy.get('[data-cy=navBar]').within(() => {
for (const link of visibleLinks.admin) {
cy.contains(link)
}
})
hasVisibleItems(13)
containsLinks(visibleLinks.admin)
userButtonWorks('admin')
})

it("mocking normal user shows only the mocked user's programmes", () => {
cy.contains('mocking').should('not.exist')
cy.cs('user-edit-button-basic').click()
cy.get('i.spy').click()
cy.contains('mocking as basic')
cy.contains('Programmes').click().siblings().contains('Class statistics').click()
cy.contains('label', 'Study programme')
.siblings()
.within(() => {
cy.get("div[role='option']").should('have.length', 2)
cy.get("div[role='option']").eq(0).contains('Matemaattisten tieteiden kandiohjelma')
cy.get("div[role='option']").eq(1).contains('Matematiikan ja tilastotieteen maisteriohjelma')
})
describe('can mock as other users', () => {
beforeEach(() => {
cy.cs('user-edit-button-basic').click()
cy.get('i.spy').click()
})

it('user button shows mocked user', () => {
userButtonWorks('basic', true)
})

it("only the mocked user's programmes are visible", () => {
cy.get('[data-cy=nav-bar-button-studyProgramme]').click()
cy.get('[data-cy=nav-bar-button-class]').click()
cy.contains('label', 'Study programme')
.siblings()
.within(() => {
cy.get("div[role='option']").should('have.length', 2)
cy.get("div[role='option']").eq(0).contains('Matemaattisten tieteiden kandiohjelma')
cy.get("div[role='option']").eq(1).contains('Matematiikan ja tilastotieteen maisteriohjelma')
})
})
})
})
})
Loading

0 comments on commit b17b119

Please sign in to comment.