Skip to content

Commit

Permalink
Add test for template
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Jan 23, 2024
1 parent 9f8a22f commit 423a33c
Showing 1 changed file with 105 additions and 3 deletions.
108 changes: 105 additions & 3 deletions __tests__/templates/MMM-CTA.njk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,113 @@ nunjucks = require('../../__mocks__/nunjucks');

translate = (str) => str;

let data;
let template;

describe('loading', () => {
it('shows loading', () => {
const payload = { loading: true };
const template = nunjucks.render('MMM-CTA.njk', payload);
beforeEach(() => {
data = { loading: true };
template = nunjucks.render('MMM-CTA.njk', data);
});

it('shows loading', () => {
expect(template).toContain('LOADING');
});
});

describe('train stop', () => {
beforeEach(() => {
data = {
stops: [{
type: 'train',
name: 'Train Stop',
arrivals: [
{
direction: 'North',
arrival: 5,
},
{
direction: 'South',
arrival: 10,
},
],
}],
};
template = nunjucks.render('MMM-CTA.njk', data);
});

it('shows train stop name', () => {
expect(template).toContain('Train Stop');
});

it('shows train stop directions', () => {
expect(template).toContain('North');
expect(template).toContain('South');
});

it('shows train stop arrivals', () => {
expect(template).toContain('5');
expect(template).toContain('10');
});
});

describe('bus stop', () => {
beforeEach(() => {
data = {
stops: [{
type: 'bus',
name: 'Bus Stop',
arrivals: [
{
direction: 'North',
arrival: 5,
},
{
direction: 'South',
arrival: 10,
},
],
}],
};
template = nunjucks.render('MMM-CTA.njk', data);
});

it('shows bus stop name', () => {
expect(template).toContain('Bus Stop');
});

it('shows bus stop directions', () => {
expect(template).toContain('North');
expect(template).toContain('South');
});

it('shows bus stop arrivals', () => {
expect(template).toContain('5');
expect(template).toContain('10');
});
});

describe('multiple stops', () => {
beforeEach(() => {
data = {
stops: [
{
type: 'bus',
name: 'Bus Stop',
arrivals: [],
},
{
type: 'train',
name: 'Train Stop',
arrivals: [],
},
],
};
template = nunjucks.render('MMM-CTA.njk', data);
});

it('shows all stop names', () => {
expect(template).toContain('Bus Stop');
expect(template).toContain('Train Stop');
});
});

0 comments on commit 423a33c

Please sign in to comment.