Skip to content

Commit

Permalink
tests - in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
meganthecoder committed Jan 22, 2024
1 parent 86bf7d7 commit d8e88d6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
8 changes: 4 additions & 4 deletions scripts/aa-university.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function registerAAUniversity() {
university: 'none',
country: country?.value,
}),
});
// .catch((error) => {
// window.lana.log('Marketo AA University Error:', error);
// });
})
.catch((error) => {
window.lana.log('Marketo AA University Error:', error);
});
}
3 changes: 2 additions & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ const miloLibs = setLibs(LIBS);
await loadArea();

if (document.querySelector('meta[name="aa-university"]')) {
console.log('boop');
const { default: registerAAUniversity } = await import('./aa-university.js');
window.addEventListener('mktoSubmit', registerAAUniversity);
window.addEventListener('mktoSubmit', () => console.log('mktoSubmit'));
}
}());
20 changes: 13 additions & 7 deletions test/scripts/mocks/body.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<input name="FirstName">Jane</input>
<input name="LastName">Doe</input>
<input name="Email">[email protected]</input>
<select name="Country">
<option value="US" selected>United States</option>
<option value="GB">United Kingdom</option>
</select>
<header></header>
<main>
<div>
<input name="FirstName">Jane</input>
<input name="LastName">Doe</input>
<input name="Email">[email protected]</input>
<select name="Country">
<option value="US" selected>United States</option>
<option value="GB">United Kingdom</option>
</select>
</div>
</main>
<footer></footer>
6 changes: 6 additions & 0 deletions test/scripts/mocks/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<link rel="icon" href="data:,">
<meta name="aa-university" content="on">
<meta name="georouting" content="off">
<meta name="martech" content="off">
<meta name="header" content="off">
<meta name="footer" content="off">
21 changes: 21 additions & 0 deletions test/scripts/scripts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import { mockFetch } from '../helpers/generalHelpers.js';

const ogFetch = window.fetch;

document.body.innerHTML = await readFile({ path: './mocks/body.html' });
document.head.innerHTML = await readFile({ path: './mocks/head.html' });

describe('Scripts', async () => {
before(async () => {
await import('../../scripts/scripts.js');
});

it('Registers user into AA University', async () => {
window.fetch = mockFetch();
window.dispatchEvent(new Event('mktoSubmit'));
expect(window.fetch.called).to.be.true;
window.fetch = ogFetch;
});
});
1 change: 0 additions & 1 deletion web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default {
'**/node_modules/**',
'**/test/**',
'**/deps/**',
'**/scripts/**',
],
},
plugins: [importMapsPlugin({})],
Expand Down

0 comments on commit d8e88d6

Please sign in to comment.