BestNotes/test/specs/base/navigation.js

69 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2019-11-29 22:16:18 +01:00
const base = require('./base');
const Login = require('../components/login');
2019-12-08 22:46:26 +01:00
const Note = require('../components/note');
2019-11-29 22:16:18 +01:00
class Navigation {
constructor() {
2020-01-01 20:18:23 +01:00
this.baseUrl = 'bestnotes.pythonanywhere';
2019-11-29 22:16:18 +01:00
this.loginUrl = 'http://bestnotes.pythonanywhere.com/bestnotes/accounts/login/';
2019-12-08 22:46:26 +01:00
this.notesUrl = 'http://bestnotes.pythonanywhere.com/bestnotes/notes/1';
2020-01-01 20:18:23 +01:00
this.subjectUrl = 'http://bestnotes.pythonanywhere.com/bestnotes/subject/';
this.topicUrl = 'http://bestnotes.pythonanywhere.com/bestnotes/topics_by_subject_id/1';
this.loggedInCookiesSet = [
{
name: 'sessionid',
value: 'wjx1o12d94hf2pv3xmfu5kya29v4kono',
path: '/',
domain: `.${this.baseUrl}.com`,
},
];
this.anonCookiesSet = [
{
name: 'sessionid',
value: 'abcdef',
path: '/',
domain: `.${this.baseUrl}.com`,
},
];
2019-11-29 22:16:18 +01:00
}
toLoginPage() {
browser.url(this.loginUrl);
return new Login();
2019-12-08 22:46:26 +01:00
}
2020-01-01 20:18:23 +01:00
toNotesPage(user) {
2019-12-08 22:46:26 +01:00
browser.url(this.notesUrl);
2020-01-01 20:18:23 +01:00
this.setUser(user);
2019-12-08 22:46:26 +01:00
return new Note();
2019-11-29 22:16:18 +01:00
}
2020-01-01 20:18:23 +01:00
toSubjectPage(user) {
browser.url(this.notesUrl);
this.setUser(user);
return new Note();
}
toTopicPage(user) {
browser.url(this.topicUrl);
this.setUser(user);
return new Note();
}
setUser(user) {
switch (user.toLowerCase()) {
case 'anon':
browser.setCookies(this.anonCookiesSet);
base.waitForCookiesSet(this.anonCookiesSet);
break;
case 'user':
browser.setCookies(this.loggedInCookiesSet);
base.waitForCookiesSet(this.loggedInCookiesSet);
break;
default:
throw new Error('setUser() method parameter is invalid');
}
}
2019-11-29 22:16:18 +01:00
}
module.exports = new Navigation();