Skip to content

Commit

Permalink
Fix format and syntax in .js specs
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecalvo committed Jan 29, 2021
1 parent 713eaca commit 7d65ad0
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 92 deletions.
4 changes: 2 additions & 2 deletions spec/javascripts/bridge-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('bridge', () => {
it('can create bridge', () => {
expect(new mumuki.bridge.Laboratory()).not.toBe(null);
})
})
});
});
4 changes: 2 additions & 2 deletions spec/javascripts/csrf-token-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('csrf token', () => {
it('can create token', () => {
expect(new mumuki.CsrfToken()).not.toBe(null);
})
})
});
});


16 changes: 7 additions & 9 deletions spec/javascripts/editors-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
describe('editors', () => {

beforeEach(() => {
mumuki.CustomEditor.clearSources()
})
mumuki.CustomEditor.clearSources();
});

it('has initially no sources', () => {
expect(mumuki.CustomEditor.hasSources).toBe(false)
expect(mumuki.CustomEditor.hasSources).toBe(false);
});

it('can add a custom source', () => {
Expand All @@ -26,7 +25,7 @@ describe('editors', () => {
<div class="field form-group editor-code">
<textarea class="form-control editor" name="solution[content]" id="solution_content">the standard solution</textarea>
</div>
</form>`)
</form>`);

mumuki.editors.addCustomSource({
getContent() {
Expand All @@ -43,11 +42,10 @@ describe('editors', () => {
<div class="field form-group editor-code">
<textarea class="form-control editor" name="solution[content]" id="solution_content">the solution</textarea>
</div>
</form>`)
</form>`);
expect(mumuki.editors.getSubmission()).toEqual({"solution[content]":"the solution"});
});


it('reads the form if no sources and exercise is multifile', () => {
$('body').html(`
<form role="form" class="new_solution">
Expand All @@ -63,7 +61,7 @@ describe('editors', () => {
name="solution[content[receta.css]]"
id="solution_content[receta.css]">some css</textarea>
</div>
</form>`)
</form>`);
expect(mumuki.editors.getSubmission()).toEqual({
"solution[content[index.html]]": "some html",
"solution[content[receta.css]]": "some css"
Expand All @@ -74,4 +72,4 @@ describe('editors', () => {
$('body').html(``);
expect(mumuki.editors.getSubmission()).toEqual({});
});
})
});
8 changes: 4 additions & 4 deletions spec/javascripts/elipsis-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('elipsis', () => {
it('does nothing when no elipsis', () => {
expect(mumuki.elipsis('hello')).toEqual('hello');
})
});

it('replaces student elipsis', () => {
expect(mumuki.elipsis(`function longitud(unString) {
Expand All @@ -10,7 +10,7 @@ describe('elipsis', () => {
/*@elipsis-for-student&gt;*/
}`)).toEqual(`function longitud(unString) {
/* ... */
}`)
}`);
});

it('replaces student hidden', () => {
Expand All @@ -20,6 +20,6 @@ describe('elipsis', () => {
/*@hidden-for-student&gt;*/
}`)).toEqual(`function longitud(unString) {
/**/
}`)
}`);
});
})
});
14 changes: 7 additions & 7 deletions spec/javascripts/events-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ describe('events', () => {
it('is not called when it is not fired', () => {
mumuki.events.on('foo', (e) => {
fail(`should not be called, but got ${JSON.stringify(e)}`);
})
})
});
});

it('is not called when it is fired but not enabled', () => {
let fired = false;
mumuki.events.on('foo', (e) => {
fail(`should not be called, but got ${JSON.stringify(e)}`);
fired = true;
})
});
mumuki.events.fire('foo', 42);
expect(fired).toBe(false);
})
});

it('is called when it is fired and enabled', () => {
let fired = false;
mumuki.events.enable('foo');
mumuki.events.on('foo', (event) => {
expect(event).toEqual(42);
fired = true;
})
});

mumuki.events.fire('foo', 42);
expect(fired).toBe(true);
})
})
});
});
15 changes: 7 additions & 8 deletions spec/javascripts/exercise-spec.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
describe('exercise', () => {

it('current exercise information is available when present', () => {
$('body').html(`
<input type="hidden" name="mu-exercise-id" id="mu-exercise-id" value="3361" />
<input type="hidden" name="mu-exercise-layout" id="mu-exercise-layout" value="input_right" />
<input type="hidden" name="mu-exercise-settings" id="mu-exercise-settings" value="{}" />`)
<input type="hidden" name="mu-exercise-settings" id="mu-exercise-settings" value="{}" />`);

mumuki.exercise.load();

expect(mumuki.exercise.id).toBe(3361);
expect(mumuki.exercise.layout).toBe('input_right');
expect(mumuki.exercise.settings).toEqual({});
expect(mumuki.exercise.current).not.toBe(null);
})
});

it('current exercise information is available when present and settings are not empty', () => {
$('body').html(`
<input type="hidden" name="mu-exercise-id" id="mu-exercise-id" value="3361" />
<input type="hidden" name="mu-exercise-layout" id="mu-exercise-layout" value="input_right" />
<input type="hidden" name="mu-exercise-settings" id="mu-exercise-settings" value="{&quot;game_framework&quot;:true}" />`)
<input type="hidden" name="mu-exercise-settings" id="mu-exercise-settings" value="{&quot;game_framework&quot;:true}" />`);

mumuki.exercise.load();

expect(mumuki.exercise.id).toBe(3361);
expect(mumuki.exercise.layout).toBe('input_right');
expect(mumuki.exercise.settings.game_framework).toBe(true);
expect(mumuki.exercise.current).not.toBe(null);
})
});

it('current exercise information is available when not present', () => {
$('body').html(``)
$('body').html(``);

mumuki.exercise.load();

expect(mumuki.exercise.id).toBe(null);
expect(mumuki.exercise.layout).toBe(null);
expect(mumuki.exercise.settings).toBe(null);
expect(mumuki.exercise.current).toBe(null);
})
})
});
});
6 changes: 3 additions & 3 deletions spec/javascripts/global-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("global loading", () => {
it("produces no global loading errors", () => {
const error = window['__globalLoadingError__'];
expect(!error).toBe(true, `Expected no global loading errors but got ${error && error.message}`)
})
})
expect(!error).toBe(true, `Expected no global loading errors but got ${error && error.message}`);
});
});
43 changes: 23 additions & 20 deletions spec/javascripts/i18n-spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
describe('I18n', () => {

describe('t / translate', () => {

it('accept english translations', () => {
mumuki.locale = 'en';
expect(mumuki.I18n.translate('passed')).toBe('Everything is in order! Your solution passed all our tests!');
})
});

it('accept spanish translations', () => {
mumuki.locale = 'es';
expect(mumuki.I18n.translate('passed_with_warnings')).toBe('Tu solución funcionó, pero hay cosas que mejorar');
})
});

it('accept chilean translations', () => {
mumuki.locale = 'es-CL';
expect(mumuki.I18n.translate('failed')).toBe('Tu solución no pasó las pruebas');
})
});

it('accept portuguese translations', () => {
mumuki.locale = 'pt';
expect(mumuki.I18n.translate('errored')).toBe('Opa! Sua solução não pode ser executada');
})
});

it('fails when translation missing', () => {
mumuki.locale = 'en';
expect(mumuki.I18n.translate('foo')).toBe('Translation missing: en, `foo`');
})

})
});
});

describe('register', () => {
beforeEach(() => {
Expand All @@ -33,21 +34,23 @@ describe('I18n', () => {
greet: (data) => `Hi ${data.name}`,
errored: "D'Oh!"
}
})
})
});
});

it('overrides existing translation key', () => {
expect(mumuki.I18n.translate('errored')).toBe("D'Oh!");
})
});

it('add missing translation key', () => {
expect(mumuki.I18n.translate('greet', {name: 'Jane'})).toBe('Hi Jane');
})
});

it('keep non overriding translation key', () => {
expect(mumuki.I18n.translate('passed')).toBe('Everything is in order! Your solution passed all our tests!');
})
})
});
});

describe('with some prefix', () => {

fixture.set(`
<div class="mu-kindergarten" data-i18n-prefix="testing">
<button class="mu-kids-button">Click me<button>
Expand All @@ -61,19 +64,19 @@ describe('I18n', () => {
en: {
testing_failed: 'Ops! Execution failed',
}
})
});
});

it('Using prefix with existing translation key', () => {
expect(mumuki.I18n.t('passed')).toBe('Everything is in order! Your solution passed all our tests!');
});

it('Use prefix with none existing translation key but default key exists', () => {
expect(mumuki.I18n.t('failed')).toBe('Ops! Execution failed');
});

it('No key found', () => {
expect(mumuki.I18n.t('foo')).toBe('Translation missing: en, `foo`');
})

});
});

});
14 changes: 6 additions & 8 deletions spec/javascripts/kids-button-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
describe('KidsButton', () => {

let button;

fixture.set(`
Expand All @@ -12,25 +11,24 @@ describe('KidsButton', () => {
beforeEach(() => {
mumuki.kids = new mumuki.Kids();
button = new mumuki.submission.KidsSubmitButton($('.mu-kids-button'));
})
});

it('can create button', () => {
expect(button).not.toBe(null);
})
});

it('overlay is hidden by default', () => {
expect(mumuki.kids.$overlay.css('display')).toBe('none');
})
});

it('call showOverlay on wait', () => {
button.wait();
expect(mumuki.kids.$overlay.css('display')).toBe('block');
})
});

it('call hideOverlay on continue', () => {
button.wait();
button.continue();
expect(mumuki.kids.$overlay.css('display')).toBe('none');
})

})
});
});
10 changes: 5 additions & 5 deletions spec/javascripts/results-renderers-spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
describe('results renderers', () => {
it('can compute class for status', () => {
expect(mumuki.renderers.classForStatus('passed')).toEqual('success');
})
});

it('can compute icon for status', () => {
expect(mumuki.renderers.iconForStatus('pending')).toEqual('fa-circle');
})
});

it('can compute progress list item for status', () => {
expect(mumuki.renderers.progressListItemClassForStatus('passed_with_warnings')).toEqual('progress-list-item text-center warning ');
})
});

it('can compute progress list item for status when active', () => {
expect(mumuki.renderers.progressListItemClassForStatus('failed', true)).toEqual('progress-list-item text-center danger active');
})
})
});
});
5 changes: 2 additions & 3 deletions spec/javascripts/speech-bubble-renderer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ describe('results renderers', () => {
<li>fix that</li>
</ul>
</div>`);
})

})
});
});
Loading

0 comments on commit 7d65ad0

Please sign in to comment.