Skip to content

Commit

Permalink
fix(overlays): add default tag in OverlayMixin test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
gerjanvangeest committed Nov 10, 2021
1 parent 3c43184 commit f69aec6
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions packages/overlays/test-suites/OverlayMixin.suite.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { expect, fixture, html, nextFrame, aTimeout } from '@open-wc/testing';
import { LitElement } from '@lion/core';
import {
aTimeout,
defineCE,
expect,
fixture,
html,
nextFrame,
unsafeStatic,
} from '@open-wc/testing';
import sinon from 'sinon';
import { overlays } from '../src/overlays.js';
import { OverlayController } from '../src/OverlayController.js';
import { OverlayMixin } from '../src/OverlayMixin.js';
import { overlays } from '../src/overlays.js';

/**
* @typedef {import('../types/OverlayConfig').OverlayConfig} OverlayConfig
* @typedef {import('../types/OverlayMixinTypes').DefineOverlayConfig} DefineOverlayConfig
* @typedef {import('../types/OverlayMixinTypes').OverlayHost} OverlayHost
* @typedef {import('../types/OverlayMixinTypes').OverlayMixin} OverlayMixin
* @typedef {import('@lion/core').LitElement} LitElement
* @typedef {LitElement & OverlayHost & {_overlayCtrl:OverlayController}} OverlayEl
*/

Expand All @@ -19,10 +27,21 @@ function getGlobalOverlayNodes() {
}

/**
* @param {{tagString:string, tag: object, suffix?:string}} config
* @param {{tagString:string, tag: object, suffix?:string}} [customConfig]
*/
export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
describe(`OverlayMixin${suffix}`, () => {
export function runOverlayMixinSuite(customConfig) {
const cfg = {
tagString: null,
suffix: '',
...customConfig,
};

describe(`OverlayMixin${cfg.suffix}`, () => {
class TestOverlay extends OverlayMixin(LitElement) {}

cfg.tagString = cfg.tagString ? cfg.tagString : defineCE(TestOverlay);
const tag = unsafeStatic(cfg.tagString);

it('should not be opened by default', async () => {
const el = /** @type {OverlayEl} */ (
await fixture(html`
Expand Down Expand Up @@ -325,7 +344,13 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
});
});

describe(`OverlayMixin${suffix} nested`, () => {
describe(`OverlayMixin${cfg.suffix} nested`, () => {
class TestOverlayNested extends OverlayMixin(LitElement) {}

cfg.tagString = cfg.tagString ? cfg.tagString : defineCE(TestOverlayNested);
const { tagString } = cfg;
const tag = unsafeStatic(cfg.tagString);

// For some reason, globalRootNode is not cleared properly on disconnectedCallback from previous overlay test fixtures...
// Not sure why this "bug" happens...
beforeEach(() => {
Expand Down

0 comments on commit f69aec6

Please sign in to comment.