Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
RC 1.2.0 - Slack improvements (#107)
Browse files Browse the repository at this point in the history
* RC 1.1.0

* Testing request URL previews for Slack messages

* Corrected function param and tests

* Removed --- from Slack messages

* fix typo explaination

* Moved from newline to quotes

* Made Karma bold

* Feature/slack message previews (#106)

* Testing request URL previews for Slack messages

* Corrected function param and tests

* Removed --- from Slack messages

* Moved from newline to quotes

* Made Karma bold

* Harded coded live preview

Added inline quotes to Slack messages

* Testing what is query

* Stringify express query object

* Stored queryString as variable

* Forgot '/'

* Updated test fixture

* Added newline to preview URL

* Renamed homepage -> home

Added ? before querystring

* Forgot '?' for Slack unit test

* Added RC 1.2.0 notes
  • Loading branch information
Adam Zerella authored Jan 8, 2019
1 parent 2961b5d commit a29fe29
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.2.0
- Added Slack message preview URL.
- Spelling tweaks


# 1.1.0
- Implemented asyncronous functionality and Slack integration.

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Wuhuu! thanks for considering contributing! We are always looking to make chamel

## Release history

- v1.1.0 - Asyncronous functionality
- v1.2.0 - Slack improvements
- v1.1.0 - Implemented asyncronous functionality and Slack integration.
- v1.0.1 - Refactoring code
- v1.0.0 - 🎉 Initial release

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chameleon",
"version": "1.1.0",
"version": "1.2.0",
"description": "Interactive colour template previews for the Design System.",
"main": "src/index.js",
"scripts": {
Expand Down
26 changes: 16 additions & 10 deletions src/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Depedencies
const { IncomingWebhook } = require( '@slack/client' );
const ColorString = require( 'color-string' );
const QueryString = require( 'querystring' );


/**
Expand Down Expand Up @@ -75,42 +76,47 @@ const GetTemplateFromURL = ( url ) => {
return baseUrl;
}

return 'homepage';
return 'home';
};


/**
* GenerateChameleonMessage - Creates a formatted message
*
* @param {string} url - The url that hit the API
* @param {string} path - The URL path
* @param {object} query - The queries that hit the API
*
* @returns {string} - The formatted message
*/
const GenerateChameleonMessage = ( url, query ) => {
let message = '---\n_Karma-Karma-Karma-Chameleon!_\n\n';
const GenerateChameleonMessage = ( path, query ) => {
let message = '>>> _*Karma-Karma-Karma-Karma-Karma-Chameleon!*_\n\n';

if( url ) {
const template = GetTemplateFromURL( url );
const template = GetTemplateFromURL( path );
const queryString = QueryString.stringify( query );

if( path ) {
message += `Generating *${ template }* page template\n\n`;
}

if( query !== {}) {
message += QueryToHexString( query );
message += `${ QueryToHexString( query ) }`;
}

// Append a preview URL to message.
message += `\nhttps://designsystem.gov.au/templates/${ template }/customise/?${ queryString }`;

return message;
};


/**
* SendChameleonMessage - Send a slack message to #chameleon
*
* @param {string} url - The url that hit the API
* @param {string} path - The URL path
* @param {object} query - The queries that hit the API
*/
const SendChameleonMessage = ( url, query ) => {
const message = GenerateChameleonMessage( url, query );
const SendChameleonMessage = ( path, query ) => {
const message = GenerateChameleonMessage( path, query );
SendSlackMessage( message );
};

Expand Down
2 changes: 1 addition & 1 deletion templates/content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<img class="au-header__brand-image" alt="Insert alternate text here" src="/chameleon/assets/img/header-logo-agov.png">
<div class="au-header__text">
<h2 class="au-header__heading">Name of website</h2>
<div class="au-header__subline">Simple explaination of the website</div>
<div class="au-header__subline">Simple explanation of the website</div>
</div>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/form/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<img class="au-header__brand-image" alt="Insert alternate text here" src="/chameleon/assets/img/header-logo-agov.png">
<div class="au-header__text">
<h2 class="au-header__heading">Name of website</h2>
<div class="au-header__subline">Simple explaination of the website</div>
<div class="au-header__subline">Simple explanation of the website</div>
</div>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<img class="au-header__brand-image" alt="Insert alternate text here" src="/chameleon/assets/img/header-logo-agov.png">
<div class="au-header__text">
<h2 class="au-header__heading">Name of website</h2>
<div class="au-header__subline">Simple explaination of the website</div>
<div class="au-header__subline">Simple explanation of the website</div>
</div>
</a>
</div>
Expand Down
16 changes: 9 additions & 7 deletions test/unit/slack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ Describe( 'GenerateChameleonMessage()', () => {
action: 'purple',
background: 'red',
};
const url = '/chameleon/form/';
const message = GenerateChameleonMessage( url, query );

let fixture = '---\n_Karma-Karma-Karma-Chameleon!_\n\nGenerating *form* page template\n\n';
const path = '/chameleon/form/';
const message = GenerateChameleonMessage( path, query );

let fixture = '>>> _*Karma-Karma-Karma-Karma-Karma-Chameleon!*_\n\nGenerating *form* page template\n\n';
fixture += '`action`: #800080\n`background`: #FF0000\n';
fixture += `\nhttps://designsystem.gov.au/templates/form/customise/?action=purple&background=red`;

Expect( message ).to.equal( fixture );
});
Expand Down Expand Up @@ -63,12 +65,12 @@ Describe( 'QueryToHexString()', () => {
* GetTemplateFromURL tests
*/
Describe( 'GetTemplateFromURL()', () => {
It( 'Should return the homepage template when requesting /chameleon', () => {
Expect( GetTemplateFromURL( '/chameleon' ) ).to.equal( 'homepage' );
It( 'Should return the home template when requesting /chameleon', () => {
Expect( GetTemplateFromURL( '/chameleon' ) ).to.equal( 'home' );
});

It( 'Should return the homepage template when requesting /chameleon/', () => {
Expect( GetTemplateFromURL( '/chameleon/' ) ).to.equal( 'homepage' );
It( 'Should return the home template when requesting /chameleon/', () => {
Expect( GetTemplateFromURL( '/chameleon/' ) ).to.equal( 'home' );
});

It( 'Should return the content template when requesting /chameleon/content', () => {
Expand Down

0 comments on commit a29fe29

Please sign in to comment.