Skip to content

Commit

Permalink
refactor: make menu click-based and reorganise related components
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric authored May 26, 2020
2 parents acf4857 + a8b26a0 commit f12e960
Show file tree
Hide file tree
Showing 50 changed files with 938 additions and 1,013 deletions.
5 changes: 0 additions & 5 deletions cypress/integration/ComponentCover/click_behavior.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
Feature: The ComponentCover has configurable click behaviour

Scenario: A non-blocking ComponentCover
Given a ComponentCover with pointerEvents none and a button below it is rendered
When the user clicks the button
Then the onClick handler of the button is called

Scenario: A blocking ComponentCover
Given a ComponentCover with a button below it is rendered
When the user clicks on the button coordinates
Expand Down
7 changes: 0 additions & 7 deletions cypress/integration/ComponentCover/click_behavior/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given(
'a ComponentCover with pointerEvents none and a button below it is rendered',
() => {
cy.visitStory('ComponentCover', 'Non Blocking')
}
)

Given('a ComponentCover with a button below it is rendered', () => {
cy.visitStory('ComponentCover', 'Blocking')
})
Expand Down
5 changes: 5 additions & 0 deletions cypress/integration/FlyoutMenu/accepts_children.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: The FlyoutMenu renders children

Scenario: A FlyoutMenu with children
Given a FlyoutMenu with children is rendered
Then the children are visible
10 changes: 10 additions & 0 deletions cypress/integration/FlyoutMenu/accepts_children/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a FlyoutMenu with children is rendered', () => {
cy.visitStory('FlyoutMenu', 'With Children')
cy.get('[data-test="dhis2-uicore-menu"]').should('be.visible')
})

Then('the children are visible', () => {
cy.contains('I am a child').should('be.visible')
})
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Feature: Position of a MenuItem component
Feature: Position of a SubMenu component
Scenario: Default rendering
Given there is enough space to the right of the MenuItem to fit the SubMenu
When the user hovers over the MenuItem
When the user clicks on the MenuItem
Then the right of the MenuItem is aligned with the left of the SubMenu
And the top of the MenuItem is aligned with the top of the SubMenu wrapper

Scenario: Flipped rendering when insufficient space to the right of
Given there is not enough space to the right of the MenuItem to fit the SubMenu
When the user hovers over the MenuItem
When the user clicks on the MenuItem
Then the left of the MenuItem is aligned with the right of the SubMenu
And the top of the MenuItem is aligned with the top of the SubMenu wrapper

Scenario: Shifting into view when insufficient space to the right of and above
Given there is not enough space to the right or the left of the MenuItem to fit the SubMenu
When the user hovers over the MenuItem
When the user clicks on the MenuItem
Then the SubMenu is rendered on top of the MenuItem
And the top of the MenuItem is aligned with the top of the SubMenu wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { Given, Then, When } from 'cypress-cucumber-preprocessor/steps'
Given(
'there is enough space to the right of the MenuItem to fit the SubMenu',
() => {
cy.visitStory('MenuItem', 'Default position')
cy.visitStory('FlyoutMenu', 'Default Position')
}
)

Given(
'there is not enough space to the right of the MenuItem to fit the SubMenu',
() => {
cy.visitStory('MenuItem', 'Flipped position')
cy.visitStory('FlyoutMenu', 'Flipped Position')
}
)

Given(
'there is not enough space to the right or the left of the MenuItem to fit the SubMenu',
() => {
cy.visitStory('MenuItem', 'Shift into view')
cy.visitStory('FlyoutMenu', 'Shift Into View')
}
)

When('the user hovers over the MenuItem', () => {
cy.get('[data-test="dhis2-uicore-menuitem"]').trigger('mouseover')
When('the user clicks on the MenuItem', () => {
cy.get('[data-test="dhis2-uicore-menuitem"]').click()
})

Then(
Expand Down Expand Up @@ -65,6 +65,6 @@ Then(
function getMenuItemAndSubMenuRects() {
return cy.getPositionsBySelectors(
'[data-test="dhis2-uicore-menuitem"]',
'[data-test="submenu"]'
'[data-test="dhis2-uicore-popper"]'
)
}
9 changes: 9 additions & 0 deletions cypress/integration/FlyoutMenu/toggles_submenus.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: The FlyoutMenu toggles SubMenus

Scenario: a FlyoutMenu with two SubMenus
Given a FlyoutMenu with two SubMenus is rendered
When the user clicks the first SubMenu anchor
Then first SubMenu is visible
When the user clicks the second SubMenu anchor
Then second SubMenu is visible
And the first SubMenu is not visible
26 changes: 26 additions & 0 deletions cypress/integration/FlyoutMenu/toggles_submenus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a FlyoutMenu with two SubMenus is rendered', () => {
cy.visitStory('FlyoutMenu', 'Toggles Sub Menus')
cy.get('[data-test="dhis2-uicore-menu"]').should('be.visible')
})

When('the user clicks the first SubMenu anchor', () => {
cy.contains('Item 1').click()
})

Then('first SubMenu is visible', () => {
cy.contains('SubMenu 1').should('be.visible')
})

When('the user clicks the second SubMenu anchor', () => {
cy.contains('Item 2').click()
})

Then('second SubMenu is visible', () => {
cy.contains('SubMenu 2').should('be.visible')
})

Then('the first SubMenu is not visible', () => {
cy.contains('SubMenu 1').should('not.be.visible')
})
5 changes: 0 additions & 5 deletions cypress/integration/Layer/click_behavior.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
Feature: The Layer has configurable click behaviour

Scenario: A non-blocking layer
Given a Layer with pointerEvents none and a button below it is rendered
When the user clicks the button
Then the onClick handler of the button is called

Scenario: A blocking layer
Given a Layer with a button below it is rendered
When the user clicks on the button coordinates
Expand Down
7 changes: 0 additions & 7 deletions cypress/integration/Layer/click_behavior/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given(
'a Layer with pointerEvents none and a button below it is rendered',
() => {
cy.visitStory('Layer', 'Non Blocking')
}
)

Given('a Layer with a button below it is rendered', () => {
cy.visitStory('Layer', 'Blocking')
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/Menu/accepts_children/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a Menu with children is rendered', () => {
cy.visitStory('Menu', 'With children')
cy.get('[data-test="dhis2-uicore-menu"]').should('be.visible')
cy.get('[data-test="dhis2-uicore-menulist"]').should('be.visible')
})

Then('the children are visible', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/MenuItem/accepts_href/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem with href is rendered', () => {
cy.visitStory('MenuItem', 'With href')
cy.visitStory('MenuItem', 'With Href')
})

Then('a link is rendered with the href', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/MenuItem/accepts_icon/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem supplied with an icon is rendered', () => {
cy.visitStory('MenuItem', 'With icon')
cy.visitStory('MenuItem', 'With Icon')
cy.get('[data-test="dhis2-uicore-menuitem"]').should('be.visible')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/MenuItem/accepts_label.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Feature: The MenuItem accepts a label prop

Scenario: MenuItem renders supplied label
Given a MenuItem supplied with a label is rendered
Then the label will be visible
Then the label is visible
6 changes: 3 additions & 3 deletions cypress/integration/MenuItem/accepts_label/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem supplied with a label is rendered', () => {
cy.visitStory('MenuItem', 'With label')
cy.visitStory('MenuItem', 'With Label')
cy.get('[data-test="dhis2-uicore-menuitem"]').should('be.visible')
})

Then('the label will be visible', () => {
cy.contains('Label').should('be.visible')
Then('the label is visible', () => {
cy.contains('label').should('be.visible')
})
2 changes: 1 addition & 1 deletion cypress/integration/MenuItem/accepts_target/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem with target is rendered', () => {
cy.visitStory('MenuItem', 'With target')
cy.visitStory('MenuItem', 'With Target')
})

Then('a link is rendered with the target', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/MenuItem/is_clickable/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem with onClick handler and value is rendered', () => {
cy.visitStory('MenuItem', 'With onClick and value')
cy.visitStory('MenuItem', 'With On Click And Value')
})

When('the MenuItem is clicked', () => {
Expand Down
5 changes: 0 additions & 5 deletions cypress/integration/MenuList/accepts_children.feature

This file was deleted.

10 changes: 0 additions & 10 deletions cypress/integration/MenuList/accepts_children/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions cypress/integration/MenuSectionHeader/accepts_label.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: The MenuSectionHeader accepts a label prop

Scenario: MenuSectionHeader renders supplied label
Given a MenuSectionHeader supplied with a label is rendered
Then the label is visible
10 changes: 10 additions & 0 deletions cypress/integration/MenuSectionHeader/accepts_label/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuSectionHeader supplied with a label is rendered', () => {
cy.visitStory('MenuSectionHeader', 'With Label')
cy.get('[data-test="dhis2-uicore-menusectionheader"]').should('be.visible')
})

Then('the label is visible', () => {
cy.contains('label').should('be.visible')
})
5 changes: 0 additions & 5 deletions packages/core/src/ComponentCover/ComponentCover.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const ComponentCover = ({
className,
dataTest,
onClick,
pointerEvents,
translucent,
}) => (
<div
Expand All @@ -40,7 +39,6 @@ const ComponentCover = ({
bottom: 0;
left: 0;
z-index: ${layers.applicationTop};
pointer-events: ${pointerEvents};
}
div.translucent {
background: rgba(33, 43, 54, 0.4);
Expand All @@ -51,7 +49,6 @@ const ComponentCover = ({

ComponentCover.defaultProps = {
dataTest: 'dhis2-uicore-componentcover',
pointerEvents: 'all',
}

/**
Expand All @@ -60,15 +57,13 @@ ComponentCover.defaultProps = {
* @prop {string} [className]
* @prop {Node} [children]
* @prop {string} [dataTest=dhis2-uicore-componentcover]
* @prop {string} [pointerEvents=all] - One of 'all', 'none'
* @prop {boolean} [translucent] - When true a semi-transparent background is added
* @prop {function} [onClick]
*/
ComponentCover.propTypes = {
children: propTypes.node,
className: propTypes.string,
dataTest: propTypes.string,
pointerEvents: propTypes.oneOf(['all', 'none']),
translucent: propTypes.bool,
onClick: propTypes.func,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ export const WithChildren = () => (
</ComponentCover>
)

export const NonBlocking = () => (
<>
<button onClick={window.onButtonClick}>Test</button>
<ComponentCover pointerEvents="none" />
</>
)

export const Blocking = () => (
<>
<button onClick={window.onButtonClick}>Test</button>
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/ComponentCover/ComponentCover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ export const WithClickHandler = () => (
</>
)

export const NonBlocking = () => (
<>
<ComponentCover translucent pointerEvents="none" />

<h1>Text behind the cover</h1>
<p>
You can still select this text because the cover has pointer-event:
none.
</p>
</>
)

export const WithCenteredContentCircularLoader = () => (
<>
<ComponentCover translucent>
Expand Down
Loading

0 comments on commit f12e960

Please sign in to comment.