Skip to content

Commit

Permalink
Merge pull request #153 from hpi-schul-cloud/BC-5623-changeLanguage_f…
Browse files Browse the repository at this point in the history
…eature

move file changeLanguage.feature from account folder to dashboard folder
  • Loading branch information
marcinpasscon authored Oct 25, 2023
2 parents 691cb97 + 282b5a6 commit c5db9c2
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 149 deletions.
File renamed without changes.
119 changes: 0 additions & 119 deletions cypress/support/pages/account/pageAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ class Account {
static #settingsButton = '[data-testid="settings"]'
static #email = '[data-testid="user_email"]'
static #emailReadOnly = '[data-testid="user_email_readonly"]'
static #languageMenu = '#language-menu'
static #selectedLanguage = '#selected-language'
static #listOfAllLanguages = '#available-languages'
static #germanLanguage = '[data-testid="available-language-de"]'
static #spanishLanguage = '[data-testid="available-language-es"]'
static #ukrainianLanguage = '[data-testid="available-language-uk"]'
static #englishLanguage = '[data-testid="available-language-en"]'
static #pageTitle = '#page-title'

static #testAssertionData = {
german: 'Deutsch',
spanish: 'Español',
ukrainian: 'Yкраїнська',
english: 'English',
overviewInGerman: 'Übersicht',
overviewInSpanish: 'Panel',
overviewInUkrainian: 'Панель керування',
overviewInEnglish: 'Dashboard'
}

navigateToAccountSettingsSection () {
cy.get(Account.#initialsButton).click()
Expand All @@ -40,105 +21,5 @@ class Account {
cy.get(Account.#emailReadOnly).should('have.attr', 'readonly')
}
}

assertNameInitialsIsVisible () {
cy.get(Account.#initialsButton).should('be.visible')
}

clickInitialsOfName () {
cy.get(Account.#initialsButton)
.should('be.visible')
.then($btn => {
if ($btn.is(':disabled')) {
cy.log('Button exists and is disabled!')
return
} else {
cy.log('Button exists and is enabled!')
cy.wrap($btn).click()
}
})
}

clickLanguagesDropDownMenu () {
cy.get(Account.#languageMenu)
.should('be.visible')
.click()
.then(() => {
cy.get(Account.#selectedLanguage).should('be.visible')
cy.get(Account.#listOfAllLanguages).find('li').each($element => {
cy.get($element).should('have.prop', 'value')
cy.get($element).should('be.visible')
})
})
}

changeLanguage (language) {
if (language === 'german') {
return this.selectLanguage(
Account.#germanLanguage,
Account.#testAssertionData.german
)
}

if (language === 'spanish') {
return this.selectLanguage(
Account.#spanishLanguage,
Account.#testAssertionData.spanish
)
}

if (language === 'ukrainian') {
return this.selectLanguage(
Account.#ukrainianLanguage,
Account.#testAssertionData.ukrainian
)
}

return this.selectLanguage(
Account.#englishLanguage,
Account.#testAssertionData.english
)
}

selectLanguage (sel, language) {
return cy.contains(sel, language)
.should('be.visible')
.click()
.wait(['@alerts_api'])
}

assertLanguageUpdate (updatedText) {
cy.wait(300)
.get(Account.#pageTitle)
.invoke('text')
.should('eq', updatedText)
cy.get(Account.#pageTitle)
.invoke('attr', 'data-testid')
.should('eq', updatedText)
}

verifyLanguageChanged (language) {
if (language === 'german') {
return this.assertLanguageUpdate(
Account.#testAssertionData.overviewInGerman
)
}

if (language === 'spanish') {
return this.assertLanguageUpdate(
Account.#testAssertionData.overviewInSpanish
)
}

if (language === 'ukrainian') {
return this.assertLanguageUpdate(
Account.#testAssertionData.overviewInUkrainian
)
}

return this.assertLanguageUpdate(
Account.#testAssertionData.overviewInEnglish
)
}
}
export default Account
121 changes: 121 additions & 0 deletions cypress/support/pages/dashboard/pageDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

class Dashboard {

static #initialsButton = '[data-testid="initials"]'
static #languageMenu = '#language-menu'
static #selectedLanguage = '#selected-language'
static #listOfAllLanguages = '#available-languages'
static #germanLanguage = '[data-testid="available-language-de"]'
static #spanishLanguage = '[data-testid="available-language-es"]'
static #ukrainianLanguage = '[data-testid="available-language-uk"]'
static #englishLanguage = '[data-testid="available-language-en"]'
static #getPageTitle = '#page-title'

static #testAssertionData = {
german: 'Deutsch',
spanish: 'Español',
ukrainian: 'Yкраїнська',
english: 'English',
overviewInGerman: 'Übersicht',
overviewInSpanish: 'Panel',
overviewInUkrainian: 'Панель керування',
overviewInEnglish: 'Dashboard'
}

static #welcomeMessage = '[data-testid="welcome-section"]'
static #dashboardTasksTitle = '[data-testid="dashboard-tasks-title"]'
static #dashboardTaskCourseName = '[data-testid="task-course-name"]'
Expand All @@ -11,6 +32,106 @@ class Dashboard {
static #newsSection = '[data-testid="news-section"]'
static #titleOnDashboardPage = '[id="page-title"]'

assertNameInitialsIsVisible () {
cy.get(Dashboard.#initialsButton).should('be.visible')
}

clickInitialsOfName () {
cy.get(Dashboard.#initialsButton)
.should('be.visible')
.then($btn => {
if ($btn.is(':disabled')) {
cy.log('Button exists and is disabled!')
return
} else {
cy.log('Button exists and is enabled!')
cy.wrap($btn).click()
}
})
}

clickLanguagesDropDownMenu () {
cy.get(Dashboard.#languageMenu)
.should('be.visible')
.click()
.then(() => {
cy.get(Dashboard.#selectedLanguage).should('be.visible')
cy.get(Dashboard.#listOfAllLanguages).find('li').each($element => {
cy.get($element).should('have.prop', 'value')
cy.get($element).should('be.visible')
})
})
}

changeLanguage (language) {
if (language === 'german') {
return this.selectLanguage(
Dashboard.#germanLanguage,
Dashboard.#testAssertionData.german
)
}

if (language === 'spanish') {
return this.selectLanguage(
Dashboard.#spanishLanguage,
Dashboard.#testAssertionData.spanish
)
}

if (language === 'ukrainian') {
return this.selectLanguage(
Dashboard.#ukrainianLanguage,
Dashboard.#testAssertionData.ukrainian
)
}

return this.selectLanguage(
Dashboard.#englishLanguage,
Dashboard.#testAssertionData.english
)
}

selectLanguage (sel, language) {
return cy.contains(sel, language)
.should('be.visible')
.click()
.wait(['@alerts_api'])
}

assertLanguageUpdate (updatedText) {
cy.wait(300)
.get(Dashboard.#getPageTitle)
.invoke('text')
.should('eq', updatedText)
cy.get(Dashboard.#getPageTitle)
.invoke('attr', 'data-testid')
.should('eq', updatedText)
}

verifyLanguageChanged (language) {
if (language === 'german') {
return this.assertLanguageUpdate(
Dashboard.#testAssertionData.overviewInGerman
)
}

if (language === 'spanish') {
return this.assertLanguageUpdate(
Dashboard.#testAssertionData.overviewInSpanish
)
}

if (language === 'ukrainian') {
return this.assertLanguageUpdate(
Dashboard.#testAssertionData.overviewInUkrainian
)
}

return this.assertLanguageUpdate(
Dashboard.#testAssertionData.overviewInEnglish
)
}

arriveOnDashboard() {
cy.visit('/dashboard')
cy.url()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const { When, Then } = require("@badeball/cypress-cucumber-preprocessor")
import Account from '../../pages/account/pageAccount'
import Dashboard from '../../pages/dashboard/pageDashboard'

const account = new Account()
const dashboard = new Dashboard()

Then('I can see initials of my name', () => {
account.assertNameInitialsIsVisible()
dashboard.assertNameInitialsIsVisible()
})

When('I click on initials of my name', () => {
account.clickInitialsOfName()
dashboard.clickInitialsOfName()
})

Then('I click on language drop down menu', () => {
account.clickLanguagesDropDownMenu()
dashboard.clickLanguagesDropDownMenu()
})

When('I can change language to {string}', language => {
account.changeLanguage(language)
dashboard.changeLanguage(language)
})

Then('I can see title in dashboard is changed to {string}', language => {
account.verifyLanguageChanged(language)
dashboard.verifyLanguageChanged(language)
})
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5db9c2

Please sign in to comment.