-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Antonio
authored
Feb 25, 2021
1 parent
9c83413
commit b3d6694
Showing
12 changed files
with
146 additions
and
31 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
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 |
---|---|---|
@@ -1,16 +1,42 @@ | ||
describe('Widget', () => { | ||
before(() => { | ||
cy.visit('/widget-js.html') | ||
}) | ||
testWidget('js') | ||
testWidget('html') | ||
}) | ||
|
||
it('should display widget', () => { | ||
cy.get('.typeform-widget iframe').should('be.visible') | ||
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('contain', 'form.typeform.com/to/') | ||
}) | ||
function testWidget(type = 'html') { | ||
describe(`Widget ${type}`, () => { | ||
before(() => { | ||
cy.visit(`/widget-${type}.html`) | ||
}) | ||
|
||
it('should display widget', () => { | ||
cy.get('.typeform-widget iframe').should('be.visible') | ||
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('contain', 'form.typeform.com/to/') | ||
}) | ||
|
||
it('should pass options as query param', () => { | ||
cy.get('.typeform-widget iframe') | ||
.invoke('attr', 'src') | ||
.should('contain', 'typeform-embed=embed-widget&typeform-source=localhost&typeform-medium=unit-test') | ||
}) | ||
|
||
it('should pass options as query param', () => { | ||
cy.get('.typeform-widget iframe') | ||
.invoke('attr', 'src') | ||
.should('contain', 'typeform-embed=embed-widget&typeform-source=localhost&typeform-medium=unit-test') | ||
describe(`Widget ${type} With Parameters`, () => { | ||
before(() => { | ||
cy.visit(`/widget-${type}.html?foo=foo&bar=bar&baz=baz`) | ||
}) | ||
|
||
it('should display widget', () => { | ||
cy.get('.typeform-widget iframe').should('be.visible') | ||
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('contain', 'form.typeform.com/to/') | ||
}) | ||
|
||
it('should pass params from options to the iframe', () => { | ||
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('contain', 'foo=foo&bar=bar') | ||
}) | ||
|
||
it('should not pass params not in the list to the iframe', () => { | ||
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('not.contain', 'baz=baz') | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
packages/embed/src/utils/get-transitive-search-params.spec.ts
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,29 @@ | ||
import { getTransitiveSearchParams } from './get-transitive-search-params' | ||
|
||
describe('transferUrlParametersToQueryStrings', () => { | ||
const location: Location = window.location | ||
|
||
beforeAll(() => { | ||
delete (window as any).location | ||
const search = | ||
'?foo=jason&bar=rachel&utm_medium=cpc&utm_campaign=camp2008&utm_source=instagram&embed-hide-footer=false' | ||
|
||
window.location = { | ||
search, | ||
href: `http://localhost/${search}`, | ||
} as any | ||
}) | ||
|
||
afterAll(() => { | ||
window.location = location | ||
}) | ||
|
||
it('transfer the parameters of the URL in the query strings', () => { | ||
const urlParameters = ['foo', 'bar'] | ||
const queryStringWithTransferedUrlParameters = getTransitiveSearchParams(urlParameters) | ||
expect(queryStringWithTransferedUrlParameters).toEqual({ | ||
foo: 'jason', | ||
bar: 'rachel', | ||
}) | ||
}) | ||
}) |
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,14 @@ | ||
export const getTransitiveSearchParams = (transitiveSearchParams?: string[]) => { | ||
const url = new URL(window.location.href) | ||
const queryParamsWithTransitiveParams = {} | ||
|
||
if (transitiveSearchParams && transitiveSearchParams.length > 0) { | ||
transitiveSearchParams.forEach((key: string) => { | ||
if (url.searchParams.has(key)) { | ||
queryParamsWithTransitiveParams[key] = url.searchParams.get(key) | ||
} | ||
}) | ||
} | ||
|
||
return queryParamsWithTransitiveParams | ||
} |
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