@limetech/lime-web-components 4.54.1 → 4.54.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.54.2](https://github.com/Lundalogik/lime-web-components/compare/v4.54.1...v4.54.2) (2022-09-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **testing:** inject component states in connectedCallback ([4606839](https://github.com/Lundalogik/lime-web-components/commit/4606839a9ac0ed106e2d9352e243a270b21450b2))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [4.54.1](https://github.com/Lundalogik/lime-web-components/compare/v4.54.0...v4.54.1) (2022-09-23)
7
18
 
8
19
  **Note:** Version bump only for package @limetech/lime-web-components
@@ -8,8 +8,11 @@ var componentInstances = new WeakMap();
8
8
  var originalHooks = new WeakMap();
9
9
  var destroyFunctions = new WeakMap();
10
10
  function createComponent(component, page, config) {
11
- componentConfigs.set(component.prototype, config);
12
- extendLifecycleHook(component.prototype, 'componentWillLoad', initComponent);
11
+ componentConfigs.set(component.prototype, {
12
+ config: config,
13
+ initialized: false,
14
+ });
15
+ extendLifecycleHook(component.prototype, 'connectedCallback', initComponent);
13
16
  var element = page.doc.createElement(config.tag);
14
17
  var props = config.props || {};
15
18
  var listeners = config.listeners || {};
@@ -44,9 +47,15 @@ exports.setState = setState;
44
47
  function initComponent() {
45
48
  var element = (0, core_1.getElement)(this);
46
49
  componentInstances.set(element, this);
47
- var config = componentConfigs.get(this.constructor.prototype);
48
- if (config === null || config === void 0 ? void 0 : config.state) {
50
+ var componentState = componentConfigs.get(this.constructor.prototype);
51
+ var initialized = componentState.initialized;
52
+ var config = componentState.config;
53
+ if (!initialized && config.state) {
49
54
  setState(element, config.state);
55
+ componentConfigs.set(this.constructor.prototype, {
56
+ config: config,
57
+ initialized: true,
58
+ });
50
59
  }
51
60
  }
52
61
  function extendLifecycleHook(component, name, hook) {
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestDummy = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var core_1 = require("@stencil/core");
6
+ var testing_1 = require("@stencil/core/testing");
7
+ var component_testing_1 = require("./component-testing");
8
+ var TestDummy = (function () {
9
+ function TestDummy() {
10
+ this.injectedState = false;
11
+ this.expectedState = true;
12
+ }
13
+ TestDummy.prototype.connectedCallback = function () {
14
+ expect(this.injectedState).toEqual(this.expectedState);
15
+ };
16
+ TestDummy.prototype.disconnectedCallback = function () {
17
+ this.expectedState = false;
18
+ this.injectedState = false;
19
+ };
20
+ TestDummy.prototype.render = function () {
21
+ return 'Lime Test Dummy';
22
+ };
23
+ tslib_1.__decorate([
24
+ (0, core_1.Prop)()
25
+ ], TestDummy.prototype, "platform", void 0);
26
+ tslib_1.__decorate([
27
+ (0, core_1.Prop)()
28
+ ], TestDummy.prototype, "context", void 0);
29
+ tslib_1.__decorate([
30
+ (0, core_1.State)()
31
+ ], TestDummy.prototype, "injectedState", void 0);
32
+ TestDummy = tslib_1.__decorate([
33
+ (0, core_1.Component)({
34
+ tag: 'lime-test-dummy',
35
+ shadow: true,
36
+ })
37
+ ], TestDummy);
38
+ return TestDummy;
39
+ }());
40
+ exports.TestDummy = TestDummy;
41
+ var component;
42
+ var page;
43
+ var platform = {};
44
+ var context = { limetype: null, id: null };
45
+ var componentConfig = {
46
+ tag: 'lime-test-dummy',
47
+ state: {
48
+ injectedState: true,
49
+ },
50
+ props: {
51
+ context: context,
52
+ platform: platform,
53
+ },
54
+ };
55
+ beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
56
+ return tslib_1.__generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0: return [4, (0, testing_1.newSpecPage)({ components: [TestDummy] })];
59
+ case 1:
60
+ page = _a.sent();
61
+ component = (0, component_testing_1.createComponent)(TestDummy, page, componentConfig);
62
+ return [4, page.waitForChanges()];
63
+ case 2:
64
+ _a.sent();
65
+ return [2];
66
+ }
67
+ });
68
+ }); });
69
+ describe('creating a component', function () {
70
+ it('is successful', function () {
71
+ expect(component).toEqualHtml("\n <lime-test-dummy>\n <mock:shadow-root>\n Lime Test Dummy\n </mock:shadow-root>\n </lime-test-dummy>");
72
+ });
73
+ it('injects state only once', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
74
+ var parent;
75
+ return tslib_1.__generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ parent = component.parentElement;
79
+ component.remove();
80
+ parent.appendChild(component);
81
+ return [4, page.waitForChanges()];
82
+ case 1:
83
+ _a.sent();
84
+ return [2];
85
+ }
86
+ });
87
+ }); });
88
+ });
@@ -13,8 +13,11 @@ const destroyFunctions = new WeakMap();
13
13
  * @returns {HTMLElement} the component
14
14
  */
15
15
  export function createComponent(component, page, config) {
16
- componentConfigs.set(component.prototype, config);
17
- extendLifecycleHook(component.prototype, 'componentWillLoad', initComponent);
16
+ componentConfigs.set(component.prototype, {
17
+ config: config,
18
+ initialized: false,
19
+ });
20
+ extendLifecycleHook(component.prototype, 'connectedCallback', initComponent);
18
21
  const element = page.doc.createElement(config.tag);
19
22
  const props = config.props || {};
20
23
  const listeners = config.listeners || {};
@@ -59,7 +62,7 @@ export function setState(component, state) {
59
62
  /**
60
63
  * Init a component that is under test
61
64
  *
62
- * This is called just before the `componentWillLoad` lifecycle hook
65
+ * This is called just before the `connectedCallback` lifecycle hook
63
66
  * of the component and is a good place to save the component instance
64
67
  * and set the initial state
65
68
  *
@@ -68,9 +71,15 @@ export function setState(component, state) {
68
71
  function initComponent() {
69
72
  const element = getElement(this);
70
73
  componentInstances.set(element, this);
71
- const config = componentConfigs.get(this.constructor.prototype);
72
- if (config === null || config === void 0 ? void 0 : config.state) {
74
+ const componentState = componentConfigs.get(this.constructor.prototype);
75
+ const initialized = componentState.initialized;
76
+ const config = componentState.config;
77
+ if (!initialized && config.state) {
73
78
  setState(element, config.state);
79
+ componentConfigs.set(this.constructor.prototype, {
80
+ config: config,
81
+ initialized: true,
82
+ });
74
83
  }
75
84
  }
76
85
  /**
@@ -0,0 +1,10 @@
1
+ import { LimeWebComponent, LimeWebComponentContext, LimeWebComponentPlatform } from '../core';
2
+ export declare class TestDummy implements LimeWebComponent {
3
+ platform: LimeWebComponentPlatform;
4
+ context: LimeWebComponentContext;
5
+ private injectedState;
6
+ private expectedState;
7
+ connectedCallback(): void;
8
+ disconnectedCallback(): void;
9
+ render(): string;
10
+ }
@@ -0,0 +1,71 @@
1
+ import { __decorate } from "tslib";
2
+ import { Component, Prop, State } from '@stencil/core';
3
+ import { newSpecPage } from '@stencil/core/testing';
4
+ import { createComponent } from './component-testing';
5
+ let TestDummy = class TestDummy {
6
+ constructor() {
7
+ this.injectedState = false;
8
+ this.expectedState = true;
9
+ }
10
+ connectedCallback() {
11
+ expect(this.injectedState).toEqual(this.expectedState);
12
+ }
13
+ disconnectedCallback() {
14
+ this.expectedState = false;
15
+ this.injectedState = false;
16
+ }
17
+ render() {
18
+ return 'Lime Test Dummy';
19
+ }
20
+ };
21
+ __decorate([
22
+ Prop()
23
+ ], TestDummy.prototype, "platform", void 0);
24
+ __decorate([
25
+ Prop()
26
+ ], TestDummy.prototype, "context", void 0);
27
+ __decorate([
28
+ State()
29
+ ], TestDummy.prototype, "injectedState", void 0);
30
+ TestDummy = __decorate([
31
+ Component({
32
+ tag: 'lime-test-dummy',
33
+ shadow: true,
34
+ })
35
+ ], TestDummy);
36
+ export { TestDummy };
37
+ let component;
38
+ let page;
39
+ const platform = {};
40
+ const context = { limetype: null, id: null };
41
+ const componentConfig = {
42
+ tag: 'lime-test-dummy',
43
+ state: {
44
+ injectedState: true,
45
+ },
46
+ props: {
47
+ context: context,
48
+ platform: platform,
49
+ },
50
+ };
51
+ beforeEach(async () => {
52
+ page = await newSpecPage({ components: [TestDummy] });
53
+ component = createComponent(TestDummy, page, componentConfig);
54
+ await page.waitForChanges();
55
+ });
56
+ describe('creating a component', () => {
57
+ it('is successful', () => {
58
+ expect(component).toEqualHtml(`
59
+ <lime-test-dummy>
60
+ <mock:shadow-root>
61
+ Lime Test Dummy
62
+ </mock:shadow-root>
63
+ </lime-test-dummy>`);
64
+ });
65
+ it('injects state only once', async () => {
66
+ const parent = component.parentElement;
67
+ component.remove();
68
+ parent.appendChild(component);
69
+ await page.waitForChanges();
70
+ });
71
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limetech/lime-web-components",
3
- "version": "4.54.1",
3
+ "version": "4.54.2",
4
4
  "author": "Lime Technologies",
5
5
  "homepage": "https://github.com/Lundalogik/lime-web-components",
6
6
  "license": "Apache-2.0",
@@ -51,5 +51,5 @@
51
51
  "peerDependencies": {
52
52
  "@stencil/core": "^2.17.1"
53
53
  },
54
- "gitHead": "4b82a12b6d6fc9a8c8c1494e7bb3701b6fe8a7c2"
54
+ "gitHead": "13613b1b5a0b22a21cd574f5050391e403a315c3"
55
55
  }