From 1db078d1027cfe8fb03c9dfcdd925f983556c243 Mon Sep 17 00:00:00 2001 From: Eithliu Date: Wed, 9 Oct 2024 11:23:48 +0200 Subject: [PATCH] fix: Access the nl version in decli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laura Bergoens Co-authored-by: Jérémie Jadé Co-authored-by: Fael Bassetti --- .../prototypes/single/alternatives/single.js | 6 + .../acceptance/localized-challenge-test.js | 181 +++++++++++------- 2 files changed, 120 insertions(+), 67 deletions(-) diff --git a/pix-editor/app/routes/authenticated/competence/prototypes/single/alternatives/single.js b/pix-editor/app/routes/authenticated/competence/prototypes/single/alternatives/single.js index bb0d20041..4b141c64c 100644 --- a/pix-editor/app/routes/authenticated/competence/prototypes/single/alternatives/single.js +++ b/pix-editor/app/routes/authenticated/competence/prototypes/single/alternatives/single.js @@ -9,6 +9,12 @@ export default class SingleRoute extends Route { return this.store.findRecord('challenge', params.alternative_id); } + async afterModel(model) { + super.afterModel(...arguments); + await model.localizedChallenges; + await model?.files; + } + setupController(controller) { super.setupController(...arguments); controller.edition = false; diff --git a/pix-editor/tests/acceptance/localized-challenge-test.js b/pix-editor/tests/acceptance/localized-challenge-test.js index 5853055b9..4a5f425d3 100644 --- a/pix-editor/tests/acceptance/localized-challenge-test.js +++ b/pix-editor/tests/acceptance/localized-challenge-test.js @@ -10,78 +10,125 @@ module('Acceptance | Localized-Challenge', function(hooks) { setupApplicationTest(hooks); setupMirage(hooks); - hooks.beforeEach(function() { - this.server.create('config', 'default'); - this.server.create('user', { trigram: 'ABC' }); - - this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr' }); - this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' }); - this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' }); - this.server.create('skill', { id: 'recSkill1', challengeIds: ['recChallenge1'] }); - this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] }); - this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] }); - this.server.create('competence', { - id: 'recCompetence1.1', - pixId: 'pixId recCompetence1.1', - rawThemeIds: ['recTheme1'], - rawTubeIds: ['recTube1'], + module('When interacting with a prototype', function(hooks) { + hooks.beforeEach(function() { + this.server.create('config', 'default'); + this.server.create('user', { trigram: 'ABC' }); + + this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr', genealogy: 'Prototype 1', version: 1 }); + this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' }); + this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' }); + this.server.create('skill', { id: 'recSkill1', challengeIds: ['recChallenge1'] }); + this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] }); + this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] }); + this.server.create('competence', { + id: 'recCompetence1.1', + pixId: 'pixId recCompetence1.1', + rawThemeIds: ['recTheme1'], + rawTubeIds: ['recTube1'], + }); + this.server.create('area', { + id: 'recArea1', + name: '1. Information et données', + code: '1', + competenceIds: ['recCompetence1.1'], + }); + this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] }); + return authenticateSession(); }); - this.server.create('area', { - id: 'recArea1', - name: '1. Information et données', - code: '1', - competenceIds: ['recCompetence1.1'], + + test('should display a default embedUrl if is empty but not for primary', async function(assert) { + // when + const screen = await visit('/'); + await click(findAll('[data-test-area-item]')[0]); + await click(findAll('[data-test-competence-item]')[0]); + await click(findAll('[data-test-skill-cell-link]')[0]); + await clickByText('Version nl'); + + // then + assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists(); }); - this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] }); - return authenticateSession(); - }); + test('should not display a default url if primary does not have any', async function(assert) { + // given + this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1', embedURL: null }); + this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' }); + this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl' }); + this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' }); - test('should display a default embedUrl if is empty but not for primary', async function(assert) { - // when - const screen = await visit('/'); - await click(findAll('[data-test-area-item]')[0]); - await click(findAll('[data-test-competence-item]')[0]); - await click(findAll('[data-test-skill-cell-link]')[0]); - await clickByText('Version nl'); + // when + const screen = await visit('/'); + await click(findAll('[data-test-area-item]')[0]); + await click(findAll('[data-test-competence-item]')[0]); + await click(findAll('[data-test-skill-cell-link]')[0]); + await clickByText('Version nl'); + + // then + assert.dom(await screen.queryByText('Embed URL auto-générée', { exact: false })).doesNotExist(); + }); + test('should display an embed url if localized challenge has one', async function(assert) { + // given + this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1' }); + this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' }); + this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl', embedURL: 'https://mon-site.fr/my-nl-link.html' }); + this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' }); + + // when + const screen = await visit('/'); + await click(findAll('[data-test-area-item]')[0]); + await click(findAll('[data-test-competence-item]')[0]); + await click(findAll('[data-test-skill-cell-link]')[0]); + await clickByText('Version nl'); + + // then + const input = await screen.findByLabelText('Embed URL :'); + assert.strictEqual(input.value, 'https://mon-site.fr/my-nl-link.html'); + }); - // then - assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists(); - }); - test('should not display a default url if primary does not have any', async function(assert) { - // given - this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1', embedURL: null }); - this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' }); - this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl' }); - this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' }); - - // when - const screen = await visit('/'); - await click(findAll('[data-test-area-item]')[0]); - await click(findAll('[data-test-competence-item]')[0]); - await click(findAll('[data-test-skill-cell-link]')[0]); - await clickByText('Version nl'); - - // then - assert.dom(await screen.queryByText('Embed URL auto-générée', { exact: false })).doesNotExist(); - }); - test('should display an embed url if localized challenge has one', async function(assert) { - // given - this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1' }); - this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' }); - this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl', embedURL: 'https://mon-site.fr/my-nl-link.html' }); - this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' }); - - // when - const screen = await visit('/'); - await click(findAll('[data-test-area-item]')[0]); - await click(findAll('[data-test-competence-item]')[0]); - await click(findAll('[data-test-skill-cell-link]')[0]); - await clickByText('Version nl'); - - // then - const input = await screen.findByLabelText('Embed URL :'); - assert.strictEqual(input.value, 'https://mon-site.fr/my-nl-link.html'); }); + module('When interacting with an alternative', function(hooks) { + hooks.beforeEach(function() { + this.server.create('config', 'default'); + this.server.create('user', { trigram: 'ABC' }); + + this.server.create('challenge', { id: 'recChallengeProto1', airtableId: 'airtableIdProto1', genealogy: 'Prototype 1', version: 1 }); + this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr', genealogy: 'Décliné 1', version: 1, instruction: 'Instruction de la déclinaison' }); + this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' }); + this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' }); + this.server.create('skill', { id: 'recSkill1', name: '@acquis2', challengeIds: ['recChallenge1', 'recChallengeProto1'] }); + this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] }); + this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] }); + this.server.create('competence', { + id: 'recCompetence1.1', + title: 'Nom de compétence', + code: 1, + pixId: 'pixId recCompetence1.1', + rawThemeIds: ['recTheme1'], + rawTubeIds: ['recTube1'], + }); + this.server.create('area', { + id: 'recArea1', + name: 'Nom du domaine', + code: '1', + competenceIds: ['recCompetence1.1'], + }); + this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] }); + return authenticateSession(); + }); + + test('should display a default embedUrl if is empty but not for primary', async function(assert) { + // when + const screen = await visit('/'); + await clickByText('Nom du domaine'); + await clickByText('1 Nom de compétence'); + await clickByText('@acquis2'); + await clickByText('Déclinaisons >>'); + await clickByText('Instruction de la déclinaison'); + await clickByText('Version nl'); + + // then + assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists(); + }); + }); });