Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 28d0781

Browse files
WardormeurArayB
authored andcommitted
Setup tests
1 parent 16539e5 commit 28d0781

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

cypress/fixtures/dojo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"notes": "<h2>Suggested Notes:<br />\n<br />\nPlease bring:</h2>\n\n<ul>\n\t<li>\n\t<h2>A laptop. Borrow one from somebody if needs be.</h2>\n\t</li>\n\t<li>\n\t<h2><strong>A parent! (Very important). If you are 12 or under, your parent must stay with you during the session.</strong></h2>\n\t</li>\n</ul>\n\n<h2>&nbsp;</h2>\n",
2020
"needMentors": 0,
2121
"placeName": "Dublin",
22+
"city": {
23+
"name": "Dublin"
24+
},
2225
"frequency": "other",
2326
"alternativeFrequency": "Sunday 10am",
2427
"website": null,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import page from '../../pages/event-form';
2+
3+
describe('Event form', () => {
4+
beforeEach(() => {
5+
cy.server();
6+
cy.route('/api/2.0/users/instance', 'fx:parentLoggedIn');
7+
cy.route('/api/2.0/dojos/d1', 'fx:dojo').as('dojo');
8+
});
9+
10+
it('should display the form', () => {
11+
cy.visit('/dashboard/dojos/d1/events/new');
12+
cy.wait('@dojo');
13+
cy.get(page.header).should('be.visible');
14+
cy.get(page.submitButton).should('be.visible');
15+
cy.get(page.submitButton).invoke('text').should('contain', 'Publish and email members');
16+
});
17+
});

cypress/pages/event-form.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
header: '.cd-event-form__header',
3+
submitButton: '.cd-event-form__button-default-submit',
4+
};

src/events/cd-event-form.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<input type="datetime-local" name="day" :value="today" :min="today">
4343
</div>
4444
<dropdown type="primary" display="splitted" class="cd-event-form__button">
45-
<button slot="submit" type="submit" class="btn btn-primary">
45+
<button slot="submit" type="submit" class="btn btn-primary cd-event-form__button-default-submit">
4646
{{ $t('Publish and email members') }}
4747
</button>
4848
<li><a href="#">Publish only</a></li>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import vueUnitHelper from 'vue-unit-helper';
2+
import eventForm from '!!vue-loader?inject!@/events/cd-event-form';
3+
4+
describe('Event Form component', () => {
5+
let sandbox;
6+
let EventFormWithMocks;
7+
let MockDojosService;
8+
9+
beforeEach(() => {
10+
sandbox = sinon.sandbox.create();
11+
MockDojosService = {
12+
getDojoById: sandbox.stub(),
13+
};
14+
EventFormWithMocks = eventForm({
15+
'@/dojos/service': MockDojosService,
16+
});
17+
});
18+
19+
afterEach(() => {
20+
sandbox.restore();
21+
});
22+
23+
describe('lifecycle functions', () => {
24+
describe('created', () => {
25+
it('should load user and event data', async () => {
26+
// ARRANGE
27+
MockDojosService.getDojoById.resolves({
28+
body: {
29+
city: { name: 'Here' },
30+
address1: 'There',
31+
},
32+
});
33+
const vm = vueUnitHelper(EventFormWithMocks);
34+
vm.$route = {
35+
params: {
36+
dojoId: 'd1',
37+
},
38+
};
39+
// ACT
40+
await vm.$lifecycleMethods.created();
41+
42+
// ASSERT
43+
expect(MockDojosService.getDojoById).to.have.been.calledOnce
44+
.and.calledWith('d1');
45+
expect(vm.address).to.equal('There');
46+
expect(vm.city).to.equal('Here');
47+
});
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)