Skip to content

Commit

Permalink
feat: add an example 'Hello, world' app with tests (#4)
Browse files Browse the repository at this point in the history
* feat: add an example 'Hello, world' app with tests

* Exclude examples dir
  • Loading branch information
chrishutchinson committed Aug 30, 2021
1 parent 2249936 commit 2d9b1c1
Show file tree
Hide file tree
Showing 8 changed files with 2,835 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/hello-world-app-home/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
node_modules
33 changes: 33 additions & 0 deletions examples/hello-world-app-home/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Slack Testing Library: Hello World example

> A simple Slack app that publishes "Hello, world!" to the App Home
## Structure

### `./server.ts`

This is the simple HTTP server that powers this Slack app.

### `./__tests__/app-home.test.ts`

The example test that verifies the App Home displays the correct text, once the app home is opened.

## Getting started

1. Install dependencies

```bash
yarn
```

2. Run the HTTP server

```bash
yarn start
```

3. Run the tests

```bash
yarn test
```
26 changes: 26 additions & 0 deletions examples/hello-world-app-home/__tests__/app-home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SlackTestingLibrary } from "../../../src/slack-testing-library";
// import { SlackTestingLibrary } from 'slack-testing-library';

const sl = new SlackTestingLibrary({
baseUrl: "http://localhost:3000",
});

describe("App home", () => {
beforeAll(async () => {
await sl.init();
});

afterAll(async () => {
await sl.teardown();
});

it("should show the text 'Hello, world!' after opening", async () => {
sl.actAs({
teamId: "T12345678",
userId: "U12345678",
});

await sl.openHome();
await sl.getByText("Hello, world!");
});
});
5 changes: 5 additions & 0 deletions examples/hello-world-app-home/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
19 changes: 19 additions & 0 deletions examples/hello-world-app-home/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@slack-testing-library/hello-world-app-home-example",
"version": "1.0.0",
"main": "server.ts",
"license": "MIT",
"scripts": {
"start": "ts-node server.ts",
"test": "jest"
},
"dependencies": {
"@slack/types": "^2.2.0",
"@slack/web-api": "^6.4.0"
},
"devDependencies": {
"jest": "^27.1.0",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1"
}
}
30 changes: 30 additions & 0 deletions examples/hello-world-app-home/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createServer } from "http";
import { WebClient } from "@slack/web-api";

const slackWebApi = new WebClient(process.env.SLACK_BOT_TOKEN, {
slackApiUrl: "http://localhost:8123/slack/api",
});

const server = createServer(async (_req, res) => {
await slackWebApi.views.publish({
view: {
type: "home",
blocks: [
{
type: "section",
text: {
text: "Hello, world!",
type: "plain_text",
},
},
],
},
user_id: "U12345678",
});

res.end();
});

server.listen(3000, () => {
console.log("Server listening on port 3000");
});
Loading

0 comments on commit 2d9b1c1

Please sign in to comment.