Files
mattermostest/e2e/specs/startup/config.test.js
Devin Binnie 39fbdf45c5 [MM-40406] Add more singletons, refactor main.ts into pieces, add tests and some cleanup + tests for additional coverage (#1890)
* Refactor main.ts dependencies into singleton pattern

* Split main.ts into testable pieces, some other refactoring for singleton pattern

* Unit tests for main/app/app

* Unit tests for main/app/config

* Unit tests for main/app/initialize

* Unit tests for main/app/intercom

* Unit tests for main/app/utils

* Add some more tests to get to 70% coverage

* Fix for linux

* Fix for alternate data dir paths

* Fix E2E test
2021-12-09 15:11:55 -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').Config;
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();
});
});