diff --git a/packages/volto-slate-glossary/src/components/Tooltips.test.js b/packages/volto-slate-glossary/src/components/Tooltips.test.js index 3206215..1d56a21 100644 --- a/packages/volto-slate-glossary/src/components/Tooltips.test.js +++ b/packages/volto-slate-glossary/src/components/Tooltips.test.js @@ -26,7 +26,7 @@ const installTooltips = (config) => { config.settings.appExtras = [ // ...config.settings.appExtras, { - match: '/', + match: '/test', component: Tooltips, }, ]; @@ -186,193 +186,213 @@ const actions = { ], }; -describe('Tooltips are generated', () => { - let baseStore = { - router: { - location: { pathname: '/test' }, - }, - actions: { actions }, - content: { - data: { - '@type': 'Document', - blocks: { - '1b1e29b6-5c16-48b7-ae63-d6dd70d9799c': { - '@type': 'slate', - plaintext: 'Morgen üben wir weiter.', - value: [ - { - children: [ - { - text: 'Morgen üben wir weiter.', - }, - ], - type: 'p', - }, - ], - }, - '5bdcc024-9715-4711-bb61-05019a4b8d1e': { - '@type': 'slate', - plaintext: 'Üben macht den Meister.', - value: [ - { - children: [ - { - text: 'Üben macht den Meister.', - }, - ], - type: 'p', - }, - ], - }, - '713f6a98-68af-4935-860b-9f17375368d8': { - '@type': 'slate', - plaintext: - 'Wir üben das. Die Abkürzung AB ist im Glossar erklärt. Wir verwenden AB ab Donnerstag.', - value: [ - { - children: [ - { - text: 'Wir üben das. Die Abkürzung AB ist im Glossar erklärt. Wir verwenden AB ab Donnerstag.', - }, - ], - type: 'p', - }, - ], - }, - '00000001-68af-4935-860b-9f17375368d8': { - '@type': 'slate', - plaintext: - 'Bij volledige elektrificatie: Canyon: Tot -57% of tot -17 μg NO2/m3', - value: [ - { - children: [ - { - text: 'Bij volledige elektrificatie: Canyon: Tot -57% of tot -17 μg NO2/m3', - }, - ], - type: 'p', - }, - ], - }, - '00000002-68af-4935-860b-9f17375368d8': { - '@type': 'slate', - plaintext: 'In automn, Aბㄱ is something you should care about.', - value: [ - { - children: [ - { - text: 'In automn, Aბㄱ is something you should care about.', - }, - ], - type: 'p', - }, - ], - }, - '00000003-68af-4935-860b-9f17375368d8': { - '@type': 'slate', - plaintext: - 'Het laatste 8-uurgemiddelde van een dag wordt berekend van 16:00 uur tot 24:00 uur.', - value: [ - { - children: [ - { - text: 'Het laatste 8-uurgemiddelde van een dag wordt berekend van 16:00 uur tot 24:00 uur.', - }, - ], - type: 'p', - }, - ], - }, - 'e4ceaac9-669f-4df4-937a-fb762f7b289e': { - '@type': 'title', - }, +const initialStore = { + router: { + location: { pathname: '/test' }, + }, + actions: { actions }, + content: { + data: { + '@type': 'Document', + blocks: { + '1b1e29b6-5c16-48b7-ae63-d6dd70d9799c': { + '@type': 'slate', + plaintext: 'Morgen üben wir weiter.', + value: [ + { + children: [ + { + text: 'Morgen üben wir weiter.', + }, + ], + type: 'p', + }, + ], + }, + '5bdcc024-9715-4711-bb61-05019a4b8d1e': { + '@type': 'slate', + plaintext: 'Üben macht den Meister.', + value: [ + { + children: [ + { + text: 'Üben macht den Meister.', + }, + ], + type: 'p', + }, + ], }, - blocks_layout: { - items: [ - 'e4ceaac9-669f-4df4-937a-fb762f7b289e', - '5bdcc024-9715-4711-bb61-05019a4b8d1e', - '713f6a98-68af-4935-860b-9f17375368d8', - '00000001-68af-4935-860b-9f17375368d8', - '00000002-68af-4935-860b-9f17375368d8', - '00000003-68af-4935-860b-9f17375368d8', - '1b1e29b6-5c16-48b7-ae63-d6dd70d9799c', + '713f6a98-68af-4935-860b-9f17375368d8': { + '@type': 'slate', + plaintext: + 'Wir üben das. Die Abkürzung AB ist im Glossar erklärt. Wir verwenden AB ab Donnerstag.', + value: [ + { + children: [ + { + text: 'Wir üben das. Die Abkürzung AB ist im Glossar erklärt. Wir verwenden AB ab Donnerstag.', + }, + ], + type: 'p', + }, ], }, + '00000001-68af-4935-860b-9f17375368d8': { + '@type': 'slate', + plaintext: + 'Bij volledige elektrificatie: Canyon: Tot -57% of tot -17 μg NO2/m3', + value: [ + { + children: [ + { + text: 'Bij volledige elektrificatie: Canyon: Tot -57% of tot -17 μg NO2/m3', + }, + ], + type: 'p', + }, + ], + }, + '00000002-68af-4935-860b-9f17375368d8': { + '@type': 'slate', + plaintext: 'In automn, Aბㄱ is something you should care about.', + value: [ + { + children: [ + { + text: 'In automn, Aბㄱ is something you should care about.', + }, + ], + type: 'p', + }, + ], + }, + '00000003-68af-4935-860b-9f17375368d8': { + '@type': 'slate', + plaintext: + 'Het laatste 8-uurgemiddelde van een dag wordt berekend van 16:00 uur tot 24:00 uur.', + value: [ + { + children: [ + { + text: 'Het laatste 8-uurgemiddelde van een dag wordt berekend van 16:00 uur tot 24:00 uur.', + }, + ], + type: 'p', + }, + ], + }, + 'e4ceaac9-669f-4df4-937a-fb762f7b289e': { + '@type': 'title', + }, }, - get: { error: null }, - }, - userSession: { token: null }, - apierror: {}, - intl: { - locale: 'en', - messages: {}, - }, - glossarytooltipterms: { - error: null, - hasErrror: false, - result: { + blocks_layout: { items: [ - { - definition: [ - '

Eine Tätigkeit ausführen um vertrauter mit ihr zu werden und sie zu meistern.

', - ], - term: 'üben', - }, - { - definition: [ - '

Microgram of één miljoenste gram.

', - ], - term: 'µg', - }, - { - definition: [ - '

No clue what that should be!?

', - ], - term: 'Aბㄱ', - }, - { - definition: ['

Arbeitsbegleitung

'], - term: 'AB', - }, - { - definition: [ - '

Voor het hoogste 8-uurgemiddelde van een dag berekenen we voor elke 8 uur het gemiddelde en nemen dan de hoogste waarde. Het eerste 8-urgemiddelde van een dag loopt van 17:00 uur op de dag daarvoor tot 1:00 uur op de dag zelf.

', - ], - term: '8-uurgemiddelde', - }, + 'e4ceaac9-669f-4df4-937a-fb762f7b289e', + '5bdcc024-9715-4711-bb61-05019a4b8d1e', + '713f6a98-68af-4935-860b-9f17375368d8', + '00000001-68af-4935-860b-9f17375368d8', + '00000002-68af-4935-860b-9f17375368d8', + '00000003-68af-4935-860b-9f17375368d8', + '1b1e29b6-5c16-48b7-ae63-d6dd70d9799c', ], - items_total: 1, }, - loadingResults: false, }, - }; + get: { error: null }, + }, + userSession: { token: null }, + apierror: {}, + intl: { + locale: 'en', + messages: {}, + }, + glossarytooltipterms: { + error: null, + hasErrror: false, + result: { + items: [ + { + definition: [ + '

Eine Tätigkeit ausführen um vertrauter mit ihr zu werden und sie zu meistern.

', + ], + term: 'üben', + }, + { + definition: [ + '

Microgram of één miljoenste gram.

', + ], + term: 'µg', + }, + { + definition: [ + '

No clue what that should be!?

', + ], + term: 'Aბㄱ', + }, + { + definition: ['

Arbeitsbegleitung

'], + term: 'AB', + }, + { + definition: [ + '

Voor het hoogste 8-uurgemiddelde van een dag berekenen we voor elke 8 uur het gemiddelde en nemen dan de hoogste waarde. Het eerste 8-urgemiddelde van een dag loopt van 17:00 uur op de dag daarvoor tot 1:00 uur op de dag zelf.

', + ], + term: '8-uurgemiddelde', + }, + ], + items_total: 1, + }, + loadingResults: false, + }, +}; + +describe('Tooltips divers', () => { + let baseStore = initialStore; - test('for all occurrences', async () => { + it(" – NO tooltips if route doesn't match configuration", () => { const store = mockStore(baseStore); + config.settings.appExtras = []; const { container } = render( <>
-
, ); - await waitFor(() => {}); expect(container).toMatchSnapshot(); expect(container).toHaveTextContent('Üben macht den Meister'); }); - test('only for first occurrences per page', async () => { + it(' – component Tooltips is rendered in AppExtras', () => { + const store = mockStore(baseStore); + config.settings.appExtras = [ + { + match: '/test', + component: Tooltips, + }, + ]; + const { container } = render( + + + , + ); + expect(container).toMatchSnapshot(); + }); +}); + +describe('Tooltips', () => { + let baseStore = initialStore; + + test('are generated for all occurrences', async () => { const store = mockStore(baseStore); - config.settings.glossary.matchOnlyFirstOccurence = true; const { container } = render( <>
- +
, ); @@ -382,15 +402,15 @@ describe('Tooltips are generated', () => { expect(container).toHaveTextContent('Üben macht den Meister'); }); - test('only case sensitive', async () => { + test('are generated only for first occurrences per page', async () => { const store = mockStore(baseStore); - config.settings.glossary.caseSensitive = true; + config.settings.glossary.matchOnlyFirstOccurence = true; const { container } = render( <>
- +
, ); @@ -400,13 +420,21 @@ describe('Tooltips are generated', () => { expect(container).toHaveTextContent('Üben macht den Meister'); }); - it(' – component Tooltips is rendered in AppExtras', () => { + test('are generated only case sensitive', async () => { const store = mockStore(baseStore); + config.settings.glossary.caseSensitive = true; const { container } = render( - + <> + +
+ +
, ); + + await waitFor(() => {}); expect(container).toMatchSnapshot(); + expect(container).toHaveTextContent('Üben macht den Meister'); }); }); diff --git a/packages/volto-slate-glossary/src/components/__snapshots__/Tooltips.test.js.snap b/packages/volto-slate-glossary/src/components/__snapshots__/Tooltips.test.js.snap index de68114..cb2c9a3 100644 --- a/packages/volto-slate-glossary/src/components/__snapshots__/Tooltips.test.js.snap +++ b/packages/volto-slate-glossary/src/components/__snapshots__/Tooltips.test.js.snap @@ -1,16 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Tooltips are generated – component Tooltips is rendered in AppExtras 1`] = ` -
-
-
-
-`; - exports[`Tooltips are generated for all occurrences 1`] = `
`; + +exports[`Tooltips divers – NO tooltips if route doesn't match configuration 1`] = ` +
+
+
+
+
+

+

+ + Üben macht den Meister. + +

+

+ + Wir üben das. Die Abkürzung AB ist im Glossar erklärt. Wir verwenden AB ab Donnerstag. + +

+

+ + Bij volledige elektrificatie: <strong>Canyon: Tot -57% of tot -17 μg NO2/m3</strong> + +

+

+ + In automn, Aბㄱ is something you should care about. + +

+

+ + Het laatste 8-uurgemiddelde van een dag wordt berekend van 16:00 uur tot 24:00 uur. + +

+

+ + Morgen üben wir weiter. + +

+

+
+
+
+
+
+
+`; + +exports[`Tooltips divers – component Tooltips is rendered in AppExtras 1`] = ` +
+
+
+
+`; diff --git a/packages/volto-slate-glossary/src/index.js b/packages/volto-slate-glossary/src/index.js index e95a4e4..7676ffe 100644 --- a/packages/volto-slate-glossary/src/index.js +++ b/packages/volto-slate-glossary/src/index.js @@ -14,7 +14,7 @@ const applyConfig = (config) => { // config.settings.appExtras = [ // ...config.settings.appExtras, // { - // match: '/', + // match: '/documentation', // component: Tooltips, // }, // ]; diff --git a/packages/volto-slate-glossary/src/utils.js b/packages/volto-slate-glossary/src/utils.js index 4dd0e77..e880d0c 100644 --- a/packages/volto-slate-glossary/src/utils.js +++ b/packages/volto-slate-glossary/src/utils.js @@ -34,5 +34,6 @@ export const TextWithGlossaryTooltips = ({ text }) => { return text; } let uid = uuidv5(text, MY_NAMESPACE); - return tooltippedTexts[uid]; + // No match in store if this route is not configured for tooltips. Return text unchanged. + return tooltippedTexts[uid] ? tooltippedTexts[uid] : text; };