Skip to content
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

Browser tests #370

Merged
merged 5 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ modernomad/local_settings.py.bak
ghostdriver.log
.env
static/CACHE/

/node_modules
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
language: node_js
node_js:
- 10
cache:
npm: true
directories:
# cache folder with Cypress binary
- ~/.cache
dist: xenial
script: script/test
install:
- sudo apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
- npm ci
script:
- script/test
- docker-compose up -d
- docker-compose run web ./manage.py migrate
- docker-compose run web ./manage.py generate_test_data
- $(npm bin)/cypress run --record --key 88257c2f-8d2e-464c-878b-650cace8563e
notifications:
slack:
rooms:
Expand Down
Empty file removed bdd/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions bdd/admin.py

This file was deleted.

Binary file removed bdd/data/avatars/craig.jpg
Binary file not shown.
52 changes: 0 additions & 52 deletions bdd/features/environment.py

This file was deleted.

100 changes: 0 additions & 100 deletions bdd/features/steps/booking.py

This file was deleted.

16 changes: 0 additions & 16 deletions bdd/features/steps/data_creation.py

This file was deleted.

20 changes: 0 additions & 20 deletions bdd/features/tourists/booking_a_room.feature

This file was deleted.

Empty file removed bdd/migrations/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions bdd/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions bdd/tests.py

This file was deleted.

3 changes: 0 additions & 3 deletions bdd/views.py

This file was deleted.

4 changes: 2 additions & 2 deletions core/factory_apps/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Meta:
longitude = factory.Faker('longitude')

welcome_email_days_ahead = factory.Iterator([1,2,3,4,5])
max_booking_days = factory.Iterator([1,5,14,30])
max_booking_days = factory.Iterator([5,14,30])

stay_page = factory.Faker('text')
front_page_stay = factory.Faker('text')
Expand Down Expand Up @@ -106,7 +106,7 @@ class Meta:

name = factory.Faker('name')
location = factory.SubFactory(LocationFactory)
default_rate = factory.Faker('pydecimal', left_digits=0, positive=True)
default_rate = factory.Iterator([14.12, 30.53, 99, 31.41])
description = factory.Faker('text')
summary = factory.Faker('sentence')
cancellation_policy = factory.Faker('text')
Expand Down
11 changes: 6 additions & 5 deletions core/views/unsorted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,15 +2301,17 @@ def process_unsaved_booking(request):
return


def user_login(request):
def user_login(request, username=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that we use https://djangopackages.org/packages/p/django-registration/ for registration / login. If you agree let's open a new issue for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sounds good! These views looked like a bit of a mess but I didn’t want to refactor them now. 🙈

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will come a day :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes agree! this project was started before django had a registration or profile functionality built in. have been keen to move to the newer functionality.

logger.debug('in user_login')
next_page = None
if 'next' in request.GET:
next_page = request.GET['next']

username = password = ''
password = ''
if request.POST:
username = request.POST['username']
# Username is pre-set if this is part of registration flow
if not username:
username = request.POST['username']
# JKS this is a bit janky. this is because we use this view both after
# the user registration or after the login view, which themselves use
# slightly different forms.
Expand Down Expand Up @@ -2355,8 +2357,7 @@ def register(request):
profile_form = UserProfileForm(request.POST, request.FILES)
if profile_form.is_valid():
user = profile_form.save()
request.POST['username'] = user.username
return user_login(request)
return user_login(request, username=user.username)
else:
logger.debug('profile form contained errors:')
logger.debug(profile_form.errors)
Expand Down
4 changes: 4 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:8000",
"projectId": "3gfovh"
}
Binary file added cypress/fixtures/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions cypress/integration/booking_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// <reference types="Cypress" />
const randomstring = require("randomstring");

describe("Booking a room", function() {
it("New user flow", function() {
cy.visit("/");
cy.contains("Cummings Green").click();
cy.contains("View all rooms").click();
cy.contains("Evan Johnson").click({ force: true });

cy.get("input[name=arrive]").focus();
// Pick next month so all the dates are available
cy.get(".react-datepicker__navigation--next").click({ force: true });
cy.get("[aria-label=day-13]").click({ force: true });
// Force de-select first date picker. For some reason immediately selecting second date
// picker causes first not to close.
cy.get("#network-footer").click("topLeft");
cy.get("input[name=depart]").focus();
cy.get("[aria-label=day-16]").click({ force: true });
cy.get("[name=purpose]").type("Work.");
cy.contains("Request to Book").click();

cy.get("[name=bio]").type("I am a robot.");
cy.get("[name=projects]").type("Kill all humans.");
cy.get("[name=sharing]").type("I can do your math homework.");
cy.get("[name=discussion]").type("Is AI risk overrated?");
cy.get("[name=first_name]").type("Bot");
cy.get("[name=last_name]").type("McBotface");
cy.get("[name=referral]").type("Pixel");
cy.get("[name=city]").type("Chapek 9");
cy.get("[name=email]").type(`${randomstring.generate(10)}@example.com`);
cy.get("[name=password1]").type("password");
cy.get("[name=password2]").type("password");

cy.uploadFile("profile.png", "input[name=image");

cy.contains("Submit").click();

cy.contains("Your booking has been submitted.");
});
});
17 changes: 17 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
41 changes: 41 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

// https://github.com/cypress-io/cypress/issues/170
Cypress.Commands.add("uploadFile", (fileName, selector) => {
cy.get(selector).then(subject => {
cy.fixture(fileName).then(content => {
Cypress.Blob.base64StringToBlob(content, "image/jpeg").then(blob => {
const el = subject[0];
const testFile = new File([blob], fileName);
const dataTransfer = new DataTransfer();

dataTransfer.items.add(testFile);
el.files = dataTransfer.files;
});
});
});
});
Loading