Skip to content

Commit

Permalink
Merge pull request #41 from UdL-EPS-SoftArch/33-create-cypress-coordi…
Browse files Browse the repository at this point in the history
…nate

cypress coordinate
  • Loading branch information
rogargon authored Dec 29, 2023
2 parents 79264f7 + 1d373df commit 4d9bb51
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 2 deletions.
24 changes: 24 additions & 0 deletions e2e/features/coordinates/CreateCoordinate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Create Coordinate
In order to use the app
As admin
I want to create a coordinate

Scenario: Create a new coordinate
Given I'm in the homepage logged in as an admin
When I go to the coordinate list page
And I click on add coordinte button
And I fill the form with
| FIELD | VALUE |
| coordinate | 41.40338,2.17403 |
And I click the "Create" button
Then I am redirected to the coordinate detail page


Scenario: Create a new incorrect coordinate
Given I'm in the homepage logged in as an admin
When I go to the coordinate list page
And I click on add coordinte button
And I fill the form with
| FIELD | VALUE |
| coordinate | 300.40338,2.17403 |
Then Create button should be disabled
19 changes: 19 additions & 0 deletions e2e/features/coordinates/DeleteCoordinate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Delete Coordinate
In order to use the app
As admin
I want to delete a coordinate

Scenario: Delete a new coordinate
Given I'm in the homepage logged in as an admin
And I go to the coordinate list page
And I click on add coordinte button
And I fill the form with
| FIELD | VALUE |
| coordinate | 41.40338,2.17403 |
And I click the "Create" button
And I am redirected to the coordinate detail page
When I click the "Delete" button
Then I am redirected to the coordinate delete page
And I click the "Delete" button
Then I am redirected to the coordinate list page

21 changes: 21 additions & 0 deletions e2e/features/coordinates/ModifyCoordinate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Modify Coordinate
In order to use the app
As admin
I want to modify a coordinate

Scenario: Modify a new coordinate
Given I'm in the homepage logged in as an admin
And I go to the coordinate list page
And I click on add coordinte button
And I fill the form with
| FIELD | VALUE |
| coordinate | 41.40338,2.17403 |
And I click the "Create" button
And I am redirected to the coordinate detail page
And I click the "Edit" button
And I am redirected to the coordinate edit page
When I clear and fill the form with
| FIELD | VALUE |
| coordinate | 42.40338,3.17403 |
And I click the "Update" button
Then I am redirected to the coordinate detail page
17 changes: 17 additions & 0 deletions e2e/features/coordinates/ReadCoordinate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Read Coordinate
In order to use the app
As admin
I want to read a coordinate

Scenario: Modify a new coordinate
Given I'm in the homepage logged in as an admin
And I go to the coordinate list page
And I click on add coordinte button
And I fill the form with
| FIELD | VALUE |
| coordinate | 41.40338,2.17403 |
And I click the "Create" button
And I am redirected to the coordinate detail page
And I go to the coordinate list page
When I click the "View" button
Then I am redirected to the coordinate detail page
38 changes: 38 additions & 0 deletions e2e/steps/coordinates/create-coordinate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {DataTable} from '@cucumber/cucumber';
import {Given, Then, When} from 'cypress-cucumber-preprocessor/steps';

Given(/^I'm in the homepage logged in as an admin$/, function () {
cy.visit('http://localhost:4200');
cy.get('.nav-link').contains('Login').click();
cy.get('#username').type('root').blur();
cy.get('#password').type('password').blur();
cy.get('button').contains('Submit').click();
});
When(/^I go to the coordinate detail page$/, function () {
cy.get('.nav-link').contains('Coordinate').click();
cy.get('.dropdown-item.coordinateListNavbar').click();
});
When(/^I click on add coordinte button$/, function () {
cy.get('.createCoordinateBtn').click();
});
Then(/^Create button should be disabled$/, function () {
cy.get('button').contains('Create').should('be.disabled');
});
Given(/^I'm in the homepage logged in as an user$/, function () {
cy.visit('http://localhost:4200');
cy.get('.nav-link').contains('Login').click();
cy.get('#username').type('demo').blur();
cy.get('#password').type('password').blur();
cy.get('button').contains('Submit').click();
});
Then(/^I should not see the seed create button$/, function () {
cy.get('#createSeed').should('not.exist');
});
When(/^I fill the form with$/, function (table: DataTable) {
table.rows().forEach((pair: string[]) =>
cy
.get('#' + pair[0])
.type(pair[1])
.blur()
);
});
26 changes: 26 additions & 0 deletions e2e/steps/coordinates/delete-coordinate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Given, Then, When} from 'cypress-cucumber-preprocessor/steps';

Given(/^I'm in the homepage logged in as an admin$/, function () {
cy.visit('http://localhost:4200');
cy.get('.nav-link').contains('Login').click();
cy.get('#username').type('root').blur();
cy.get('#password').type('password').blur();
cy.get('button').contains('Submit').click();
});
Given(/^I go to the coordinate list page$/, function () {
cy.get('.nav-link').contains('Coordinate').click();
cy.get('.dropdown-item.coordinateListNavbar').click();
});
Given(/^I click on add coordinte button$/, function () {
cy.get('.createCoordinateBtn').click();
});
Given(/^I am redirected to the coordinate detail page$/, function () {
cy.url().should('match', /\/coordinates\/\d+/);
});
When(/^I am redirected to the coordinate delete page$/, function () {
cy.url().should('match', /\/coordinates\/\d+\/delete/);
});

Then(/^I am redirected to the coordinate list page$/, function () {
cy.url().should('match', /\/coordinates/);
});
15 changes: 15 additions & 0 deletions e2e/steps/coordinates/modify-coordinate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Given, When} from 'cypress-cucumber-preprocessor/steps';
import {DataTable} from "@cucumber/cucumber";

Given(/^I am redirected to the coordinate edit page$/, function () {
cy.url().should('match', /\/coordinates\/\d+\/edit/);

});

When('I clear and fill the form with', (table: DataTable) => {
cy.wait(1000);
table.rows().forEach(function (pair: string[]) {
cy.get('#' + pair[0]).clear();
cy.get('#' + pair[0]).type(pair[1]).blur();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3>Coordinates List</h3>
<div class="col-md-6">
<div style="text-align: right;">
<button type="button" [routerLink]="['/coordinates/create']"
class="btn btn-outline-primary">Create
class="btn btn-outline-primary createCoordinateBtn">Create
</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="dropdown-menu" aria-labelledby="coordinateDropdown" ngbDropdownMenu>
<a class="dropdown-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"
[routerLink]="['/coordinates/create']"><span class="fas fa-user-circle"></span> Create</a>
<a class="dropdown-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"
<a class="dropdown-item coordinateListNavbar" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"
[routerLink]="['/coordinates']"><span class="fas fa-user-circle"></span> List</a>
</div>
</li>
Expand Down

0 comments on commit 4d9bb51

Please sign in to comment.