-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event-listener-fixes): fix an issue where "click.delegate" event…
…s don't fire because the listener is on the test spec iframe and not the app iframe (#7) * feat(event-listener-fixes): fix an issue where "click.delegate" events don't fire because the listener is on the test spec iframe and not the app iframe - add my-button component to test click.delegate - update cypress.json to not process videos if the tests pass (ie. they'll run a lot faster) and add fixed resolution (720p) - update @cypress/webpack-preprocesser so it won't hang in continuous integration anymore - update css-modules-typescript-loader to avoid infinite loop reloading when using "cypress open" mode and modifying styles - remove google-closure-compiler dependency as it's unused * fix(my-button): add missing semicolon
- Loading branch information
1 parent
aa44821
commit 3f68b5a
Showing
10 changed files
with
228 additions
and
273 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"watchForFileChanges": true | ||
"viewportWidth": 1280, | ||
"viewportHeight": 720, | ||
"videoUploadOnPasses": 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
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,22 @@ | ||
import { PLATFORM } from 'aurelia-framework'; | ||
import { bootstrap } from 'aurelia-bootstrapper'; | ||
import { StageComponent } from 'cypress-aurelia-unit-test'; | ||
|
||
import { MyButton } from '~/my-button/my-button'; | ||
|
||
describe('Button', () => { | ||
it('Test click.delegate() has event listeners have been applied to app iframe from the spec iframe by "event-listener-fixes" in lib.', () => { | ||
const component = StageComponent | ||
.withResources<MyButton>(PLATFORM.moduleName('my-button/my-button')) | ||
.inView(` | ||
<my-button | ||
value.bind="value" | ||
></my-button>`) | ||
.boundTo({ | ||
value: 'Delegate click test' | ||
}); | ||
component.create(bootstrap); | ||
cy.get('button').click(); | ||
cy.get('p').contains('Button clicked!'); | ||
}); | ||
}); |
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,39 @@ | ||
/** | ||
* copyEventHandlesFromSpecToAppIFrame will fix an issue where certain events aren't on | ||
* the app iframe context. Without this code, certain features like "click.delegate" won't | ||
* work in Aurelia templates. | ||
*/ | ||
function copyEventHandlesFromSpecIFrameToAppIFrame(): void { | ||
const specIframe = window.parent.document.querySelector('iframe.spec-iframe'); | ||
if (!specIframe) { | ||
throw new Error('Cannot find .spec-iframe'); | ||
} | ||
const specDocument: Document = (specIframe as any).contentDocument; | ||
if (!specDocument) { | ||
throw new Error('Cannot find contentDocument on specIframe'); | ||
} | ||
|
||
const rootDocument = window.parent.document; | ||
const appIframe = rootDocument.querySelector('iframe.aut-iframe'); | ||
if (!appIframe) { | ||
throw new Error('Cannot find .aut-iframe'); | ||
} | ||
const appDocument: Document = (appIframe as any).contentDocument; | ||
if (!appDocument) { | ||
throw new Error('Cannot find contentDocument on appIframe'); | ||
} | ||
|
||
// Override addEventListener on spec iframe so that we can attach those | ||
// same events to the app iframe, this fixes: | ||
// - aurelia-binding - click.delegate won't work in templates without this. | ||
const originalEventListener = specDocument.addEventListener; | ||
const addEventListener = function(this: any): void { | ||
originalEventListener.apply(this, arguments as any); | ||
appDocument.addEventListener.apply(appDocument, arguments as any); | ||
}; | ||
if (specDocument.addEventListener !== addEventListener) { | ||
specDocument.addEventListener = addEventListener; | ||
} | ||
} | ||
|
||
before(copyEventHandlesFromSpecIFrameToAppIFrame); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import './event-listener-fixes'; | ||
export * from './component-tester'; |
Oops, something went wrong.