Skip to content
Snippets Groups Projects
Verified Commit 52e32c80 authored by Jayesh's avatar Jayesh :cat2: Committed by Antoine R. Dumont
Browse files

Cypress tests for create request

parent 4acb8f17
No related branches found
Tags v0.3.2
No related merge requests found
......@@ -8,7 +8,6 @@
export function onCreateRequestPageLoad() {
$('#requestForm').submit(function(event) {
event.preventDefault();
$.ajax({
data: $(this).serialize(),
type: $(this).attr('method'),
......@@ -18,6 +17,7 @@ export function onCreateRequestPageLoad() {
$('#userMessage').text('Your request has been submitted');
$('#userMessage').removeClass('badge-danger');
$('#userMessage').addClass('badge-success');
populateRequesBrowseList();
},
error: function(response, status, error) {
$('#userMessage').text('Sorry; an error occurred');
......
/**
* Copyright (C) 2022 The Software Heritage developers
* See the AUTHORS file at the top-level directory of this distribution
* License: GNU Affero General Public License version 3, or any later version
* See top-level LICENSE file for more information
*/
function populateForm(type, url, contact, email, consent, comment) {
cy.get('#swh-input-forge-type').select(type);
cy.get('#swh-input-forge-url').type(url);
cy.get('#swh-input-forge-contact-name').type(contact);
cy.get('#swh-input-forge-contact-email').type(email);
cy.get('#swh-input-forge-comment').type(comment);
}
describe('Test add-forge-request creation', function() {
beforeEach(function() {
this.addForgeNowUrl = this.Urls.forge_add();
});
it('should show two tabs for every user', function() {
cy.visit(this.addForgeNowUrl);
cy.get('#swh-add-forge-tab')
.should('have.class', 'nav-link');
cy.get('#swh-add-forge-requests-list-tab')
.should('have.class', 'nav-link');
});
it('should show create forge tab by default', function() {
cy.visit(this.addForgeNowUrl);
cy.get('#swh-add-forge-tab')
.should('have.class', 'active');
cy.get('#swh-add-forge-requests-list-tab')
.should('not.have.class', 'active');
});
it('should show login link for anonymous user', function() {
cy.visit(this.addForgeNowUrl);
cy.get('#loginLink')
.should('be.visible')
.contains('log in here');
});
it('should bring back after login', function() {
cy.visit(this.addForgeNowUrl);
cy.get('#loginLink')
.should('have.attr', 'href')
.and('include', `${this.Urls.login()}?next=${this.Urls.forge_add()}`);
});
it('should change tabs on click', function() {
cy.visit(this.addForgeNowUrl);
cy.get('#swh-add-forge-requests-list-tab').click();
cy.get('#swh-add-forge-tab')
.should('not.have.class', 'active');
cy.get('#swh-add-forge-requests-list-tab')
.should('have.class', 'active');
cy.get('#swh-add-forge-tab').click();
cy.get('#swh-add-forge-tab')
.should('have.class', 'active');
cy.get('#swh-add-forge-requests-list-tab')
.should('not.have.class', 'active');
});
it('should show create form elements to authenticated user', function() {
cy.userLogin();
cy.visit(this.addForgeNowUrl);
cy.get('#requestForm')
.children()
.contains('Forge type');
cy.get('#requestForm')
.children()
.contains('Forge URL');
cy.get('#requestForm')
.children()
.contains('Forge contact name');
cy.get('#requestForm')
.children()
.contains('Forge contact email');
cy.get('#requestForm')
.children()
.contains('Forge contact email');
cy.get('#requestForm')
.children()
.contains('Submit Add Request');
});
it('should show browse requests table for every user', function() {
// testing only for anonymous
cy.visit(this.addForgeNowUrl);
cy.get('#swh-add-forge-requests-list-tab').click();
cy.get('#add-forge-request-browse')
.should('be.visible');
cy.get('#loginLink')
.should('not.be.visible');
});
it('should show success message on form submit', function() {
cy.userLogin();
cy.visit(this.addForgeNowUrl);
populateForm('cgit', 'gitlab.com', 'test', 'test@example.com', 'on', 'test comment');
cy.get('#requestForm').submit();
cy.get('#userMessage')
.should('have.class', 'badge-success');
});
it('should show error message on conflict', function() {
cy.userLogin();
cy.visit(this.addForgeNowUrl);
populateForm('bitbucket', 'gitlab.com', 'test', 'test@example.com', 'on', 'test comment');
cy.get('#requestForm').submit();
cy.get('#userMessage')
.should('have.class', 'badge-danger')
.should('contain', 'Sorry; an error occurred');
});
it('should should update broswse list on successul submission', function() {
cy.userLogin();
cy.visit(this.addForgeNowUrl);
populateForm('bitbucket', 'gitlab.com', 'test', 'test@example.com', 'on', 'test comment');
cy.get('#requestForm').submit();
// Change tab
cy.get('#swh-add-forge-requests-list-tab').click();
cy.get('#add-forge-request-browse')
.should('be.visible')
.contains('gitlab.com');
cy.get('#add-forge-request-browse')
.should('be.visible')
.contains('PENDING');
});
});
......@@ -51,7 +51,7 @@ See top-level LICENSE file for more information
<h3>
<p class="text-primary">
You must be logged in to submit an add forge request. Please
<a href="{% url 'login' %}?next={% url 'forge-add' %}" class="link-primary">log in here</a>
<a id="loginLink" href="{% url 'login' %}?next={% url 'forge-add' %}" class="link-primary">log in here</a>
</p>
</h3>
{% else %}
......@@ -121,7 +121,7 @@ See top-level LICENSE file for more information
<div class="form-row">
<div class="col-md-12">
<input type="submit" value="Submit Add Request" class="btn btn-default float-right">
<input id="swh-input-form-submit" type="submit" value="Submit Add Request" class="btn btn-default float-right">
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment