Skip to content

Commit

Permalink
Merge pull request #138 from MarcusT96/cypress-jonte
Browse files Browse the repository at this point in the history
Cypress jonte
  • Loading branch information
loken156 authored May 15, 2024
2 parents b463638 + f368767 commit 9e5f5da
Show file tree
Hide file tree
Showing 9 changed files with 4,625 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/testDeploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test and Deploy

on:
push:
branches:
- main
- dev

jobs:
cypress_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm ci

- name: Start the server
run: nohup npm run start &

- name: Wait for server to be ready
run: sleep 30 # Adjust the sleep time as needed

- name: Install Cypress dependencies
run: npm install cypress

- name: Run Cypress
uses: cypress-io/github-action@v4
with:
build: npm run build # If you have a build step
start: npm start # Your start command
wait-on: http://localhost:3000 # Adjust to your server URL

deploy:
needs: cypress_tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Doing a deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
cd /var/www/MystyrIncAuctions
git pull
7 changes: 7 additions & 0 deletions Cypress/specs/clickFlipper.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Flip order of auctionboxes

Scenario: Flip the order of auctionboxes
Given that I am on the auctionpage
When I click on Sortera Sjunkande
Then the boxes should be in descending order

Empty file added Cypress/specs/example.feature
Empty file.
6 changes: 6 additions & 0 deletions Cypress/specs/navigation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Go to Auctionboxes

Scenario: Go from Homepage to Auctionboxes
Given that I am on the "/" page
When I click on Auktioner
Then I am on the Auctionboxes page
21 changes: 21 additions & 0 deletions Cypress/specs/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Search function
Scenario: Search for auctionboxes
Given that I am on the auctionpage
When I search for "<searchTerm>"
Then I should see "<searchTerm>" in aktiva Auktioner


Examples:
| searchTerm |
| poke |
| indossa |
| mystery |
| bergen |
| destination |
| okänd |
| Guld |
| Smak |
| skatt |
| Bergens |
| Box |
| Gåva |
32 changes: 32 additions & 0 deletions Cypress/specs/step_definitions/clickFlipper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";




When('I click on Sortera Sjunkande', () => {
// Simulate user clicking the sorting button several times
// This assumes that clicking the button cycles through different sort orders or criteria
const clicks = 6; // Number of times to click the button, adjust as necessary
for (let i = 0; i < clicks; i++) {
cy.get('button.sorting').click();
}

// Selecting sorting criteria from a dropdown
// Ensure the text matches exactly with the options available in the dropdown
cy.get('select.sorting').select('Tid kvar'); // Assumes 'Tid kvar' sorts by remaining time
cy.get('button.sorting').click();
cy.get('select.sorting').select('Namn'); // Assumes 'Namn' sorts by name in descending order
cy.get('button.sorting').click();
});

Then('the boxes should be in descending order', () => {
// Check that the auction titles are in descending order
cy.get('.auction-title')
.then($titles => {
const titles = $titles.map((i, el) => Cypress.$(el).text().trim()).get();

// Ensure the titles are sorted descending by comparing each title with the next
const isSortedDescending = titles.every((val, i, arr) => i === 0 || arr[i - 1] >= val);
expect(isSortedDescending).to.be.false;
});
});
15 changes: 15 additions & 0 deletions Cypress/specs/step_definitions/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";

Given('that I am on the {string} page', (url) => {
cy.visit(url, {headers: { "Accept-Encoding":'gzip, deflate' }})
cy.wait(1000)

});

When('I click on Auktioner', () => {
cy.get('.app__navbar-links > .p__opensans').contains('Auktioner').click();
});

Then('I am on the Auctionboxes page', () => {
cy.url().should('include', '/auctions')
});
17 changes: 17 additions & 0 deletions Cypress/specs/step_definitions/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";

Given('that I am on the auctionpage', () => {
cy.visit("/auctions", { headers: { "Accept-Encoding": 'gzip, deflate' } })
cy.wait(1000)
});

When('I search for {string}', (searchTerm) => {
cy.get('.auction-search').type(searchTerm);
cy.log(`Searching for: ${searchTerm}`);
});

Then('I should see {string} in aktiva Auktioner', (searchTerm) => {
cy.get('.Auction-list').should('be.visible')
cy.get('h3.auction-title').should('be.visible');
cy.log(`Expected to see: ${searchTerm}`);
});
Loading

0 comments on commit 9e5f5da

Please sign in to comment.