-
Notifications
You must be signed in to change notification settings - Fork 17
MWPW-192450: Fix - Lingo placeholders in Studio card preview #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
66cb6d1
3db7e42
5d0cf6a
cf636c8
6da772f
93371e8
c0c5908
f15ad35
d7abacf
b6d4999
009e7f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import '../src/mas-fragment-editor.js'; | |
| import MasFragmentEditor from '../src/mas-fragment-editor.js'; | ||
| import Store from '../src/store.js'; | ||
| import { Fragment } from '../src/aem/fragment.js'; | ||
| import generateFragmentStore, { SourceFragmentStore } from '../src/reactivity/source-fragment-store.js'; | ||
| import generateFragmentStore from '../src/reactivity/source-fragment-store.js'; | ||
| import { PAGE_NAMES, CARD_MODEL_PATH, ODIN_PREVIEW_ORIGIN } from '../src/constants.js'; | ||
| import router from '../src/router.js'; | ||
| import Events from '../src/events.js'; | ||
|
|
@@ -239,6 +239,7 @@ describe('MasFragmentEditor', () => { | |
| search: structuredClone(Store.search.get()), | ||
| filters: structuredClone(Store.filters.get()), | ||
| translatedLocales: Store.fragmentEditor.translatedLocales.get(), | ||
| placeholdersPreview: Store.placeholders.preview.get(), | ||
| }; | ||
|
|
||
| Store.fragments.list.data.value = []; | ||
|
|
@@ -248,6 +249,7 @@ describe('MasFragmentEditor', () => { | |
| Store.search.value = {}; | ||
| Store.filters.value = { locale: 'en_US' }; | ||
| Store.fragmentEditor.translatedLocales.value = null; | ||
| Store.placeholders.preview.value = null; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
|
|
@@ -261,6 +263,7 @@ describe('MasFragmentEditor', () => { | |
| Store.search.value = originalStoreState.search; | ||
| Store.filters.value = originalStoreState.filters; | ||
| Store.fragmentEditor.translatedLocales.value = originalStoreState.translatedLocales; | ||
| Store.placeholders.preview.value = originalStoreState.placeholdersPreview; | ||
| }); | ||
|
|
||
| it('returns early when no fragment ID exists', async () => { | ||
|
|
@@ -357,19 +360,66 @@ describe('MasFragmentEditor', () => { | |
|
|
||
| it('reloads locale placeholders for variations when active locale differs', async () => { | ||
| const fragmentData = createFragmentData({ id: 'variation-id', locale: 'fr_FR', slug: 'variation' }); | ||
| const resolvePreviewSpy = sandbox.spy(SourceFragmentStore.prototype, 'resolvePreviewFragment'); | ||
|
|
||
| Store.filters.value = { locale: 'tr_TR' }; | ||
| mockRepo.aem.sites.cf.fragments.getById.resolves(fragmentData); | ||
| el.editorContextStore.isVariation.returns(true); | ||
| sandbox.stub(el, 'resolveVariationParentFragment').resolves(null); | ||
| Store.fragmentEditor.fragmentId.value = 'variation-id'; | ||
|
|
||
| mockRepo.loadPreviewPlaceholders.callsFake(async () => { | ||
| Store.placeholders.preview.set({ testDictionary: true }); | ||
| }); | ||
|
|
||
| await el.initFragment(); | ||
|
|
||
| expect(mockRepo.loadPreviewPlaceholders.calledOnce).to.be.true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weakened assertion — preview resolution no longer verifiedThe old test verified both In the new flow, preview resolution happens implicitly via Consider adding a lightweight assertion that |
||
| expect(Store.search.get().region).to.equal('fr_FR'); | ||
| expect(Store.placeholders.preview.get()).to.deep.equal({ testDictionary: true }); | ||
| }); | ||
|
|
||
| it('reloads locale placeholders for cached variation when locale differs from Store.localeOrRegion()', async () => { | ||
| const fragmentData = createFragmentData({ id: 'cached-var-id', locale: 'fr_FR', slug: 'variation' }); | ||
| const parentData = createFragmentData({ id: 'parent-id', locale: 'en_US', slug: 'default' }); | ||
| const sourceStore = generateFragmentStore(new Fragment(fragmentData), new Fragment(parentData)); | ||
| sandbox.spy(sourceStore, 'resolvePreviewFragment'); | ||
|
|
||
| mockRepo.loadPreviewPlaceholders.callsFake(async () => { | ||
| Store.placeholders.preview.set({ fromCachedVariation: true }); | ||
| }); | ||
|
|
||
| el.editorContextStore.isVariation.returns(true); | ||
| sandbox.stub(el, 'resolveVariationParentFragment').resolves(new Fragment(parentData)); | ||
|
|
||
| Store.filters.value = { locale: 'tr_TR' }; | ||
| Store.search.value = { path: 'sandbox' }; | ||
| Store.fragments.list.data.value = [sourceStore]; | ||
| Store.fragmentEditor.fragmentId.value = 'cached-var-id'; | ||
|
|
||
| await el.initFragment(); | ||
|
|
||
| expect(mockRepo.loadPreviewPlaceholders.callCount).to.equal(2); | ||
| expect(resolvePreviewSpy.calledOnce).to.be.true; | ||
| expect(mockRepo.loadPreviewPlaceholders.calledOnce).to.be.true; | ||
| expect(Store.search.get().region).to.equal('fr_FR'); | ||
| expect(Store.placeholders.preview.get()).to.deep.equal({ fromCachedVariation: true }); | ||
| expect(sourceStore.resolvePreviewFragment.calledOnce).to.be.true; | ||
| }); | ||
|
|
||
| it('does not reload preview placeholders when cached variation locale matches Store.localeOrRegion()', async () => { | ||
| const fragmentData = createFragmentData({ id: 'cached-var-id', locale: 'fr_FR', slug: 'variation' }); | ||
| const parentData = createFragmentData({ id: 'parent-id', locale: 'en_US', slug: 'default' }); | ||
| const sourceStore = generateFragmentStore(new Fragment(fragmentData), new Fragment(parentData)); | ||
|
|
||
| el.editorContextStore.isVariation.returns(true); | ||
| sandbox.stub(el, 'resolveVariationParentFragment').resolves(new Fragment(parentData)); | ||
|
|
||
| Store.filters.value = { locale: 'fr_FR' }; | ||
| Store.search.value = { path: 'sandbox' }; | ||
| Store.fragments.list.data.value = [sourceStore]; | ||
| Store.fragmentEditor.fragmentId.value = 'cached-var-id'; | ||
|
|
||
| await el.initFragment(); | ||
|
|
||
| expect(mockRepo.loadPreviewPlaceholders.called).to.be.false; | ||
| }); | ||
|
|
||
| it('uses pending parent from create variation event when context is not ready', async () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New cached-store locale reload path has no test coverage
These 6 new lines add locale-specific placeholder loading to
#initializeFromCachedStore— this is the path Codecov flagged (4 missing lines, 71.42% patch coverage on this file).The existing test at
mas-fragment-editor.test.js:358only exercises#initializeFromRepository(non-cached). A test for this path would look like: