-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ffb1d9
commit 9d22d95
Showing
8 changed files
with
234 additions
and
6 deletions.
There are no files selected for viewing
Binary file added
BIN
+8.94 KB
cypress-visual-screenshots/baseline/Clipboard.cy.tsx-clipboard-error-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.98 KB
...al-screenshots/baseline/Clipboard.cy.tsx-clipboard-raw-content-success-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.94 KB
cypress-visual-screenshots/baseline/Clipboard.cy.tsx-clipboard-success-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.94 KB
...sual-screenshots/baseline/Clipboard.cy.tsx-clipboard-with-displayed-content.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.98 KB
...isual-screenshots/baseline/Clipboard.cy.tsx-clipboard-with-only-raw-content.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,206 @@ | ||
import '../../../src/global.css'; | ||
import React from 'react'; | ||
import { Clipboard } from '../../../src/components'; | ||
import { compareSnapshot } from '../../compareSnapshot'; | ||
|
||
describe('Component | Integration | Clipboard', function () { | ||
describe('Clipboard', () => { | ||
describe('clipboard with only raw-content', () => { | ||
it('should render', () => { | ||
cy.mount(<Clipboard rawContent={'raw content'} />); | ||
|
||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains('raw content'); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
cy.mount(<Clipboard rawContent={'raw content'} />); | ||
compareSnapshot(cy, 'clipboard-with-only-raw-content'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Clipboard', () => { | ||
describe('clipboard with diplayed content', () => { | ||
it('should render', () => { | ||
cy.mount( | ||
<Clipboard | ||
rawContent={'raw content'} | ||
displayedContent={'formatted content'} | ||
/>, | ||
); | ||
|
||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains( | ||
'formatted content', | ||
); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
cy.mount( | ||
<Clipboard | ||
rawContent={'raw content'} | ||
displayedContent={'formatted content'} | ||
/>, | ||
); | ||
compareSnapshot(cy, 'clipboard-with-displayed-content'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Clipboard', () => { | ||
describe('clipboard success flow', () => { | ||
it('should render', () => { | ||
cy.mount( | ||
<Clipboard | ||
rawContent={'raw content'} | ||
success="Copied!" | ||
displayedContent={'formatted content'} | ||
/>, | ||
); | ||
|
||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains( | ||
'formatted content', | ||
); | ||
}); | ||
|
||
it('should fire the copy clipboard function', () => { | ||
cy.mount( | ||
<Clipboard | ||
rawContent={'raw content'} | ||
success="Copied!" | ||
displayedContent={'formatted content'} | ||
/>, | ||
); | ||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains( | ||
'formatted content', | ||
); | ||
cy.on('window:confirm', () => true); | ||
|
||
cy.window().then((win) => { | ||
cy.stub(win, 'prompt') | ||
.returns(win.prompt) | ||
.as('copyToClipboardPrompt'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-field"]').click(); | ||
cy.get('@copyToClipboardPrompt').should('be.called'); | ||
|
||
cy.get('@copyToClipboardPrompt') | ||
.should((prompt) => { | ||
expect(prompt.args[0][1]).to.equal('raw content'); | ||
}) | ||
.then(() => { | ||
cy.get('[data-testid="clipboard-input-message"]') | ||
.should('exist') | ||
.contains('Copied!'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-input-message"]').should('not.exist'); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
cy.mount( | ||
<Clipboard | ||
rawContent={'raw content'} | ||
success="Copied!" | ||
displayedContent={'formatted content'} | ||
/>, | ||
); | ||
compareSnapshot(cy, 'clipboard-success-flow'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Clipboard', () => { | ||
describe('clipboard raw content success flow', () => { | ||
it('should render', () => { | ||
cy.mount(<Clipboard rawContent={'raw content'} success="Copied!" />); | ||
|
||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains('raw content'); | ||
}); | ||
|
||
it('should fire the copy clipboard function', () => { | ||
cy.mount(<Clipboard rawContent={'raw content'} success="Copied!" />); | ||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]').contains('raw content'); | ||
cy.on('window:confirm', () => true); | ||
|
||
cy.window().then((win) => { | ||
cy.stub(win, 'prompt') | ||
.returns(win.prompt) | ||
.as('copyToClipboardPrompt'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-field"]').click(); | ||
cy.get('@copyToClipboardPrompt').should('be.called'); | ||
|
||
cy.get('@copyToClipboardPrompt') | ||
.should((prompt) => { | ||
expect(prompt.args[0][1]).to.equal('raw content'); | ||
}) | ||
.then(() => { | ||
cy.get('[data-testid="clipboard-input-message"]') | ||
.should('exist') | ||
.contains('Copied!'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-input-message"]').should('not.exist'); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
cy.mount(<Clipboard rawContent={'raw content'} success="Copied!" />); | ||
compareSnapshot(cy, 'clipboard-raw-content-success-flow'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Clipboard', () => { | ||
describe('clipboard error flow', () => { | ||
it('should render', () => { | ||
cy.mount(<Clipboard rawContent={''} error="Oupps!" />); | ||
|
||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]') | ||
.contains('foo') | ||
.should('not.exist'); | ||
}); | ||
|
||
it('should not fire the copy clipboard function', () => { | ||
cy.mount(<Clipboard rawContent={''} error="Oupps!" />); | ||
cy.get('[data-testid="clipboard-field"]').should('exist'); | ||
cy.get('[data-testid="clipboard-content"]') | ||
.contains('foo') | ||
.should('not.exist'); | ||
cy.on('window:confirm', () => true); | ||
|
||
cy.window().then((win) => { | ||
cy.stub(win, 'prompt') | ||
.returns(win.prompt) | ||
.as('copyToClipboardPrompt'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-copy-icon"]').click(); | ||
cy.get('@copyToClipboardPrompt') | ||
.should('not.be.called') | ||
.then(() => { | ||
cy.get('[data-testid="clipboard-input-message"]') | ||
.should('exist') | ||
.contains('Oupps!'); | ||
}); | ||
|
||
cy.get('[data-testid="clipboard-input-message"]').should('not.exist'); | ||
}); | ||
|
||
// We are not testing snapshots here because we know it will fail due to the absence of raw content | ||
|
||
// it('should match snapshot', () => { | ||
// cy.mount(<Clipboard rawContent={''} error="Oupps!" />); | ||
// compareSnapshot(cy 'clipboard-error-flow'); | ||
// }); | ||
}); | ||
}); | ||
}); |
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