-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-141104: Consume Milo SWC in the unit tests (#157)
- Loading branch information
Showing
8 changed files
with
206 additions
and
68 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
test/blocks/sidenav/mocks/sidenav.html → test/blocks/sidenav/sidenav.test.html
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { runTests } from '@web/test-runner-mocha'; | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import sinon from 'sinon'; | ||
import { setLibs } from '../../../creativecloud/scripts/utils.js'; | ||
|
||
setLibs('/node_modules/@adobecom/milo/libs', true); | ||
|
||
const { default: init } = await import('../../../creativecloud/blocks/sidenav/sidenav.js'); | ||
|
||
const taxoString = await readFile({ path: './mocks/taxonomy.json' }); | ||
const taxonomy = JSON.parse(taxoString); | ||
|
||
const mockedTaxonomy = ({ | ||
payload = taxonomy, | ||
status = 200, ok = true, | ||
} = {}) => new Promise((resolve) => { | ||
resolve({ | ||
status, | ||
ok, | ||
json: () => payload, | ||
text: () => payload, | ||
}); | ||
}); | ||
|
||
runTests(async () => { | ||
describe('Sidenav', () => { | ||
beforeEach(() => { | ||
window.fetch = sinon.stub().callsFake(() => mockedTaxonomy()); | ||
}); | ||
|
||
const testCategorySidenav = async (selector, expectedItemCount, expectedChildItemCount) => { | ||
const sidenavEl = document.querySelector(selector); | ||
const newRoot = await init(sidenavEl); | ||
expect(newRoot.tagName).to.equal('MERCH-SIDENAV'); | ||
expect(newRoot.title).to.equal('REFINE YOUR RESULTS'); | ||
const items = newRoot.querySelectorAll('sp-sidenav-item'); | ||
expect(items.length).to.equal(expectedItemCount); | ||
const search = newRoot.querySelector('sp-search'); | ||
expect(search.getAttribute('placeholder')).to.equal('Search all your products'); | ||
expect(newRoot.querySelectorAll('sp-checkbox').length).to.equal(3); | ||
const nestedItems = newRoot.querySelectorAll('sp-sidenav-item > sp-sidenav-item'); | ||
expect(nestedItems.length).to.equal(expectedChildItemCount); | ||
expect(newRoot.querySelector('sp-checkbox').textContent.trim()).to.equal('Desktop'); | ||
}; | ||
|
||
it('does create nice categories default sidenav', async () => { | ||
await testCategorySidenav('.categories', 24, 18); | ||
}); | ||
|
||
it('does create nice reordered categories sidenav', async () => { | ||
await testCategorySidenav('.reordered-categories', 17, 11); | ||
}); | ||
|
||
it('does create nice plans sidenav', async () => { | ||
const sidenavEl = document.querySelector('.plans'); | ||
const newRoot = await init(sidenavEl); | ||
expect(newRoot.tagName).to.equal('MERCH-SIDENAV'); | ||
expect(newRoot.title).to.equal('REFINE YOUR RESULTS'); | ||
const search = newRoot.querySelector('sp-search'); | ||
expect(search).to.be.null; | ||
const nestedItems = newRoot.querySelectorAll('sp-sidenav-item > sp-sidenav-item'); | ||
expect(nestedItems.length).to.equal(0); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { importMapsPlugin } from '@web/dev-server-import-maps'; | ||
|
||
async function enableCORS(context, next) { | ||
await next(); | ||
context.set('Access-Control-Allow-Credentials', true); | ||
context.set('Access-Control-Allow-Origin', context.request.headers.origin); | ||
} | ||
|
||
const swcImportMaps = Object.fromEntries([ | ||
'theme.js', | ||
'search.js', | ||
'checkbox.js', | ||
'dialog.js', | ||
'base.js', | ||
'reactive-controllers.js', | ||
'shared.js', | ||
'textfield.js', | ||
'button.js', | ||
'icons-workflow.js', | ||
'icons-ui.js', | ||
'checkmark.js', | ||
'dash.js', | ||
'divider.js', | ||
'button-group.js', | ||
'alert-dialog.js', | ||
'underlay.js', | ||
'help-text.js', | ||
'icon.js', | ||
'icons/checkmark.js', | ||
'icons/dash.js', | ||
].map((file) => [`/libs/features/spectrum-web-components/dist/${file}`, `/node_modules/@adobecom/milo/libs/features/spectrum-web-components/dist/${file}`])); | ||
|
||
export default { | ||
coverageConfig: { | ||
include: ['src/**'], | ||
exclude: ['test/mocks/**', 'test/**', '**/node_modules/**'], | ||
}, | ||
debug: false, | ||
files: ['test/**/*.test.(js|html)'], | ||
nodeResolve: true, | ||
middlewares: [enableCORS], | ||
plugins: [importMapsPlugin({ inject: { importMap: { imports: { ...swcImportMaps } } } })], | ||
port: 2000, | ||
browserLogs: false, | ||
}; |