| 24 | } |
| 25 | |
| 26 | function getData(languageCode = null) { |
| 27 | try { |
| 28 | // Setup data array |
| 29 | const data = []; |
| 30 | // Expose this.data in cypress |
| 31 | cy.wrap(data).as('data'); |
| 32 | // Allow adapt-style shorthand properties: |
| 33 | // this.data.course, this.data.contentObjects, this.data.articles, etc |
| 34 | Object.defineProperties(data, { |
| 35 | course: { |
| 36 | get() { |
| 37 | return data.find(item => item._type === 'course'); |
| 38 | }, |
| 39 | enumerable: false |
| 40 | }, |
| 41 | contentObjects: { |
| 42 | get() { |
| 43 | return data.filter(item => ['menu', 'page'].includes(item._type)); |
| 44 | }, |
| 45 | enumerable: false |
| 46 | }, |
| 47 | articles: { |
| 48 | get() { |
| 49 | return data.filter(item => item._type === 'article'); |
| 50 | }, |
| 51 | enumerable: false |
| 52 | }, |
| 53 | blocks: { |
| 54 | get() { |
| 55 | return data.filter(item => item._type === 'block'); |
| 56 | }, |
| 57 | enumerable: false |
| 58 | }, |
| 59 | components: { |
| 60 | get() { |
| 61 | return data.filter(item => item._type === 'component'); |
| 62 | }, |
| 63 | enumerable: false |
| 64 | } |
| 65 | }); |
| 66 | return getBuild().then(build => { |
| 67 | const { |
| 68 | coursedir, |
| 69 | availableLanguageNames |
| 70 | } = build; |
| 71 | // Load the config.json |
| 72 | return getConfig().then(config => { |
| 73 | // Check that the specified language is available |
| 74 | const defaultLanguage = config._defaultLanguage; |
| 75 | languageCode = languageCode ?? defaultLanguage; |
| 76 | if (!availableLanguageNames.includes(languageCode)) { |
| 77 | throw new Error(`Language code is not available: ${languageCode}`); |
| 78 | } |
| 79 | // Load the language_data_manifest.js for the default or specified language |
| 80 | cy.fixture(`${coursedir}/${languageCode}/language_data_manifest.js`).then(languageDataManifest => { |
| 81 | // Load each of the files specified in the manifest |
| 82 | languageDataManifest.forEach(localFilePath => { |
| 83 | const filePath = `${coursedir}/${languageCode}/${localFilePath}`; |