2020-08-28 17:10:37 +02:00
|
|
|
/* global expect beforeAll */
|
2020-02-24 15:03:21 +01:00
|
|
|
const {
|
2020-08-28 17:10:37 +02:00
|
|
|
challengesDir,
|
|
|
|
createChallengeCreator,
|
|
|
|
hasEnglishSourceCreator
|
2020-02-24 15:03:21 +01:00
|
|
|
} = require('./getChallenges');
|
|
|
|
|
|
|
|
/* eslint-disable max-len */
|
2020-08-28 17:10:37 +02:00
|
|
|
const REAL_PATH =
|
|
|
|
'01-responsive-web-design/applied-accessibility/add-a-text-alternative-to-images-for-visually-impaired-accessibility.english.md';
|
|
|
|
const REAL_MISSING_PATH =
|
|
|
|
'01-responsive-web-design/applied-accessibility/add-a-text-alternative-to-images-for-visually-impaired.md';
|
2020-02-24 15:03:21 +01:00
|
|
|
|
2020-08-28 17:10:37 +02:00
|
|
|
const EXISTING_CHALLENGE_PATH = 'challenge.md';
|
|
|
|
const MISSING_CHALLENGE_PATH = 'no/challenge.md';
|
2020-02-24 15:03:21 +01:00
|
|
|
/* eslint-enable max-len */
|
|
|
|
|
2020-08-28 17:10:37 +02:00
|
|
|
let hasEnglishSource;
|
|
|
|
let createChallenge;
|
|
|
|
const basePath = '__fixtures__';
|
|
|
|
|
2020-02-24 15:03:21 +01:00
|
|
|
describe('create non-English challenge', () => {
|
|
|
|
describe('createChallenge', () => {
|
2020-08-28 17:10:37 +02:00
|
|
|
it('throws if lang is an invalid language', async () => {
|
|
|
|
createChallenge = createChallengeCreator(basePath, 'notlang');
|
|
|
|
await expect(createChallenge(REAL_PATH)).rejects.toThrow(
|
2020-02-24 15:03:21 +01:00
|
|
|
'notlang is not a accepted language'
|
|
|
|
);
|
|
|
|
});
|
2020-08-28 17:10:37 +02:00
|
|
|
it('throws an error if the source challenge is missing', async () => {
|
|
|
|
createChallenge = createChallengeCreator(challengesDir, 'chinese');
|
|
|
|
await expect(createChallenge(REAL_MISSING_PATH)).rejects.toThrow(
|
|
|
|
`Missing English challenge for
|
|
|
|
${REAL_MISSING_PATH}
|
|
|
|
It should be in
|
|
|
|
`
|
2020-02-24 15:03:21 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-08-28 17:10:37 +02:00
|
|
|
describe('hasEnglishSource', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
hasEnglishSource = hasEnglishSourceCreator(basePath);
|
2020-02-24 15:03:21 +01:00
|
|
|
});
|
2020-08-28 17:10:37 +02:00
|
|
|
it('returns a boolean', async () => {
|
|
|
|
const sourceExists = await hasEnglishSource(EXISTING_CHALLENGE_PATH);
|
|
|
|
expect(typeof sourceExists).toBe('boolean');
|
2020-02-24 15:03:21 +01:00
|
|
|
});
|
2020-08-28 17:10:37 +02:00
|
|
|
it('returns true if the English challenge exists', async () => {
|
|
|
|
const sourceExists = await hasEnglishSource(EXISTING_CHALLENGE_PATH);
|
|
|
|
expect(sourceExists).toBe(true);
|
2020-02-24 15:03:21 +01:00
|
|
|
});
|
2020-08-28 17:10:37 +02:00
|
|
|
it('returns false if the English challenge is missing', async () => {
|
|
|
|
const sourceExists = await hasEnglishSource(MISSING_CHALLENGE_PATH);
|
|
|
|
expect(sourceExists).toBe(false);
|
2020-02-24 15:03:21 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|