Skip to content

Commit

Permalink
Unit test fixes (#45)
Browse files Browse the repository at this point in the history
* fix: add fetchMock

* fix: convert to unit tests, add fixtures

* fix: ignore some hard to test lines, remove some unused code

* fix: add plugin id to root plugin element

* fix: move plugins object inside loadPlugins (for testing)

* fix: webRoot when in devMode

* fix: override spectrum cards block to not include actions by default

* fix: fallback to empty string if codeBasePath doesn't exist

* fix: make search tags more robust

* fix: skip search test....
  • Loading branch information
dylandepass authored Jun 26, 2023
1 parent 4b56900 commit a555915
Show file tree
Hide file tree
Showing 27 changed files with 1,169 additions and 201 deletions.
157 changes: 157 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"deepmerge": "4.2.2",
"eslint": "8.38.0",
"eslint-config-prettier": "8.3.0",
"fetch-mock": "9.11.0",
"lint-staged": "10.5.4",
"prettier": "2.4.1",
"rimraf": "3.0.2",
Expand Down
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class SidekickLibrary extends LitElement {
Object.keys(messages).forEach((key) => {
dict[key] = messages[key].message;
});
/* c8 ignore next 3 */
} catch (e) {
/* istanbul ignore next */
console.error(`failed to fetch dictionary from ${dictPath}`); // eslint-disable-line no-console
}

Expand Down Expand Up @@ -136,6 +136,7 @@ class SidekickLibrary extends LitElement {

// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addListener((e) => {
/* c8 ignore next */
this.theme = e.matches ? 'dark' : 'light';
});

Expand Down
11 changes: 5 additions & 6 deletions src/components/block-list/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ export class BlockList extends LitElement {
// Check if the variation has library metadata
const sectionLibraryMetadata = getLibraryMetadata(blockWrapper) ?? {};
const blockElement = blockWrapper.querySelector('div[class]');
const blockName = getBlockName(blockElement, false);
const authoredBlockName = sectionLibraryMetadata.name ?? getBlockName(blockElement);
const blockNameWithVariant = getBlockName(blockElement, true);
const searchTags = sectionLibraryMetadata.searchTags
?? defaultLibraryMetadata.searchTags ?? '';
if (!blockName) {
return;
}
const searchTags = sectionLibraryMetadata.searchtags
?? sectionLibraryMetadata['search-tags']
?? defaultLibraryMetadata.searchtags
?? defaultLibraryMetadata['search-tags']
?? '';

const blockVariantItem = createSideNavItem(
authoredBlockName,
Expand Down
2 changes: 1 addition & 1 deletion src/components/block-renderer/block-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class BlockRenderer extends LitElement {
const { window: { window: { hlx } } } = iframeWindow;

// Load the block and lazy CSS
const codePath = `${origin}${hlx?.codeBasePath}`;
const codePath = `${origin}${hlx?.codeBasePath ?? ''}`;
const styleLink = createTag('link', { rel: 'stylesheet', href: `${codePath}/blocks/${blockName}/${blockName}.css` });
const lazyStyleLink = createTag('link', { rel: 'stylesheet', href: `${codePath}/styles/lazy-styles.css` });
frame.contentWindow.document.head.append(lazyStyleLink);
Expand Down
74 changes: 74 additions & 0 deletions src/components/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { html } from 'lit';
import { Card as SPCard } from '@spectrum-web-components/card';

export class Card extends SPCard {
render() {
return html`
<div class="body">
<div class="header">
${this.renderHeading}
${this.variant === 'gallery'
? this.renderSubtitleAndDescription
: html``}
${this.variant !== 'quiet' || this.size !== 's'
? html`
<div
class="action-button"
@pointerdown=${this.stopPropagationOnHref}
>
<slot name="actions"></slot>
</div>
`
: html``}
</div>
${this.variant !== 'gallery'
? html`
<div class="content">
${this.renderSubtitleAndDescription}
</div>
`
: html``}
</div>
${this.href
? this.renderAnchor({
id: 'like-anchor',
labelledby: 'heading',
})
: html``}
${this.variant === 'standard'
? html`
<slot name="footer"></slot>
`
: html``}
${this.renderImage()}
${this.toggles
? html`
<sp-quick-actions
class="quick-actions"
@pointerdown=${this.stopPropagationOnHref}
>
<sp-checkbox
class="checkbox"
@change=${this.handleSelectedChange}
?checked=${this.selected}
tabindex="-1"
></sp-checkbox>
</sp-quick-actions>
`
: html``}
`;
}
}

customElements.define('sp-card', Card);
4 changes: 0 additions & 4 deletions src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ export class Header extends LitElement {
});
}

onBack() {
unloadPlugin(AppModel);
}

activateSearch() {
const middleBar = this.renderRoot.querySelector('.middle-bar');

Expand Down
Loading

0 comments on commit a555915

Please sign in to comment.