docbrown/cypress/integration/loggedOutFlows/runtimeBannerDeepLinking.spec.js
Fernando Valverde affc704c9b
Runtime Banner for Mobile Deep Linking (#13190)
* First version using custom schemes for iOS

* Starting to take shape with /r/mobile redirect page

* Wording and aasa

* Adds e2e tests

* Trigger CI

* Tweaks to AASA

* Uses external pivot domain to trigger Universal Links

* Add missing external domain deep link

* Fix test by enabling runtime_banner only in E2E tests

* Fix URL encoding mismatch in Cypress test

* banner sttyling

* Cleanup unrelated changes

* Add AASA tests + remove lingering Gemfile.lock changes

* Fix cypress test

* Remove unnecessary window global assignment

* Trigger Travis

* Replace querySelectorAll with querySelector

* Apply suggestions from code review

Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>

* Refactor inline comments, extract URL.deep_link logic and other review feedback

* Small tweaks

* Remove untrusted user-provided redirect (CodeQL suggestion)

* Fix failing tests

* Whoops - another test fix

* Use Forem's UDL server

* Extract timeoutDelay and add comment clarifying

* Add target='_blank' to deep link

* Add TODO comment for replacing hardcoded identifiers

* Apply suggestions from code review

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Add a11y attributes

Co-authored-by: Paweł Ludwiczak <ludwiczakpawel@gmail.com>
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2021-04-23 15:45:34 -06:00

72 lines
2.6 KiB
JavaScript

describe('Runtime Banner Deep Linking', () => {
const runtimeStub = {
onBeforeLoad: (win) => {
Object.defineProperty(win.navigator, 'userAgent', {
value:
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1',
});
Object.defineProperty(win.navigator, 'platform', { value: 'iPhone' });
},
};
beforeEach(() => {
cy.testSetup();
cy.visit(`/`, runtimeStub);
});
it('should include the correct deep_link param in the banner link', () => {
// When visiting the root path the banner should deep link into it
cy.get('.runtime-banner > a')
.should('have.attr', 'href')
.and('contains', `deep_link%3D%2F`);
// NOTE: %3D%2F -> '=/' (URL Encoded)
// When visiting `/tags` the banner should deep link into `/tags`
cy.visit('/tags', runtimeStub).then(() => {
cy.get('.runtime-banner > a')
.should('have.attr', 'href')
.and('contains', `deep_link%3D%2Ftags`);
// NOTE: %3D%2Ftags -> '=/tags' (URL Encoded)
});
});
it('should redirect to custom scheme when someone taps on the banner', () => {
const deepLinkPath = '/custom_path';
const launchCustomSchemeDeepLinkStub = (url) => {
expect(url).to.eq(`com.forem.app:/${deepLinkPath}`);
};
cy.window()
.then((win) => {
cy.stub(
win,
'launchCustomSchemeDeepLink',
launchCustomSchemeDeepLinkStub,
);
})
.then(() => {
// After visiting the deep link redirect page (`/r/mobile`) it should
// immediately trigger the custom scheme, which gets caught by the stub
cy.visit(`/r/mobile?deep_link=${deepLinkPath}`);
});
});
it('should show a loading spinner and then the fallback page', () => {
const deepLinkPath = '/custom_path2';
cy.visit(`/r/mobile?deep_link=${deepLinkPath}`)
.then(() => {
// The loading spinner appears with the following text
cy.get('p').contains('Opening the mobile app...').should('be.visible');
})
.then(() => {
// After 3 seconds the following options appear visible
cy.get('p')
.contains('Whoops! Did you get stuck trying to open the mobile app?')
.should('be.visible');
cy.get('a').contains('Take me back').should('be.visible');
cy.get('a').contains('Try again').should('be.visible');
cy.get('a').contains('Install the app').should('be.visible');
// Also the loading text should not exist anymore
cy.get('p').contains('Opening the mobile app...').should('not.exist');
});
});
});