mattermost-desktop/e2e/specs/startup/config.test.js
Devin Binnie 4fa89a5fce
[MM-40144] Restructure tests, add test case numbers, some cleanup (#1864)
* [MM-40144] Restructure tests, add test case numbers, some cleanup

* Fix a test
2021-11-19 10:21:34 -05:00

77 lines
2.7 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
const fs = require('fs');
const env = require('../../modules/environment');
describe('config', function desc() {
this.timeout(30000);
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
});
afterEach(async () => {
if (this.app) {
try {
await this.app.close();
// eslint-disable-next-line no-empty
} catch (err) {}
}
});
describe('MM-T4401 should show servers in dropdown when there is config file', async () => {
const config = env.demoConfig;
beforeEach(async () => {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = await env.getApp();
});
afterEach(async () => {
if (this.app) {
try {
await this.app.close();
// eslint-disable-next-line no-empty
} catch (err) {}
}
});
it('MM-T4401_1 should show correct server in the dropdown button', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('example');
});
it('MM-T4401_2 should set src of browser view from config file', async () => {
const firstServer = this.app.windows().find((window) => window.url() === config.teams[0].url);
const secondServer = this.app.windows().find((window) => window.url() === config.teams[1].url);
firstServer.should.not.be.null;
secondServer.should.not.be.null;
});
});
it('MM-T4402 should upgrade v0 config file', async () => {
const Config = require('../../../src/common/config').default;
const newConfig = new Config(env.configFilePath);
const oldConfig = {
url: env.mattermostURL,
};
fs.writeFileSync(env.configFilePath, JSON.stringify(oldConfig));
this.app = await env.getApp();
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton:has-text("Primary team")');
dropdownButtonText.should.equal('Primary team');
const str = fs.readFileSync(env.configFilePath, 'utf8');
const upgradedConfig = JSON.parse(str);
upgradedConfig.version.should.equal(newConfig.defaultData.version);
await this.app.close();
});
});