forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.test.js
More file actions
200 lines (159 loc) · 6.65 KB
/
Copy pathsetup.test.js
File metadata and controls
200 lines (159 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const puppeteer = require('puppeteer');
const orchard = require('./orchard.js');
let browser;
let page;
let basePath;
let error;
// e.g., npm test --debug
// In debug mode we show the editor, slow down operations, and increase the timeout for each test
let debug = process.env.npm_config_debug || false;
jest.setTimeout(debug ? 60000 : 30000);
beforeAll(async () => {
try {
basePath = orchard.run('../../src/OrchardCore.Cms.Web', 'OrchardCore.Cms.Web.dll');
browser = await puppeteer.launch(debug ? { headless: false, slowMo: 100 } : {});
page = await browser.newPage();
} catch (ex) {
error = ex;
}
});
afterAll(async () => {
if (browser) {
await browser.close();
}
orchard.stop();
orchard.cleanAppData('../../src/OrchardCore.Cms.Web');
orchard.printLog();
});
describe('Browser is initialized', () => {
// Workaround for https://github.com/jasmine/jasmine/issues/1533.
// Jasmine will not report errors from beforeAll and instead continue running tests which will
// inevitably fail since the initial state isn't correct.
// This test allows us to print the error from beforeAll, if any.
test('no errors on launch', () => {
expect(error).toBeUndefined();
// Sanity testing
expect(basePath).toBeDefined();
expect(browser).toBeDefined();
expect(page).toBeDefined();
})
})
describe('Setup', () => {
beforeAll(async () => {
await page.goto(`${basePath}`);
});
it('should display "Orchard Setup"', async () => {
await expect(await page.content()).toMatch('Orchard Setup');
});
it('should focus on the site name', async () => {
await expect(await page.evaluate(() => document.activeElement.id)).toMatch('SiteName');
});
it('should not be able to submit the form', async () => {
// Same as page.keyboard.press('Enter');
await page.click('#SubmitButton');
await expect(await page.evaluate(() => document.activeElement.id)).toMatch('SiteName');
});
it('should setup a SaaS site on sqlite', async () => {
await page.type('#SiteName', 'My Sites');
await page.click('#recipeButton');
await (await page.$x("//a[contains(text(), 'Software as a Service')]"))[0].click();
await page.select('#DatabaseProvider', 'Sqlite');
await page.type('#TablePrefix', '');
await page.type('#UserName', 'admin');
await page.type('#Email', 'admin@orchard.com');
await page.type('#Password', 'Demo123!');
await page.type('#PasswordConfirmation', 'Demo123!');
await Promise.all([
page.waitForNavigation(),
page.click('#SubmitButton')
]);
await expect(await page.content()).toMatch('Welcome to the Orchard Framework, your site has been successfully set up');
});
});
describe('Create Tenants', () => {
it('should display login form', async () => {
await page.goto(`${basePath}/Login`);
await expect(await page.content()).toMatch('Use a local account to log in');
});
it('should login with setup credentials', async () => {
await page.type('#UserName', 'admin');
await page.type('#Password', 'Demo123!');
await Promise.all([
page.waitForNavigation(),
page.keyboard.press('Enter')
]);
await expect(await page.url()).toBe(`${basePath}/`);
await expect(await page.content()).toMatch('admin');
});
it('should display a single tenant', async () => {
await page.goto(`${basePath}/Admin/Tenants`);
await expect(await page.content()).toMatch('Default');
await expect((await page.$$("div.properties")).length).toBe(1);
});
it('should create a tenant based on Agency', async () => {
// Create tenant
await page.goto(`${basePath}/Admin/Tenants/Create`);
await page.type('#Name', 'Agency');
await page.type('#RequestUrlPrefix', 'agency');
await Promise.all([
page.waitForNavigation(),
(await page.$x("//button[contains(text(), 'Create')]"))[0].click()
]);
await expect(await page.url()).toBe(`${basePath}/Admin/Tenants`);
await expect(await page.content()).toMatch('Agency');
// Go to Setup page
await Promise.all([
page.waitForNavigation(),
page.click('#btn-setup-Agency')
]);
await expect(await page.content()).toMatch('Orchard Setup');
// Setup site
await page.type('#SiteName', 'Agency');
await page.click('#recipeButton');
await (await page.$x("//a[contains(text(), 'Agency')]"))[0].click();
await page.select('#DatabaseProvider', 'Sqlite');
await page.type('#TablePrefix', '');
await page.type('#UserName', 'admin');
await page.type('#Email', 'admin@orchard.com');
await page.type('#Password', 'Demo123!');
await page.type('#PasswordConfirmation', 'Demo123!');
await Promise.all([
page.waitForNavigation(),
page.click('#SubmitButton')
]);
await expect(await page.content()).toMatch('Lorem ipsum dolor sit amet consectetur');
});
it('should create a tenant based on Blog', async () => {
// Create tenant
await page.goto(`${basePath}/Admin/Tenants/Create`);
await page.type('#Name', 'Blog');
await page.type('#RequestUrlPrefix', 'blog');
await Promise.all([
page.waitForNavigation(),
(await page.$x("//button[contains(text(), 'Create')]"))[0].click()
]);
await expect(await page.url()).toBe(`${basePath}/Admin/Tenants`);
await expect(await page.content()).toMatch('Blog');
// Go to Setup page
await Promise.all([
page.waitForNavigation(),
page.click('#btn-setup-Blog')
]);
await expect(await page.content()).toMatch('Orchard Setup');
// Setup site
await page.type('#SiteName', 'Blog');
await page.click('#recipeButton');
await (await page.$x("//a[contains(text(), 'Blog')]"))[0].click();
await page.select('#DatabaseProvider', 'Sqlite');
await page.type('#TablePrefix', '');
await page.type('#UserName', 'admin');
await page.type('#Email', 'admin@orchard.com');
await page.type('#Password', 'Demo123!');
await page.type('#PasswordConfirmation', 'Demo123!');
await Promise.all([
page.waitForNavigation(),
page.click('#SubmitButton')
]);
await expect(await page.content()).toMatch('This is the description of your blog');
});
});