Skip to content

Commit

Permalink
Merge pull request #3264 from learningequality/hotfixes
Browse files Browse the repository at this point in the history
Master release of last 2 sprints ending 2021-08-02
  • Loading branch information
bjester authored Aug 17, 2021
2 parents 93d54de + 14c1b65 commit ec5cb45
Show file tree
Hide file tree
Showing 70 changed files with 853 additions and 1,105 deletions.
15 changes: 0 additions & 15 deletions .deepsource.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/frontendtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
yarn --frozen-lockfile
npm rebuild node-sass
- name: Run tests
run: yarn run test-jest
run: yarn run test
9 changes: 6 additions & 3 deletions bin/run_minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

run_type = os.getenv("MINIO_RUN_TYPE")

assert run_type in MINIO_RUN_TYPES, "MINIO_RUN_TYPE must be one of {}".format(MINIO_RUN_TYPES)
if run_type not in MINIO_RUN_TYPES:
raise AssertionError("MINIO_RUN_TYPE must be one of {}".format(MINIO_RUN_TYPES))

if run_type == "LOCAL":
cmd = ["minio", "server", "-C", str(MINIO_CONFIG_DIR), str(MINIO_LOCAL_HOME_STORAGE)]
elif run_type == "GCS_PROXY":

assert os.path.exists(GOOGLE_APPLICATION_CREDENTIALS_PATH), "the env var GOOGLE_APPLICATION_CREDENTIALS must be defined," " and pointing to a credentials file for your project."
if not os.path.exists(GOOGLE_APPLICATION_CREDENTIALS_PATH):
raise AssertionError("the env var GOOGLE_APPLICATION_CREDENTIALS must be defined," " and pointing to a credentials file for your project.")

assert GOOGLE_GCS_PROJECT_ID, "$GOOGLE_GCS_PROJECT_ID must be defined with the project" " id where you store your objects."
if not GOOGLE_GCS_PROJECT_ID:
raise AssertionError("$GOOGLE_GCS_PROJECT_ID must be defined with the project" " id where you store your objects.")
cmd = ["minio", "gateway", "gcs", GOOGLE_GCS_PROJECT_ID]
else:
raise Exception("Unhandled run_type type: {}".format(run_type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function generateFilterMixin(filterMap) {
const query = transform(
params,
(result, value, key) => {
if (value != null) {
if (value !== null) {
result[key] = value;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@
},
featureFlagValue() {
return function(key) {
return this.loading ? false : this.details.feature_flags[key] || false;
return this.loading
? false
: (this.details && this.details.feature_flags && this.details.feature_flags[key]) ||
false;
};
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ const makeWrapper = ({ store, topicId = TOPIC.id }) => {
localVue,
router,
store,
stubs: {
NodePanel: true,
},
});
};

function getNodeListItems(wrapper) {
return wrapper.findAll('[data-test="node-list-item"]');
}

function hasEditSelectedBtn(wrapper) {
return wrapper.contains('[data-test="edit-selected-btn"]');
}
Expand All @@ -77,11 +76,8 @@ function hasDeleteSelectedBtn(wrapper) {
return wrapper.contains('[data-test="delete-selected-btn"]');
}

function selectNode(wrapper, nodeIdx) {
const nodeCheckbox = getNodeListItems(wrapper)
.at(nodeIdx)
.find('input[type="checkbox"]');
nodeCheckbox.setChecked();
function selectNode(wrapper) {
wrapper.vm.selected = [NODE_1.id];
}

describe('CurrentTopicView', () => {
Expand All @@ -99,9 +95,6 @@ describe('CurrentTopicView', () => {
global.CHANNEL_EDIT_GLOBAL.channel_id = CHANNEL.id;

const storeConfig = cloneDeep(STORE_CONFIG);
// `loadChildren` call needs to be resolved for NodePanel
// to finish loading (see NodePanel's `created` hook)
jest.spyOn(storeConfig.modules.contentNode.actions, 'loadChildren').mockResolvedValue();
store = storeFactory(storeConfig);

store.commit('channel/ADD_CHANNEL', CHANNEL);
Expand All @@ -117,14 +110,6 @@ describe('CurrentTopicView', () => {
jest.resetAllMocks();
});

it('should display all nodes of a topic', () => {
const nodeListItems = getNodeListItems(wrapper);

expect(nodeListItems.length).toBe(2);
expect(nodeListItems.at(0).text()).toContain('Test node 1');
expect(nodeListItems.at(1).text()).toContain('Test node 2');
});

it("shouldn't display any nodes operations buttons when no nodes are selected", () => {
expect(hasEditSelectedBtn(wrapper)).toBe(false);
expect(hasCopySelectedToClipboardBtn(wrapper)).toBe(false);
Expand All @@ -135,7 +120,7 @@ describe('CurrentTopicView', () => {

describe("when a user can't edit a channel", () => {
it('should display only copy to clipboard button when some nodes are selected', () => {
selectNode(wrapper, 0);
selectNode(wrapper);

expect(hasCopySelectedToClipboardBtn(wrapper)).toBe(true);
expect(hasEditSelectedBtn(wrapper)).toBe(false);
Expand All @@ -151,7 +136,7 @@ describe('CurrentTopicView', () => {
});

it('should display all nodes operations buttons when some nodes are selected', () => {
selectNode(wrapper, 0);
selectNode(wrapper);

expect(hasCopySelectedToClipboardBtn(wrapper)).toBe(true);
expect(hasEditSelectedBtn(wrapper)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<ResourceDrawer
:nodeId="previewNodeId"
:channelId="currentChannelId"
style="margin-top: 64px; max-height: calc(100vh-64px);"
style="margin-top: 64px; max-height: calc(100vh - 64px);"
app
@close="previewNodeId = null"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@
};
}
function generateExtraFieldsGetterSetter(key) {
function generateExtraFieldsGetterSetter(key, defaultValue) {
return {
get() {
return this.getExtraFieldsValueFromNodes(key);
return this.getExtraFieldsValueFromNodes(key, defaultValue);
},
set(value) {
this.updateExtraFields({ [key]: value });
Expand Down Expand Up @@ -415,7 +415,7 @@
/* FORM FIELDS */
title: generateGetterSetter('title'),
description: generateGetterSetter('description'),
randomizeOrder: generateExtraFieldsGetterSetter('randomize'),
randomizeOrder: generateExtraFieldsGetterSetter('randomize', true),
author: generateGetterSetter('author'),
provider: generateGetterSetter('provider'),
aggregator: generateGetterSetter('aggregator'),
Expand Down Expand Up @@ -621,14 +621,14 @@
let results = uniq(this.nodes.map(node => node[key] || null));
return getValueFromResults(results);
},
getExtraFieldsValueFromNodes(key) {
getExtraFieldsValueFromNodes(key, defaultValue = null) {
if (
Object.prototype.hasOwnProperty.call(this.diffTracker, 'extra_fields') &&
Object.prototype.hasOwnProperty.call(this.diffTracker.extra_fields, key)
) {
return this.diffTracker.extra_fields[key];
}
let results = uniq(this.nodes.map(node => node.extra_fields[key] || null));
let results = uniq(this.nodes.map(node => node.extra_fields[key] || defaultValue));
return getValueFromResults(results);
},
getPlaceholder(field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
currentLocationId() {
// If opening modal from inside TrashModal, begin navigation at root node
if (this.movingFromTrash) {
return this.currentChannel.root_id;
return this.currentChannel && this.currentChannel.root_id;
}
const contentNode = this.getContentNode(this.moveNodeIds[0]);
return contentNode && contentNode.parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export function updateAnswersToQuestionType(questionType, answers) {
}

export function isImportedContent(node) {
return !!(node && node.original_source_node_id && node.node_id !== node.original_source_node_id);
return Boolean(
node && node.original_source_node_id && node.node_id !== node.original_source_node_id
);
}

export function importedChannelLink(node, router) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function makeWrapper(items) {
methods: {
loadContentNodes: jest.fn(),
loadAncestors: jest.fn(),
loadChildren: jest.fn(() => Promise.resolve()),
},
stubs: {
ResourceDrawer: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('contentNode actions', () => {
return ContentNode.put(contentNodeDatum).then(newId => {
id = newId;
contentNodeDatum.id = newId;
jest
.spyOn(ContentNode, 'fetchCollection')
.mockImplementation(() => Promise.resolve([contentNodeDatum]));
jest
.spyOn(ContentNode, 'fetchModel')
.mockImplementation(() => Promise.resolve(contentNodeDatum));
return ContentNode.put({ title: 'notatest', parent: newId, lft: 2 }).then(() => {
store = storeFactory({
modules: {
Expand All @@ -34,6 +40,7 @@ describe('contentNode actions', () => {
});
});
afterEach(() => {
jest.restoreAllMocks();
return ContentNode.table.toCollection().delete();
});
describe('loadContentNodes action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function fetchResourceSearchResults(context, params) {
export function loadChannels(context, params) {
// Used for search channel filter dropdown
params.page_size = 25;
return Channel.requestCollection({ deleted: false, ...params }).then(channelPage => {
return Channel.fetchCollection({ deleted: false, ...params }).then(channelPage => {
return channelPage;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ const NEW_CHANNEL_SET = {
[NEW_OBJECT]: true,
};

const loadChannelSetMock = (cs, store) => {
return jest.fn().mockImplementation(() => {
store.commit('channelSet/ADD_CHANNELSET', cs);
return Promise.resolve(cs);
});
};

const makeWrapper = ({ store, channelSetId }) => {
if (router.currentRoute.name !== RouteNames.CHANNEL_SET_DETAILS) {
router.push({
Expand All @@ -55,21 +62,24 @@ const makeWrapper = ({ store, channelSetId }) => {
});
}

return mount(ChannelSetModal, {
const loadChannelSet = loadChannelSetMock(CHANNEL_SET, store);
const loadChannelList = jest.fn().mockImplementation(() => Promise.resolve(CHANNEL_SET.channels));

const wrapper = mount(ChannelSetModal, {
propsData: {
channelSetId,
},
methods: {
loadChannelSet,
loadChannelList,
},
router,
localVue,
store,
});
};

const loadChannelSetMock = channelSet => {
return jest.fn().mockImplementation(({ commit }) => {
commit('ADD_CHANNELSET', channelSet);
return Promise.resolve(channelSet);
});
wrapper.loadChannelSet = loadChannelSet;
wrapper.loadChannelList = loadChannelList;
return wrapper;
};

const getCollectionNameInput = wrapper => {
Expand Down Expand Up @@ -110,54 +120,47 @@ describe('ChannelSetModal', () => {
});

describe('if there are no data for a channel set yet', () => {
let loadChannelSet, loadChannelList;

let wrapper;
beforeEach(() => {
const storeConfig = cloneDeep(STORE_CONFIG);
loadChannelSet = loadChannelSetMock(CHANNEL_SET);
loadChannelList = jest.fn();
storeConfig.modules.channelSet.actions.loadChannelSet = loadChannelSet;
storeConfig.modules.channel.actions.loadChannelList = loadChannelList;

const store = storeFactory(storeConfig);

makeWrapper({ store, channelSetId: CHANNEL_SET.id });
wrapper = makeWrapper({ store, channelSetId: CHANNEL_SET.id });
});

it('should load the channel set', () => {
expect(loadChannelSet).toHaveBeenCalledTimes(1);
expect(loadChannelSet.mock.calls[0][1]).toBe(CHANNEL_SET.id);
expect(wrapper.loadChannelSet).toHaveBeenCalledTimes(1);
expect(wrapper.loadChannelSet.mock.calls[0][0]).toBe(CHANNEL_SET.id);
});

it('should load channels of the channel set', () => {
expect(loadChannelList).toHaveBeenCalledTimes(1);
expect(loadChannelList.mock.calls[0][1]).toEqual({ id__in: [CHANNEL_1.id, CHANNEL_2.id] });
expect(wrapper.loadChannelList).toHaveBeenCalledTimes(1);
expect(wrapper.loadChannelList.mock.calls[0][0]).toEqual({
id__in: [CHANNEL_1.id, CHANNEL_2.id],
});
});
});

describe('if a channel set has been already loaded', () => {
let store, loadChannelSet, loadChannelList;
let store, wrapper;

beforeEach(() => {
const storeConfig = cloneDeep(STORE_CONFIG);
loadChannelSet = jest.fn();
loadChannelList = jest.fn();
storeConfig.modules.channelSet.actions.loadChannelSet = loadChannelSet;
storeConfig.modules.channel.actions.loadChannelList = loadChannelList;

store = storeFactory(storeConfig);
store.commit('channelSet/ADD_CHANNELSET', CHANNEL_SET);

makeWrapper({ store, channelSetId: CHANNEL_SET.id });
wrapper = makeWrapper({ store, channelSetId: CHANNEL_SET.id });
});

it("shouldn't load the channel set", () => {
expect(loadChannelSet).not.toHaveBeenCalled();
expect(wrapper.loadChannelSet).not.toHaveBeenCalled();
});

it('should load channels from the channel set', () => {
expect(loadChannelList).toHaveBeenCalledTimes(1);
expect(loadChannelList.mock.calls[0][1]).toEqual({ id__in: [CHANNEL_1.id, CHANNEL_2.id] });
expect(wrapper.loadChannelList).toHaveBeenCalledTimes(1);
expect(wrapper.loadChannelList.mock.calls[0][0]).toEqual({
id__in: [CHANNEL_1.id, CHANNEL_2.id],
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function searchCatalog(context, params) {
params.published = true;
let promise;
if (context.rootGetters.loggedIn) {
promise = Channel.requestCollection(params);
promise = Channel.fetchCollection(params);
} else {
promise = Channel.searchCatalog(params);
}
Expand Down
3 changes: 3 additions & 0 deletions contentcuration/contentcuration/frontend/shared/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export default async function startApp({ store, router, index }) {
}

window.addEventListener('beforeunload', e => {
if (e.currentTarget.location.origin !== window.location.origin) {
return;
}
const logoutConfirmed = window.sessionStorage.getItem('logoutConfirmed');
const areAllChangesSaved = store.getters['areAllChangesSaved'];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as resources from '../resources';

Object.values(resources).forEach(resource => {
if (resource.requestCollection) {
resource.requestCollection = () => Promise.resolve([]);
if (resource.fetchCollection) {
resource.fetchCollection = () => Promise.resolve([]);
}
if (resource.requestModel) {
resource.requestModel = () => Promise.resolve({});
if (resource.fetchModel) {
resource.fetchModel = () => Promise.resolve({});
}
});

Expand Down
Loading

0 comments on commit ec5cb45

Please sign in to comment.