Commit e592be3e authored by Rémy Coutable's avatar Rémy Coutable

Move a first batch of EE-specific JS specs to ee/spec/javascripts

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent c975e29e
import Vue from 'vue';
import addGitlabSlackApplication from 'ee/add_gitlab_slack_application/components/add_gitlab_slack_application.vue';
import GitlabSlackService from 'ee/add_gitlab_slack_application/services/gitlab_slack_service';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('AddGitlabSlackApplication', () => {
const redirectLink = '//redirectLink';
const gitlabForSlackGifPath = '//gitlabForSlackGifPath';
const signInPath = '//signInPath';
const slackLinkPath = '//slackLinkPath';
const docsPath = '//docsPath';
const gitlabLogoPath = '//gitlabLogoPath';
const slackLogoPath = '//slackLogoPath';
const projects = [{
id: 4,
name: 'test',
}, {
id: 6,
name: 'nope',
}];
const DEFAULT_PROPS = {
projects,
gitlabForSlackGifPath,
signInPath,
slackLinkPath,
docsPath,
gitlabLogoPath,
slackLogoPath,
isSignedIn: false,
};
const AddGitlabSlackApplication = Vue.extend(addGitlabSlackApplication);
it('opens popup when button is clicked', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.$el.querySelector('.js-popup-button').click();
vm.$nextTick()
.then(() => expect(vm.$el.querySelector('.js-popup')).toBeDefined())
.then(done)
.catch(done.fail);
});
it('hides popup when button is clicked', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.popupOpen = true;
vm.$nextTick()
.then(() => vm.$el.querySelector('.js-popup-button').click())
.then(vm.$nextTick)
.then(() => expect(vm.$el.querySelector('.js-popup')).toBeNull())
.then(done)
.catch(done.fail);
});
it('popup has a project select when signed in', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
isSignedIn: true,
});
vm.popupOpen = true;
vm.$nextTick()
.then(() => expect(vm.$el.querySelector('.js-project-select')).toBeDefined())
.then(done)
.catch(done.fail);
});
it('popup has a message when there is no projects', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
projects: [],
isSignedIn: true,
});
vm.popupOpen = true;
vm.$nextTick()
.then(() => {
expect(vm.$el.querySelector('.js-no-projects').textContent)
.toMatch("You don't have any projects available.");
})
.then(done)
.catch(done.fail);
});
it('popup has a sign in link when logged out', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
});
vm.popupOpen = true;
vm.selectedProjectId = 4;
vm.$nextTick()
.then(() => {
expect(vm.$el.querySelector('.js-gitlab-slack-sign-in-link').href)
.toMatch(new RegExp(signInPath, 'i'));
})
.then(done)
.catch(done.fail);
});
it('redirects user to external link when submitted', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
isSignedIn: true,
});
const addToSlackPromise = Promise.resolve({ data: { add_to_slack_link: redirectLink } });
spyOn(GitlabSlackService, 'addToSlack').and.returnValue(addToSlackPromise);
const redirectTo = spyOnDependency(addGitlabSlackApplication, 'redirectTo');
vm.popupOpen = true;
vm.$nextTick()
.then(() => vm.$el.querySelector('.js-add-button').click())
.then(vm.$nextTick)
.then(addToSlackPromise)
.then(() => expect(redirectTo).toHaveBeenCalledWith(redirectLink))
.then(done)
.catch(done.fail);
});
});
import Vue from 'vue';
import DeployBoard from 'ee/environments/components/deploy_board_component.vue';
import { deployBoardMockData, environment } from './mock_data';
import { deployBoardMockData, environment } from 'spec/environments/mock_data';
describe('Deploy Board', () => {
let DeployBoardComponent;
......
import Vue from 'vue';
import DeployBoardInstance from 'ee/environments/components/deploy_board_instance_component.vue';
import { folder } from './mock_data';
import { folder } from 'spec/environments/mock_data';
describe('Deploy Board Instance', () => {
let DeployBoardInstanceComponent;
......
......@@ -2,7 +2,7 @@ import $ from 'jquery';
import KubernetesLogs from 'ee/kubernetes_logs';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import { logMockData, podMockData } from './ee/kubernetes_mock_data';
import { logMockData, podMockData } from './kubernetes_mock_data';
describe('Kubernetes Logs', () => {
const fixtureTemplate = 'static/environments_logs.html.raw';
......
import Vue from 'vue';
import addGitlabSlackApplication from 'ee/add_gitlab_slack_application/components/add_gitlab_slack_application.vue';
import GitlabSlackService from 'ee/add_gitlab_slack_application/services/gitlab_slack_service';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('AddGitlabSlackApplication', () => {
const redirectLink = '//redirectLink';
const gitlabForSlackGifPath = '//gitlabForSlackGifPath';
const signInPath = '//signInPath';
const slackLinkPath = '//slackLinkPath';
const docsPath = '//docsPath';
const gitlabLogoPath = '//gitlabLogoPath';
const slackLogoPath = '//slackLogoPath';
const projects = [{
id: 4,
name: 'test',
}, {
id: 6,
name: 'nope',
}];
const DEFAULT_PROPS = {
projects,
gitlabForSlackGifPath,
signInPath,
slackLinkPath,
docsPath,
gitlabLogoPath,
slackLogoPath,
isSignedIn: false,
};
const AddGitlabSlackApplication = Vue.extend(addGitlabSlackApplication);
it('opens popup when button is clicked', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.$el.querySelector('.js-popup-button').click();
vm.$nextTick()
.then(() => expect(vm.$el.querySelector('.js-popup')).toBeDefined())
.then(done)
.catch(done.fail);
});
it('hides popup when button is clicked', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.popupOpen = true;
vm.$nextTick()
.then(() => vm.$el.querySelector('.js-popup-button').click())
.then(vm.$nextTick)
.then(() => expect(vm.$el.querySelector('.js-popup')).toBeNull())
.then(done)
.catch(done.fail);
});
it('popup has a project select when signed in', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
isSignedIn: true,
});
vm.popupOpen = true;
vm.$nextTick()
.then(() => expect(vm.$el.querySelector('.js-project-select')).toBeDefined())
.then(done)
.catch(done.fail);
});
it('popup has a message when there is no projects', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
projects: [],
isSignedIn: true,
});
vm.popupOpen = true;
vm.$nextTick()
.then(() => {
expect(vm.$el.querySelector('.js-no-projects').textContent)
.toMatch("You don't have any projects available.");
})
.then(done)
.catch(done.fail);
});
it('popup has a sign in link when logged out', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
});
vm.popupOpen = true;
vm.selectedProjectId = 4;
vm.$nextTick()
.then(() => {
expect(vm.$el.querySelector('.js-gitlab-slack-sign-in-link').href)
.toMatch(new RegExp(signInPath, 'i'));
})
.then(done)
.catch(done.fail);
});
it('redirects user to external link when submitted', (done) => {
const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS,
isSignedIn: true,
});
const addToSlackPromise = Promise.resolve({ data: { add_to_slack_link: redirectLink } });
spyOn(GitlabSlackService, 'addToSlack').and.returnValue(addToSlackPromise);
const redirectTo = spyOnDependency(addGitlabSlackApplication, 'redirectTo');
vm.popupOpen = true;
vm.$nextTick()
.then(() => vm.$el.querySelector('.js-add-button').click())
.then(vm.$nextTick)
.then(addToSlackPromise)
.then(() => expect(redirectTo).toHaveBeenCalledWith(redirectLink))
.then(done)
.catch(done.fail);
});
});
......@@ -7,23 +7,23 @@ describe ApplicationController, '(Static JavaScript fixtures)', type: :controlle
clean_frontend_fixtures('static/')
end
fixtures_path = File.expand_path(JavaScriptFixturesHelpers::FIXTURE_PATH, Rails.root)
haml_fixtures = Dir.glob(File.expand_path('**/*.haml', fixtures_path)).map do |file_path|
file_path.sub(/\A#{fixtures_path}#{File::SEPARATOR}/, '')
end
JavaScriptFixturesHelpers::FIXTURE_PATHS.each do |fixture_path|
fixtures_path = File.expand_path(fixture_path, Rails.root)
Dir.glob(File.expand_path('**/*.haml', fixtures_path)).map do |file_path|
template_file_name = file_path.sub(/\A#{fixtures_path}#{File::SEPARATOR}/, '')
haml_fixtures.each do |template_file_name|
it "static/#{template_file_name.sub(/\.haml\z/, '.raw')}" do |example|
fixture_file_name = example.description
rendered = render_template(template_file_name)
rendered = render_template(fixture_path, template_file_name)
store_frontend_fixture(rendered, fixture_file_name)
end
end
end
private
def render_template(template_file_name)
fixture_path = JavaScriptFixturesHelpers::FIXTURE_PATH
def render_template(fixture_path, template_file_name)
controller = ApplicationController.new
controller.prepend_view_path(fixture_path)
controller.render_to_string(template: template_file_name, layout: false)
......
......@@ -4,31 +4,35 @@ require 'fileutils'
module JavaScriptFixturesHelpers
include Gitlab::Popen
FIXTURE_PATH = 'spec/javascripts/fixtures'.freeze
FIXTURE_PATHS = %w[spec/javascripts/fixtures ee/spec/javascripts/fixtures].freeze
# Public: Removes all fixture files from given directory
#
# directory_name - directory of the fixtures (relative to FIXTURE_PATH)
# directory_name - directory of the fixtures (relative to FIXTURE_PATHS)
#
def clean_frontend_fixtures(directory_name)
directory_name = File.expand_path(directory_name, FIXTURE_PATH)
FIXTURE_PATHS.each do |fixture_path|
directory_name = File.expand_path(directory_name, fixture_path)
Dir[File.expand_path('*.html.raw', directory_name)].each do |file_name|
FileUtils.rm(file_name)
end
end
end
# Public: Store a response object as fixture file
#
# response - string or response object to store
# fixture_file_name - file name to store the fixture in (relative to FIXTURE_PATH)
# fixture_file_name - file name to store the fixture in (relative to FIXTURE_PATHS)
#
def store_frontend_fixture(response, fixture_file_name)
fixture_file_name = File.expand_path(fixture_file_name, FIXTURE_PATH)
FIXTURE_PATHS.each do |fixture_path|
fixture_file_name = File.expand_path(fixture_file_name, fixture_path)
fixture = response.respond_to?(:body) ? parse_response(response) : response
FileUtils.mkdir_p(File.dirname(fixture_file_name))
File.write(fixture_file_name, fixture)
end
end
def remove_repository(project)
Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment