-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core/workflow-steps): update step position after first rendering (#…
…459) Co-authored-by: Daniel Leroux <daniel.leroux@siemens.com>
- Loading branch information
1 parent
0d18866
commit 715d50d
Showing
4 changed files
with
161 additions
and
25 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
94 changes: 94 additions & 0 deletions
94
packages/core/src/components/workflow-steps/test/workflow-steps.spec.ts
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,94 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { WorkflowStep } from '../..//workflow-step/workflow-step'; | ||
import { WorkflowSteps } from '../workflow-steps'; | ||
import { createMutationObserver } from './../../utils/mutation-observer'; | ||
|
||
jest.mock('./../../utils/mutation-observer'); | ||
|
||
describe('workflow-steps', () => { | ||
let observerCallback: Function; | ||
|
||
beforeEach(async () => { | ||
//@ts-ignore | ||
createMutationObserver = jest.fn((callback) => { | ||
observerCallback = callback; | ||
return { | ||
observe: jest.fn(), | ||
}; | ||
}); | ||
}); | ||
|
||
it('should render steps', async () => { | ||
const page = await newSpecPage({ | ||
components: [WorkflowSteps, WorkflowStep], | ||
html: `<ix-workflow-steps> | ||
<ix-workflow-steps>`, | ||
}); | ||
|
||
const step = document.createElement('ix-workflow-step'); | ||
page.root.querySelector('ix-workflow-steps').append(step); | ||
|
||
observerCallback([{ type: 'childList' }]); | ||
|
||
await page.waitForChanges(); | ||
expect(step).toEqualAttributes({ | ||
position: 'last', | ||
selected: true, | ||
}); | ||
}); | ||
|
||
it('should re-render workflow steps', async () => { | ||
const page = await newSpecPage({ | ||
components: [WorkflowSteps, WorkflowStep], | ||
html: `<ix-workflow-steps> | ||
<ix-workflow-steps>`, | ||
}); | ||
|
||
const step = document.createElement('ix-workflow-step'); | ||
const step1 = document.createElement('ix-workflow-step'); | ||
const step2 = document.createElement('ix-workflow-step'); | ||
page.root.querySelector('ix-workflow-steps').append(step); | ||
page.root.querySelector('ix-workflow-steps').append(step1); | ||
|
||
observerCallback([{ type: 'childList' }]); | ||
await page.waitForChanges(); | ||
|
||
expect(step).toEqualAttributes({ | ||
position: 'first', | ||
selected: true, | ||
}); | ||
|
||
expect(step1).toEqualAttributes({ | ||
position: 'last', | ||
selected: false, | ||
}); | ||
|
||
page.root.querySelector('ix-workflow-steps').append(step2); | ||
observerCallback([{ type: 'childList' }]); | ||
await page.waitForChanges(); | ||
|
||
expect(step).toEqualAttributes({ | ||
position: 'first', | ||
selected: true, | ||
}); | ||
|
||
expect(step1).toEqualAttributes({ | ||
position: 'undefined', | ||
selected: false, | ||
}); | ||
|
||
expect(step2).toEqualAttributes({ | ||
position: 'last', | ||
selected: false, | ||
}); | ||
}); | ||
}); |
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