-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ui-drawer-layout): migrate old DrawerLayout tests
Closes: INSTUI-4206
- Loading branch information
1 parent
ff2618e
commit e1a4af5
Showing
14 changed files
with
644 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
import React from 'react' | ||
import { expect } from 'chai' | ||
|
||
import '../support/component' | ||
import { px, within } from '@instructure/ui-utils' | ||
import DrawerLayoutFixture from '../../packages/ui-drawer-layout/src/DrawerLayout/__fixtures__/DrawerLayout.fixture' | ||
|
||
describe('<DrawerLayout/>', () => { | ||
it('with no overlay, layout content should have margin equal to tray width with placement=start', () => { | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="800px" | ||
trayWidth="250px" | ||
placement="start" | ||
/> | ||
) | ||
|
||
cy.contains('div', 'Hello from tray').then(($tray) => { | ||
const trayWidth = px($tray.css('width')) | ||
|
||
cy.get('div[class$="-drawerLayout__content"]').should(($content) => { | ||
const marginLeft = px($content.css('margin-left')) | ||
|
||
expect(within(marginLeft, 250, 2)).to.equal(true) | ||
expect(marginLeft).to.equal(trayWidth) | ||
}) | ||
}) | ||
}) | ||
|
||
it(`with no overlay, layout content should have margin equal to tray width with placement=end`, async () => { | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
placement="end" | ||
layoutWidth="800px" | ||
trayWidth="250px" | ||
/> | ||
) | ||
|
||
cy.contains('div', 'Hello from tray').then(($tray) => { | ||
const trayWidth = px($tray.css('width')) | ||
|
||
cy.get('div[class$="-drawerLayout__content"]').should(($content) => { | ||
const marginRight = px($content.css('margin-right')) | ||
|
||
expect(within(marginRight, 250, 2)).to.equal(true) | ||
expect(marginRight).to.equal(trayWidth) | ||
}) | ||
}) | ||
}) | ||
|
||
it(`with overlay, layout content should have a margin of zero with placement=start`, async () => { | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="700px" | ||
trayWidth="250px" | ||
placement="start" | ||
/> | ||
) | ||
|
||
cy.get('div[class$="-drawerLayout__content"]').should(($content) => { | ||
const marginLeft = px($content.css('margin-left')) | ||
|
||
expect(marginLeft).to.equal(0) | ||
}) | ||
}) | ||
|
||
it(`with overlay, layout content should have a margin of zero with placement=end`, async () => { | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
placement="end" | ||
layoutWidth="700px" | ||
trayWidth="250px" | ||
/> | ||
) | ||
|
||
cy.get('div[class$="-drawerLayout__content"]').should(($content) => { | ||
const marginRight = px($content.css('margin-right')) | ||
|
||
expect(marginRight).to.equal(0) | ||
}) | ||
}) | ||
|
||
it('the tray should overlay the content when the content is less than the minWidth', async () => { | ||
const onOverlayTrayChange = cy.spy() | ||
|
||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="800px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
// set prop layoutWidth | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="295px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
cy.wrap(onOverlayTrayChange).should('have.been.calledWith', true) | ||
}) | ||
|
||
it('the tray should stop overlaying the content when there is enough space for the content', async () => { | ||
const onOverlayTrayChange = cy.spy() | ||
|
||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="400px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
// set prop layoutWidth | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="705px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
cy.wrap(onOverlayTrayChange).should('have.been.calledWith', false) | ||
}) | ||
|
||
it('the tray should be set to overlay when it is opened and there is not enough space', async () => { | ||
const onOverlayTrayChange = cy.spy() | ||
|
||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="295px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
// set prop open | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="295px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
cy.wrap(onOverlayTrayChange).should('have.been.calledWith', true) | ||
}) | ||
|
||
it('the tray should not overlay on open when there is enough space', async () => { | ||
const onOverlayTrayChange = cy.spy() | ||
|
||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="705px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
// set prop open | ||
cy.mount( | ||
<DrawerLayoutFixture | ||
open={true} | ||
layoutWidth="705px" | ||
onOverlayTrayChange={onOverlayTrayChange} | ||
/> | ||
) | ||
|
||
cy.wrap(onOverlayTrayChange).should('have.been.calledWith', false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
import React from 'react' | ||
|
||
import '../support/component' | ||
import canvas from '@instructure/ui-themes' | ||
import { | ||
DrawerLayoutContext, | ||
DrawerTray | ||
} from '@instructure/ui-drawer-layout/src/DrawerLayout' | ||
import { InstUISettingsProvider } from '@instructure/emotion' | ||
|
||
describe('<DrawerTray/>', () => { | ||
it('should render tray content when open', async () => { | ||
cy.mount( | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
open={true} | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
) | ||
cy.get('div[class$="-drawerTray__content"]').should( | ||
'have.text', | ||
'Hello from layout tray' | ||
) | ||
}) | ||
|
||
it('should not render tray content when closed', async () => { | ||
cy.mount( | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
) | ||
cy.get('div[class$="-drawerTray__content"]').should('not.exist') | ||
}) | ||
|
||
it(`should place the tray correctly with placement=start`, async () => { | ||
cy.mount( | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
open={true} | ||
placement="start" | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
) | ||
cy.get('div[class$="-drawerTray__content"]') | ||
.parent() | ||
.should('have.css', 'left', '0px') | ||
}) | ||
|
||
it(`should place the tray correctly with placement=end`, async () => { | ||
cy.mount( | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
open={true} | ||
placement="end" | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
) | ||
cy.get('div[class$="-drawerTray__content"]') | ||
.parent() | ||
.should('have.css', 'right', '0px') | ||
}) | ||
|
||
it('should apply theme overrides when open', async () => { | ||
cy.mount( | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
open={true} | ||
themeOverride={{ zIndex: 333 }} | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
) | ||
cy.get('div[class$="-drawerTray__content"]') | ||
.parent() | ||
.should('have.css', 'z-index', '333') | ||
}) | ||
|
||
it('drops a shadow if the prop is set, and it is overlaying content', async () => { | ||
const onEntered = cy.spy() | ||
cy.mount( | ||
<DrawerLayoutContext.Provider value={true}> | ||
<InstUISettingsProvider theme={canvas}> | ||
<DrawerTray | ||
label="DrawerTray Example" | ||
open={true} | ||
shadow={true} | ||
onEntered={onEntered} | ||
render={() => { | ||
return 'Hello from layout tray' | ||
}} | ||
/> | ||
</InstUISettingsProvider> | ||
</DrawerLayoutContext.Provider> | ||
) | ||
cy.get('div[class*="-drawerTray--with-shadow"]').should( | ||
'have.css', | ||
'box-shadow' | ||
) | ||
cy.get('div[class*="-drawerTray--with-shadow"]').should( | ||
'not.have.css', | ||
'box-shadow', | ||
'none' | ||
) | ||
}) | ||
}) |
Oops, something went wrong.