@@ -3,63 +3,121 @@ import { module, test } from 'qunit';
33import { setupApplicationTest } from 'ember-qunit' ;
44import Pretender from 'pretender' ;
55
6- const CHANGELOG_URL = 'https://raw.githubusercontent.com/emberjs/ember-inspector/master/CHANGELOG.md' ;
7- const CHANGELOG_RESPONSE = `
8- # Changelog
6+ function urlFor ( ref ) {
7+ return `https://raw.githubusercontent.com/emberjs/ember-inspector/ ${ encodeURIComponent ( ref ) } /CHANGELOG.md` ;
8+ }
99
10+ function generateContent ( master = false ) {
11+ let content = [ ] ;
12+
13+ content . push ( `# Changelog` ) ;
14+
15+ if ( master ) {
16+ content . push ( `
1017## [Unreleased](https://github.com/emberjs/ember-inspector/tree/HEAD)
1118
1219**Merged pull requests:**
1320
14- - Stuff
21+ - Stuff` ) ;
22+ }
1523
24+ content . push ( `
1625## [v3.3.0](https://github.com/emberjs/ember-inspector/tree/v3.3.0) (2018-08-02)
1726
1827[Full Changelog](https://emberjs.com)
1928
2029**Implemented enhancements:**
2130
31+ - Stuff
32+
2233## [v3.2.0](https://github.com/emberjs/ember-inspector/tree/v3.2.0) (2018-07-03)
2334
2435[Full Changelog](https://emberjs.com)
2536
2637**Fixed bugs:**
2738
28- - Data
29- ` ;
39+ - Data` ) ;
40+
41+ return content . join ( '\n' ) ;
42+ }
3043
31- module ( 'Whats New' , function ( hooks ) {
32- setupApplicationTest ( hooks ) ;
44+ module ( 'Whats New' , function ( outer ) {
45+ setupApplicationTest ( outer ) ;
46+
47+ outer . beforeEach ( function ( ) {
48+ this . config = this . owner . lookup ( 'config:main' ) ;
49+ this . originalVersion = this . config . version ;
50+ } ) ;
51+
52+ outer . afterEach ( function ( ) {
53+ this . config . version = this . originalVersion ;
3354
34- hooks . afterEach ( function ( ) {
3555 if ( this . server ) {
3656 this . server . shutdown ( ) ;
3757 }
3858 } ) ;
3959
40- test ( 'Changelog is parsed and displayed' , async function ( assert ) {
41- this . server = new Pretender ( function ( ) {
42- this . get ( CHANGELOG_URL , ( ) => [ 200 , { 'Content-Type' : 'text/plain' } , CHANGELOG_RESPONSE ] ) ;
60+ module ( 'Released version' , function ( inner ) {
61+ inner . beforeEach ( function ( ) {
62+ this . config . version = '3.3.0' ;
63+ } ) ;
64+
65+ test ( 'Changelog is parsed and displayed' , async function ( assert ) {
66+ this . server = new Pretender ( function ( ) {
67+ this . get ( urlFor ( 'v3.3.0' ) , ( ) => [ 200 , { 'Content-Type' : 'text/plain' } , generateContent ( ) ] ) ;
68+ } ) ;
69+
70+ await visit ( '/info/whats-new' ) ;
71+
72+ assert . dom ( '.whats-new h2' ) . exists ( { count : 1 } , 'correct section of markdown is rendered' ) ;
73+
74+ assert . equal (
75+ find ( '.whats-new h2 a' ) . text ,
76+ 'v3.3.0' ,
77+ 'correct section of markdown is rendered'
78+ ) ;
4379 } ) ;
4480
45- await visit ( '/info/whats-new' ) ;
81+ test ( 'Error message is displayed on request failure' , async function ( assert ) {
82+ this . server = new Pretender ( function ( ) {
83+ this . get ( urlFor ( 'v3.3.0' ) , ( ) => [ 404 , { } , '' ] ) ;
84+ } ) ;
4685
47- assert . dom ( '. whats-new h2' ) . exists ( { count : 1 } , 'correct section of markdown is rendered ') ;
86+ await visit ( '/info/ whats-new') ;
4887
49- assert . equal (
50- find ( '.whats-new h2 a' ) . text ,
51- 'v3.3.0' ,
52- 'correct section of markdown is rendered'
53- ) ;
88+ assert . dom ( '.whats-new p' ) . exists ( { count : 1 } , 'Changelog could not be loaded' ) ;
89+ } ) ;
5490 } ) ;
5591
56- test ( 'Error message is displayed on request failure ', async function ( assert ) {
57- this . server = new Pretender ( function ( ) {
58- this . get ( CHANGELOG_URL , ( ) => [ 404 , { } , '' ] ) ;
92+ module ( 'Nightly version ', function ( inner ) {
93+ inner . beforeEach ( function ( ) {
94+ this . config . version = '3.4.0-alpha.1' ;
5995 } ) ;
6096
61- await visit ( '/info/whats-new' ) ;
97+ test ( 'Changelog is parsed and displayed' , async function ( assert ) {
98+ this . server = new Pretender ( function ( ) {
99+ this . get ( urlFor ( 'master' ) , ( ) => [ 200 , { 'Content-Type' : 'text/plain' } , generateContent ( true ) ] ) ;
100+ } ) ;
101+
102+ await visit ( '/info/whats-new' ) ;
103+
104+ assert . dom ( '.whats-new h2' ) . exists ( { count : 1 } , 'correct section of markdown is rendered' ) ;
62105
63- assert . dom ( '.whats-new p' ) . exists ( { count : 1 } , 'Changelog could not be loaded' ) ;
106+ assert . equal (
107+ find ( '.whats-new h2 a' ) . text ,
108+ 'Unreleased' ,
109+ 'correct section of markdown is rendered'
110+ ) ;
111+ } ) ;
112+
113+ test ( 'Error message is displayed on request failure' , async function ( assert ) {
114+ this . server = new Pretender ( function ( ) {
115+ this . get ( urlFor ( 'master' ) , ( ) => [ 404 , { } , '' ] ) ;
116+ } ) ;
117+
118+ await visit ( '/info/whats-new' ) ;
119+
120+ assert . dom ( '.whats-new p' ) . exists ( { count : 1 } , 'Changelog could not be loaded' ) ;
121+ } ) ;
64122 } ) ;
65123} ) ;
0 commit comments