Skip to content

Commit

Permalink
Merge branch 'main' into feature/132/refactor-address-input-test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar authored Sep 27, 2024
2 parents 5f6a1bb + 0b669c7 commit 7166e92
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 175 deletions.
2 changes: 1 addition & 1 deletion src/components/button/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{% else %}
type="{{ buttonType }}"
{% endif %}
class="ons-btn{{ ' ' + params.classes if params.classes else '' }}{% if params.variants and params.variants is not string %}{% for variant in params.variants %}{{ ' ' }}ons-btn--{{ variant }}{% endfor %}{% else %}{{ ' ' }}ons-btn--{{ params.variants }}{% endif %}{{ ' ons-btn--link ons-js-submit-btn' if params.url }}{{ variantClasses }}"
class="ons-btn{{ ' ' + params.classes if params.classes else '' }}{% if params.variants and params.variants is not string %}{% for variant in params.variants %}{{ ' ' }}ons-btn--{{ variant }}{% endfor %}{% elif params.variants %}{{ ' ' }}ons-btn--{{ params.variants }}{% endif %}{{ ' ons-btn--link ons-js-submit-btn' if params.url }}{{ variantClasses }}"
{% if params.id %}id="{{ params.id }}"{% endif %}
{% if params.value and tag != "a" %}value="{{ params.value }}"{% endif %}
{% if params.name and tag != "a" %}name="{{ params.name }}"{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/components/text-indent/example-text-indent.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% from "components/text-indent/_macro.njk" import onsTextIndent %}
{{-
onsTextIndent({
text: '<p>Telephone: 0800 141 2021<br>Monday to Friday, 8 am to 7pm<br>Saturday, 8am to 4pm</p>'
"text": '<p>Telephone: 0800 141 2021<br>Monday to Friday, 8 am to 7pm<br>Saturday, 8am to 4pm</p>'
})
-}}
12 changes: 6 additions & 6 deletions src/tests/helpers/cheerio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as cheerio from 'cheerio';
import * as helper from '../../tests/helpers/cheerio';

const EXAMPLE_HTML = `
<div>
<div id="a">First</div>
<div id="b" class="second">Second</div>
<div id="c" class="third">Third</div>
</div>
`;
<div>
<div id="a">First</div>
<div id="b" class="second">Second</div>
<div id="c" class="third">Third</div>
</div>
`;

describe('mapAll(cheerioNodes, selector)', () => {
it('gets mapped values`', () => {
Expand Down
118 changes: 59 additions & 59 deletions src/tests/helpers/puppeteer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ describe('PuppeteerEndpointFaker', () => {
});

const TEST_HTML_REQUEST_DATA_FROM_ENDPOINT = `
<div id="output"></div>
<script>
fetch('/test/fake/api/json/abc')
.then(async (response) => {
const data = await response.json();
const el = document.getElementById('output');
el.innerHTML = response.status + ':' + data.value;
el.classList.add('test');
});
</script>
`;
<div id="output"></div>
<script>
fetch('/test/fake/api/json/abc')
.then(async (response) => {
const data = await response.json();
const el = document.getElementById('output');
el.innerHTML = response.status + ':' + data.value;
el.classList.add('test');
});
</script>
`;

describe('get requestHistory()', () => {
it('has faked requests in history', async () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);

const paths = apiFaker.requestHistory.map((entry) => entry.path);
Expand All @@ -78,13 +78,13 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/text?abc=789');
fetch('/test/fake/api/other');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/text?abc=789');
fetch('/test/fake/api/other');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);

const paths = apiFaker.requestHistory.map((entry) => entry.path);
Expand All @@ -95,12 +95,12 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);

const paths = apiFaker.requestHistory.map((entry) => entry.path);
Expand All @@ -111,10 +111,10 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
</script>
`,
);

const entry = apiFaker.requestHistory.find((entry) => entry.path === '/text?abc=123');
Expand All @@ -125,14 +125,14 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123', {
headers: {
'foo': '123',
}
});
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123', {
headers: {
'foo': '123',
}
});
</script>
`,
);

const entry = apiFaker.requestHistory.find((entry) => entry.path === '/text?abc=123');
Expand All @@ -145,13 +145,13 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/text?abc=789');
fetch('/test/fake/api/other');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/text?abc=789');
fetch('/test/fake/api/other');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);

expect(apiFaker.requestedPaths).toEqual(['/text?abc=123', '/text?abc=789', '/other', '/json?abc=456']);
Expand All @@ -171,11 +171,11 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);
await apiFaker.reset();

Expand Down Expand Up @@ -299,12 +299,12 @@ describe('PuppeteerEndpointFaker', () => {
await setTestPage(
'/test',
`
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
fetch('/test/fake/api/json?abc=456');
</script>
`,
<script>
fetch('/test/fake/api/text?abc=123');
fetch('/test/fake/api/json?abc=456');
fetch('/test/fake/api/json?abc=456');
</script>
`,
);

expect(apiFaker.getRequestCount('/text?abc=123')).toBe(1);
Expand Down
30 changes: 15 additions & 15 deletions src/tests/helpers/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ export function renderComponent(componentName, params = {}, children = null, fak
if (!!children) {
return renderTemplate(
`
{% from "${info.templateName}" import ${info.macroName} %}
{%- call ${info.macroName}(${JSON.stringify(params, null, 2)}) -%}
${Array.isArray(children) ? children.join('') : children}
{%- endcall -%}
`,
{% from "${info.templateName}" import ${info.macroName} %}
{%- call ${info.macroName}(${JSON.stringify(params, null, 2)}) -%}
${Array.isArray(children) ? children.join('') : children}
{%- endcall -%}
`,
fakerContext,
isDesignSystemExample,
);
} else {
return renderTemplate(
`
{% from "${info.templateName}" import ${info.macroName} %}
{{- ${info.macroName}(${JSON.stringify(params, null, 2)}) -}}
`,
{% from "${info.templateName}" import ${info.macroName} %}
{{- ${info.macroName}(${JSON.stringify(params, null, 2)}) -}}
`,
fakerContext,
isDesignSystemExample,
);
Expand All @@ -66,9 +66,9 @@ export function renderComponent(componentName, params = {}, children = null, fak

export function renderBaseTemplate(config) {
const compositedTemplate = `
{% extends 'layout/_template.njk' %}
${config}
`;
{% extends 'layout/_template.njk' %}
${config}
`;

return renderTemplate(compositedTemplate);
}
Expand Down Expand Up @@ -172,10 +172,10 @@ export async function setTestPage(path, template, blockName = 'body') {
verifyConsoleSubscription(page);

const compositedTemplate = `
{% block ${blockName} %}
${template}
{% endblock %}
`;
{% block ${blockName} %}
${template}
{% endblock %}
`;

const html = renderBaseTemplate(compositedTemplate);

Expand Down
Loading

0 comments on commit 7166e92

Please sign in to comment.