Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/localization escape #32

Merged
merged 3 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [12]
node: [14]

steps:
- uses: actions/setup-node@v2
Expand Down
11 changes: 5 additions & 6 deletions example/cypress/integration/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

describe("Snipcart", () => {
it("snipcart element should have been injected", () => {
cy.visit("/");
cy.server()
cy.route({
cy.intercept({
method: "GET",
url: "https://cdn.snipcart.com/**"
url: "https://app.snipcart.com/api/sessions"
}).as("apiCheck");

cy.wait('@apiCheck')
cy.wait(1000)
cy.visit("/");

cy.wait("@apiCheck");

cy.get('[data-item-custom1-name="Frame color"]').should('exist')
cy.get('[data-item-custom5-name="Readonly information"]').should('exist')
Expand Down
22 changes: 20 additions & 2 deletions example/cypress/integration/injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@

describe('Snipcart', () => {
it('snipcart element should have been injected', () => {
cy.intercept({
method: "GET",
url: "https://app.snipcart.com/api/sessions"
}).as("apiCheck");

cy.intercept({
method: "GET",
url: "https://cdn.snipcart.com/themes/*/default/snipcart.js"
}).as("jsCheck");

cy.intercept({
method: "GET",
url: "https://cdn.snipcart.com/themes/*/default/snipcart.css"
}).as("cssCheck");

cy.visit('/')

cy.wait("@apiCheck");
cy.wait("@jsCheck");
cy.wait("@cssCheck");


cy.get('html').then((el) => {
const html = el[0].innerHTML

Expand All @@ -26,8 +46,6 @@ describe('Snipcart', () => {
);
})

cy.wait(1000)

cy.get('html').then((el) => {
const html = el[0].innerHTML;

Expand Down
13 changes: 6 additions & 7 deletions example/cypress/integration/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

describe("Snipcart", () => {
it("snipcart element should have been injected", () => {
cy.visit("/");
cy.server();
cy.route({
cy.intercept({
method: "GET",
url: "https://cdn.snipcart.com/**"
url: "https://app.snipcart.com/api/sessions"
}).as("apiCheck");

cy.visit("/");

cy.wait("@apiCheck");
cy.wait(1000)

cy.get(".snipcart-add-item").trigger("click");

cy.get(".snipcart-modal__container").should("contain", "Total fr");
cy.get(".snipcart-modal__container").should("contain", "We're Total fr");

cy.get(".snipcart-modal__close-title").trigger('click');

cy.get(".switch-lang").trigger('click');

cy.get(".snipcart-checkout").trigger('click');

cy.get(".snipcart-modal__container").should("contain", "Total en");
cy.get(".snipcart-modal__container").should("contain", "We're Total en");

});
});
4 changes: 2 additions & 2 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default {
locales: {
fr: {
cart_summary: {
total: 'Total fr'
total: 'We\'re Total fr'
}
},
en: {
cart_summary: {
total: 'Total en'
total: "We're Total en"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ module.exports = function (moduleOptions) {
}
)

let str = JSON.stringify(options.locales)
str = str.replace(/'/g, "\\\\'")
options.locales = JSON.parse(str)

this.addPlugin({
src: path.resolve(__dirname, 'plugin.js'),
options
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"lint": "eslint --ext .js,.vue .",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && yarn test:e2e",
"test:e2e": "cd example && yarn cypress:run"
"test:e2e": "cd example && yarn cypress:run",
"cypress:open": "cd example && yarn open"
},
"devDependencies": {
"@babel/core": "latest",
Expand All @@ -31,7 +32,7 @@
"@nuxtjs/module-test-utils": "latest",
"babel-eslint": "latest",
"chai": "latest",
"cypress": "^7.1.0",
"cypress": "^8.6.0",
"eslint": "latest",
"husky": "latest",
"nuxt": "latest",
Expand Down