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

Hubert / Navigation test machine #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 4 additions & 8 deletions cypress/integration/api.deriv.com.spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
/// <reference types="cypress" />

import { testsModel, testsMobileModel } from "./cypressStates";
import { itTests } from "./itVisitsAndRunsPathTests";

context("Deriv API full run", () => {
const testPlans = testsModel('home').getShortestPathPlans();
const testPlans = cy.testsModel('home').getShortestPathPlans();
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
});
});
});

context("Deriv API mobile", () => {
const testPlans = testsMobileModel('home').getShortestPathPlans();
const testPlans = cy.testsMobileModel('home').getShortestPathPlans();
beforeEach(() => {
// run these tests as if in a mobile browser
// and ensure our responsive UI is correct
cy.viewport('iphone-x')
})
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
});
});
});
13 changes: 13 additions & 0 deletions cypress/integration/hamburger.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
context("Deriv API mobile", () => {
const testPlans = cy.hamburgerTestModel().getSimplePathPlans();
beforeEach(() => {
// run these tests as if in a mobile browser
// and ensure our responsive UI is correct
cy.viewport('iphone-x')
})
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(cy.itTests('/'));
});
});
});
11 changes: 4 additions & 7 deletions cypress/integration/homeslider.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { homeSliderTestsModel } from './cypressStates'
import { itTests } from "./itVisitsAndRunsPathTests";

context("Homepage slider", () => {
const testPlans = homeSliderTestsModel().getSimplePathPlans();
const testPlans = cy.homeSliderTestsModel().getSimplePathPlans();
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
});
});
});

context("Deriv API mobile", () => {
const testPlans = homeSliderTestsModel().getShortestPathPlans();
const testPlans = cy.homeSliderTestsModel().getSimplePathPlans();
beforeEach(() => {
// run these tests as if in a mobile browser
// and ensure our responsive UI is correct
cy.viewport('iphone-x')
})
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
});
});
});
6 changes: 0 additions & 6 deletions cypress/integration/itVisitsAndRunsPathTests.js

This file was deleted.

11 changes: 4 additions & 7 deletions cypress/integration/snapshots.homeslider.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { homeSliderTestsModel, homeSliderMobileTestsModel } from "./cypressStates";
import { itTests } from "./itVisitsAndRunsPathTests";

context("Snapshots", () => {
const testPlans = homeSliderTestsModel().getSimplePathPlans();
const testPlans = cy.homeSliderTestsModel().getSimplePathPlans();
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
afterEach(() => {
cy.get("[aria-label='slider-component']").matchImageSnapshot();
});
Expand All @@ -14,15 +11,15 @@ const testPlans = homeSliderTestsModel().getSimplePathPlans();
});

context("Snapshots mobile", () => {
const testPlans = homeSliderTestsModel().getShortestPathPlans();
const testPlans = cy.homeSliderTestsModel().getShortestPathPlans();
beforeEach(() => {
// run these tests as if in a mobile browser
// and ensure our responsive UI is correct
cy.viewport('iphone-x')
})
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
afterEach(() => {
cy.get("[aria-label='slider-component']").matchImageSnapshot();
});
Expand Down
7 changes: 2 additions & 5 deletions cypress/integration/snapshots.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { testsModel } from "./cypressStates";
import { itTests } from "./itVisitsAndRunsPathTests";

context("Snapshots", () => {
const testPlans = testsModel('home').getShortestPathPlans();
const testPlans = cy.testsModel('home').getShortestPathPlans();
testPlans.forEach((plan) => {
describe(plan.description, () => {
plan.paths.forEach(itTests('/'));
plan.paths.forEach(cy.itTests('/'));
afterEach(() => {
cy.matchImageSnapshot();
});
Expand Down
3 changes: 2 additions & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import './commands';
import './machine_blueprints/commands.js';

// Alternatively you can use CommonJS syntax:
// require('./commands')
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createTestModel } from "./createTestModel.js";
import { derivApiMachine } from "./derivApiMachine";
import { homeSliderMachine } from "./homeSliderMachine.js";
import { hamburgerMachine } from "./hamburgerMachine.js"

const cypressStates = {
home: () => {
Expand Down Expand Up @@ -163,6 +164,106 @@ const homeSliderEvents = {
},
}

export const testsModel = (initialState) => createTestModel(derivApiMachine(initialState), cypressStates, cypressEvents);
export const testsMobileModel = (initialState) => createTestModel(derivApiMachine(initialState), cypressMobileStates, cypressMobileEvents);
export const homeSliderTestsModel = () => createTestModel(homeSliderMachine(), homeSliderStates, homeSliderEvents);
const hamburgerStates = {
open_hamburger: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/api playground/i).should('be.visible')
},
home_active: () => {
cy.get(`[aria-label="hamburger-dropdown"] .menu-wrapper > :nth-child(2)::before`)
},
documentation_closed: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/quickstart/i).should('not.be.visible')
},
documentation_open: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/quickstart/i).should('be.visible')
},
documentation_closed: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/quickstart/i).should('not.be.visible')
},
quickstart: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/quickstart/i).should('be.visible')
},
app_registration: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/app registration/i).should('be.visible')
},
api_guide: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/api guide/i).should('be.visible')
},
faq: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/faq/i).should('be.visible')
},
json_schemas: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/json schemas/i).should('be.visible')
},
bug_bounty: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/bug bounty/i).should('be.visible')
},
api_playground: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/home/i).should('be.visible')
},
closed_hamburger: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/api playground/i).should('not.be.visible')
}
}

const hamburgerEvents = {
CLICK_HAMBURGER: () => {
cy.get(`[role="menu"]`).click();
cy.wait(500);
},
CLICK_HOME: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/home/i).click()
},
TOGGLE_DOCUMENTATION: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
},
CLICK_QUICKSTART: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/quickstart/i).click()
},
CLICK_APP_REGISTRATION: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/app registration/i).click()
},
CLICK_API_GUIDE: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/api guide/i).click()
},
CLICK_FAQ: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/faq/i).click()
},
CLICK_JSON_SCHEMAS: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/json schemas/i).click()
},
CLICK_BUG_BOUNTY: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/documentation/i).click()
cy.wait(250)
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/bug bounty/i).click()
},
CLICK_PLAYGROUND: () => {
cy.get(`[aria-label="hamburger-dropdown"]`).contains(/api playground/i).click()
},
CLOSE_HAMBURGER: () => {
cy.get(`.desktop\:hidden[role="menu"]`).click();
cy.wait(500);
},
}

const itVisitsAndRunsPathTests = (url) => (path) => {
it(path.description, function () {
cy.visit(url).then(path.test);
});
};

cy.itTests = (appAddress) => itVisitsAndRunsPathTests(appAddress);
cy.testsModel = (initialState) => createTestModel(derivApiMachine(initialState), cypressStates, cypressEvents);
cy.testsMobileModel = (initialState) => createTestModel(derivApiMachine(initialState), cypressMobileStates, cypressMobileEvents);
cy.homeSliderTestsModel = () => createTestModel(homeSliderMachine(), homeSliderStates, homeSliderEvents);
cy.hamburgerTestModel = () => createTestModel(hamburgerMachine(), hamburgerStates, hamburgerEvents);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createMachine } from 'xstate';
import { createMachine } from "xstate";
import { createModel } from "@xstate/test";

function addTests(state, tests) {
Expand All @@ -18,7 +18,7 @@ function addTests(state, tests) {
}, {})
};
}
export const createTestModel = (machine, stateTests, eventTests) => {
export const createTestModel = (machine, stateTests, eventTests) => {
const modelMachine = createMachine(addTests(machine, stateTests));
const model = createModel(modelMachine, { events: eventTests });
return model;
Expand Down
46 changes: 46 additions & 0 deletions cypress/support/machine_blueprints/hamburgerMachine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const hamburgerMachine = () => ({
id: 'hamburger',
initial: 'closed_hamburger',
on: {
CLICK_HAMBURGER: 'open_hamburger',
},
states: {
open_hamburger: {
on: {
CLICK_HAMBURGER: '#hamburger.closed_hamburger',
CLOSE_HAMBURGER: '#hamburger.closed_hamburger',
CLICK_HOME: '#hamburger.closed_hamburger',
TOGGLE_DOCUMENTATION: '#hamburger.open_hamburger.documentation_open',
CLICK_APP_REGISTRATION: '#hamburger.closed_hamburger',
CLICK_API_GUIDE: '#hamburger.closed_hamburger',
CLICK_FAQ: '#hamburger.closed_hamburger',
CLICK_JSON_SCHEMAS: '#hamburger.closed_hamburger',
CLICK_BUG_BOUNTY: '#hamburger.closed_hamburger',
CLICK_API_PLAYGROUND: '#hamburger.closed_hamburger',
},
states: {
documentation_open: {
on: {
TOGGLE_DOCUMENTATION: 'documentation_closed',
CLICK_QUICKSTART: '#hamburger.closed_hamburger',
CLICK_APP_REGISTRATION: '#hamburger.closed_hamburger',
CLICK_API_GUIDE: '#hamburger.closed_hamburger',
CLICK_FAQ: '#hamburger.closed_hamburger',
CLICK_JSON_SCHEMAS: '#hamburger.closed_hamburger',
CLICK_BUG_BOUNTY: '#hamburger.closed_hamburger',
},
},
documentation_closed: {
on: {
TOGGLE_DOCUMENTATION: 'documentation_open'
},
},
},
},
closed_hamburger: {
on: {
CLICK_HAMBURGER: 'open_hamburger',
}
},
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to see our hamburger :D In the end I'd say it looks clear (this nesting is not that scary as I thought it could be)

6 changes: 4 additions & 2 deletions src/Components/NavigationBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const NavigationBar: Component = () => {
</div>
</div>
<header class="h-[73px] w-4/5 mobile:h-[48px] mobile:pl-4 mobile:w-full mobile:flex">
<section class="flex items-center">
<section aria-label="hamburger" class="flex items-center">
<img
role='menu'
class="desktop:hidden mobile:mr-2.5"
src={showMobileNav() ? closeSVGUrl : hamburgerMenuUrl}
alt="Deriv Logo"
Expand Down Expand Up @@ -72,7 +73,8 @@ export const NavigationBar: Component = () => {
</section>
</header>
<section
class={`fixed bg-white top-[48px] h-[calc(100%+54px) w-[253px] overflow-hidden left-[-254px] text-base burger ${
aria-label="hamburger-dropdown"
class={`fixed bg-white top-[48px] h-[calc(100%+54px) w-[253px] overflow-hidden left-[-254px] text-base burger ${
showMobileNav() && "transition-left"
}`}
>
Expand Down